From f3299b941aea8c50730e5490f58b3c4e1f842a53 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Mon, 20 Nov 2017 10:14:48 -0800 Subject: [PATCH 01/17] Deprecate bitwase calls to ~ to bitnot. --- base/bool.jl | 2 +- base/deprecated.jl | 5 +++++ base/gmp.jl | 2 +- base/int.jl | 12 ++++++------ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/base/bool.jl b/base/bool.jl index be60d2758337e..eef13a337cd07 100644 --- a/base/bool.jl +++ b/base/bool.jl @@ -38,7 +38,7 @@ function !(x::Bool) return not_int(x) end -(~)(x::Bool) = !x +bitnot(x::Bool) = !x (&)(x::Bool, y::Bool) = and_int(x, y) (|)(x::Bool, y::Bool) = or_int(x, y) diff --git a/base/deprecated.jl b/base/deprecated.jl index 9b417d90922c4..2426d881ebf63 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -2084,6 +2084,11 @@ end @deprecate parse(str::AbstractString, pos::Int, ; kwargs...) Meta.parse(str, pos; kwargs...) @deprecate_binding ParseError Meta.ParseError +@deprecate (~)(x::BitInteger) bitnot(x) +@deprecate (~)(n::Integer) bitnot(x) +@deprecate (~)(x::BigInt) bitnot(x) +@deprecate (~)(x::Bool) bitnot(x) + # #24258 # Physical units define an equivalence class: there is no such thing as a step of "1" (is # it one day or one second or one nanosecond?). So require the user to specify the step diff --git a/base/gmp.jl b/base/gmp.jl index 33eaa6e704c9a..55a2580fd64aa 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -465,7 +465,7 @@ end # unary ops (-)(x::BigInt) = MPZ.neg(x) -(~)(x::BigInt) = MPZ.com(x) +bitnot(x::BigInt) = MPZ.com(x) <<(x::BigInt, c::UInt) = c == 0 ? x : MPZ.mul_2exp(x, c) >>(x::BigInt, c::UInt) = c == 0 ? x : MPZ.fdiv_q_2exp(x, c) diff --git a/base/int.jl b/base/int.jl index ff7f24246bb75..b91fe4d9affaf 100644 --- a/base/int.jl +++ b/base/int.jl @@ -122,7 +122,7 @@ function abs end abs(x::Unsigned) = x abs(x::Signed) = flipsign(x,x) -~(n::Integer) = -n-1 +bitnot(n::Integer) = -n-1 unsigned(x::BitSigned) = reinterpret(typeof(convert(Unsigned, zero(x))), x) unsigned(x::Bool) = convert(Unsigned, x) @@ -242,23 +242,23 @@ end ## integer bitwise operations ## """ - ~(x) + bitnot(x) Bitwise not. # Examples ```jldoctest -julia> ~4 +julia> bitnot(4) -5 -julia> ~10 +julia> bitnot(10) -11 -julia> ~true +julia> bitnot(true) false ``` """ -(~)(x::BitInteger) = not_int(x) +bitnot(x::BitInteger) = not_int(x) """ &(x, y) From 4fb8ebef7c3b8dac875ff7f475215e9198ab393b Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Mon, 20 Nov 2017 11:10:05 -0800 Subject: [PATCH 02/17] Replace bitwise calls to ~ with bitnot in test/. --- test/arrayops.jl | 6 +++--- test/bigint.jl | 2 +- test/bitarray.jl | 26 +++++++++++++------------- test/core.jl | 2 +- test/int.jl | 2 +- test/numbers.jl | 16 ++++++++-------- test/ranges.jl | 6 +++--- test/show.jl | 12 ++++++------ test/version.jl | 24 ++++++++++++------------ 9 files changed, 48 insertions(+), 48 deletions(-) diff --git a/test/arrayops.jl b/test/arrayops.jl index a78bffc27d3a4..2538147536b72 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -2001,7 +2001,7 @@ end @test f15894(ones(Int, 100)) == 100 end -@testset "sign, conj, ~" begin +@testset "sign, conj, bitnot" begin local A, B, C A = [-10,0,3] B = [-10.0,0.0,3.0] @@ -2019,8 +2019,8 @@ end @test typeof(conj(B)) == Vector{Float64} @test typeof(conj(C)) == Vector{Complex{Int}} - @test .~A == [9,-1,-4] - @test typeof(.~A) == Vector{Int} + @test bitnot.(A) == [9,-1,-4] + @test typeof(bitnot.(A)) == Vector{Int} end @testset "issue #16247" begin diff --git a/test/bigint.jl b/test/bigint.jl index fad42ff934cd3..c9496d35384f8 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -181,7 +181,7 @@ end @test BigInt(-5) << -1 == -3 end @testset "boolean ops" begin - @test ~BigInt(123) == -124 + @test bitnot(BigInt(123)) == -124 @test BigInt(123) & BigInt(234) == 106 @test BigInt(123) | BigInt(234) == 251 @test BigInt(123) ⊻ BigInt(234) == 145 diff --git a/test/bitarray.jl b/test/bitarray.jl index 4700eec1e7a17..5b3bbd7c6a5b7 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -742,7 +742,7 @@ timesofar("dequeue") @testset "Unary operators" begin b1 = bitrand(n1, n2) - @check_bit_operation broadcast(~, b1) BitMatrix + @check_bit_operation broadcast(bitnot, b1) BitMatrix @check_bit_operation broadcast(!, b1) BitMatrix @check_bit_operation (-)(b1) Matrix{Int} @check_bit_operation broadcast(sign, b1) BitMatrix @@ -751,7 +751,7 @@ timesofar("dequeue") @check_bit_operation conj(b1) BitMatrix b0 = falses(0) - @check_bit_operation broadcast(~, b0) BitVector + @check_bit_operation broadcast(bitnot, b0) BitVector @check_bit_operation broadcast(!, b0) BitVector @check_bit_operation (-)(b0) Vector{Int} @check_bit_operation broadcast(sign, b0) BitVector @@ -759,7 +759,7 @@ timesofar("dequeue") @testset "flipbits!" begin b1 = bitrand(n1, n2) i1 = Array(b1) - @test flipbits!(b1) == .~i1 + @test flipbits!(b1) == bitnot.(i1) @test bitcheck(b1) end end @@ -1095,13 +1095,13 @@ timesofar("datamove") b1 = trues(v1) for i = 0:(v1-1) @test findfirst(b1 >> i) == i+1 - @test Base.findfirstnot(.~(b1 >> i)) == i+1 + @test Base.findfirstnot(bitnot.(b1 >> i)) == i+1 end for i = 3:(v1-1), j = 2:i submask = b1 << (v1-j+1) @test findnext((b1 >> i) .| submask, j) == i+1 - @test findnextnot((.~(b1 >> i)) .⊻ submask, j) == i+1 + @test findnextnot((bitnot.(b1 >> i)) .⊻ submask, j) == i+1 end b1 = bitrand(n1, n2) @@ -1140,7 +1140,7 @@ timesofar("nnz&find") for c = [falses, trues] b1 = c(n) b1[elts] = .!b1[elts] - b2 = .~b1 + b2 = bitnot.(b1) i1 = Array(b1) for i = 1:n @test findprev(b1, i) == findprev(i1, i) == findprevnot(b2, i) == findprev(!, b2, i) @@ -1151,7 +1151,7 @@ timesofar("nnz&find") b1 = falses(1000) b1[77] = true b1[777] = true - b2 = .~b1 + b2 = bitnot.(b1) @test_throws BoundsError findprev(b1, 1001) @test_throws BoundsError findprevnot(b2, 1001) @test_throws BoundsError findprev(!, b2, 1001) @@ -1207,13 +1207,13 @@ timesofar("nnz&find") @test findprev(t, l) == findprevnot(f, l) == l b1 = falses(l) b1[end] = true - b2 = .~b1 + b2 = bitnot.(b1) @test findprev(b1, l) == findprevnot(b2, l) == l @test findprevnot(b1, l) == findprev(b2, l) == l-1 if l > 1 b1 = falses(l) b1[end-1] = true - b2 = .~b1 + b2 = bitnot.(b1) @test findprev(b1, l) == findprevnot(b2, l) == l-1 @test findprevnot(b1, l) == findprev(b2, l) == l end @@ -1246,7 +1246,7 @@ timesofar("reductions") for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401] b1 = bitrand(l) b2 = bitrand(l) - @test map(~, b1) == map(x->~x, b1) == broadcast(~, b1) + @test map(bitnot, b1) == map(x->bitnot(x), b1) == broadcast(bitnot, b1) @test map(identity, b1) == map(x->x, b1) == b1 @test map(&, b1, b2) == map((x,y)->x&y, b1, b2) == broadcast(&, b1, b2) @@ -1268,8 +1268,8 @@ timesofar("reductions") @testset "map! for length $l" begin b = BitArray(l) - @test map!(~, b, b1) == map!(x->~x, b, b1) == broadcast(~, b1) == b - @test map!(!, b, b1) == map!(x->!x, b, b1) == broadcast(~, b1) == b + @test map!(bitnot, b, b1) == map!(x->bitnot(x), b, b1) == broadcast(bitnot, b1) == b + @test map!(!, b, b1) == map!(x->!x, b, b1) == broadcast(bitnot, b1) == b @test map!(identity, b, b1) == map!(x->x, b, b1) == b1 == b @test map!(zero, b, b1) == map!(x->false, b, b1) == falses(l) == b @test map!(one, b, b1) == map!(x->true, b, b1) == trues(l) == b @@ -1298,7 +1298,7 @@ timesofar("reductions") B17970 = map(x -> x ? 1 : 2, A17970) @test B17970::Array{Int,1} == [2,1,2] C17970 = map(x -> x ? false : true, A17970) - @test C17970::BitArray{1} == map(~, A17970) + @test C17970::BitArray{1} == map(bitnot, A17970) end end diff --git a/test/core.jl b/test/core.jl index 6a84a56d9e0b2..dad326f165282 100644 --- a/test/core.jl +++ b/test/core.jl @@ -567,7 +567,7 @@ let end # tricky space sensitive syntax cases -@test [-1 ~1] == [(-1) (~1)] +@test [-1 bitnot(1)] == [(-1) (bitnot(1))] # undefinedness mutable struct UndefField diff --git a/test/int.jl b/test/int.jl index 9ad8b5ff5710c..c988be1593f83 100644 --- a/test/int.jl +++ b/test/int.jl @@ -102,7 +102,7 @@ end @test mod(123, UInt8) == 0x7b primitive type MyBitsType <: Integer 8 end -@test_throws MethodError ~reinterpret(MyBitsType, 0x7b) +@test_throws MethodError bitnot(reinterpret(MyBitsType, 0x7b)) UItypes = Base.BitUnsigned_types SItypes = Base.BitSigned_types diff --git a/test/numbers.jl b/test/numbers.jl index a03ebd2a8e947..53d0418fc0068 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -19,8 +19,8 @@ const ≣ = isequal # convenient for comparing NaNs @test true != false @test false != true - @test ~true == false - @test ~false == true + @test bitnot(true) == false + @test bitnot(false) == true @test false & false == false @test true & false == false @@ -2059,9 +2059,9 @@ end @test signif(Float16(1.1), 70) === Float16(1.1) end @testset "issue #1308" begin - @test hex(~UInt128(0)) == "f"^32 - @test (~0)%UInt128 == ~UInt128(0) - @test Int128(~0) == ~Int128(0) + @test hex(bitnot(UInt128(0))) == "f"^32 + @test(bitnot(0)%UInt128 == bitnot(UInt128(0)) + @test Int128(bitnot(0)) == bitnot(Int128(0)) end @testset "issue 1552" begin @test isa(rationalize(Int8, float(pi)), Rational{Int8}) @@ -2289,7 +2289,7 @@ end @testset "ispow2" begin @test ispow2(64) @test !ispow2(42) - @test !ispow2(~typemax(Int)) + @test !ispow2(bitnot(typemax(Int))) end @testset "nextpow/prevpow" begin @test nextpow(2,1) == 1 @@ -2874,8 +2874,8 @@ end let types = (Base.BitInteger_types..., BigInt, Bool) for S in types - T = @inferred Base.promote_op(~, S) - t = @inferred ~one(S) + T = @inferred Base.promote_op(bitnot, S) + t = @inferred bitnot(one(S)) @test T === typeof(t) for R in types diff --git a/test/ranges.jl b/test/ranges.jl index c665fe920676a..811eaeeb880c3 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -1031,7 +1031,7 @@ end @test size(similar(r, size(r))) == size(similar(r, length(r))) end end -@testset "sign, conj, ~ (Issue #16067)" begin +@testset "sign, conj, bitnot (Issue #16067)" begin A = -1:1 B = -1.0:1.0 @test sign.(A) == [-1,0,1] @@ -1042,8 +1042,8 @@ end @test conj(A) === A @test conj(B) === B - @test .~A == [0,-1,-2] - @test typeof(.~A) == Vector{Int} + @test bitnot.(A) == [0,-1,-2] + @test typeof(bitnot.(A)) == Vector{Int} end @testset "conversion to Array" begin diff --git a/test/show.jl b/test/show.jl index 71a9577899615..745c388676c2c 100644 --- a/test/show.jl +++ b/test/show.jl @@ -66,7 +66,7 @@ end @test_repr "2e" @test_repr "!x" @test_repr "f(1, 2, 3)" -@test_repr "x = ~y" +@test_repr "x = bitnot(y)" @test_repr ":(:x, :y)" @test_repr ":(:(:(x)))" @@ -185,17 +185,17 @@ end""" # line meta if delta_kd == 0 # line meta - msk_d0 = ~(u << ld0) | (u << ld1 << 1) + msk_d0 = bitnot(u << ld0) | (u << ld1 << 1) else # line meta - msk_d0 = ~(u << ld0) + msk_d0 = bitnot(u << ld0) # line meta msk_d1 = (u << ld1 << 1) end # line meta if delta_ks == 0 # line meta - msk_s0 = (u << ls0) & ~(u << ls1 << 1) + msk_s0 = (u << ls0) & bitnot(u << ls1 << 1) else # line meta msk_s0 = (u << ls0) @@ -203,7 +203,7 @@ end""" # line meta chunk_s0 = glue_src_bitchunks(src, ks0, ks1, msk_s0, ls0) # line meta - dest[kd0] = (dest[kd0] & msk_d0) | ((chunk_s0 << ld0) & ~msk_d0) + dest[kd0] = (dest[kd0] & msk_d0) | ((chunk_s0 << ld0) & bitnot(msk_d0)) # line meta if delta_kd == 0 # line meta @@ -231,7 +231,7 @@ end""" # line meta chunk_s = (chunk_s0 >>> (63 - ld0) >>> 1) | (chunk_s1 << ld0) # line meta - dest[kd1] = (dest[kd1] & msk_d1) | (chunk_s & ~msk_d1) + dest[kd1] = (dest[kd1] & msk_d1) | (chunk_s & bitnot(msk_d1)) # line meta return end""" diff --git a/test/version.jl b/test/version.jl index f1e94fd0df477..30a8eb4ba82ad 100644 --- a/test/version.jl +++ b/test/version.jl @@ -103,18 +103,18 @@ end # issupbuild import Base.issupbuild @test issupbuild(v"4.3.2+") -@test ~issupbuild(v"4.3.2") -@test ~issupbuild(v"4.3.2-") -@test ~issupbuild(v"4.3.2-a") -@test ~issupbuild(v"4.3.2-a1") -@test ~issupbuild(v"4.3.2-1") -@test ~issupbuild(v"4.3.2-a.1") -@test ~issupbuild(v"4.3.2-1a") -@test ~issupbuild(v"4.3.2+a") -@test ~issupbuild(v"4.3.2+a1") -@test ~issupbuild(v"4.3.2+1") -@test ~issupbuild(v"4.3.2+a.1") -@test ~issupbuild(v"4.3.2+1a") +@test !issupbuild(v"4.3.2") +@test !issupbuild(v"4.3.2-") +@test !issupbuild(v"4.3.2-a") +@test !issupbuild(v"4.3.2-a1") +@test !issupbuild(v"4.3.2-1") +@test !issupbuild(v"4.3.2-a.1") +@test !issupbuild(v"4.3.2-1a") +@test !issupbuild(v"4.3.2+a") +@test !issupbuild(v"4.3.2+a1") +@test !issupbuild(v"4.3.2+1") +@test !issupbuild(v"4.3.2+a.1") +@test !issupbuild(v"4.3.2+1a") # basic comparison VersionNumber(2, 3, 1) == VersionNumber(Int8(2), UInt32(3), Int32(1)) == v"2.3.1" From a925e72a7024408b72849383de0eebfe10376bab Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Mon, 20 Nov 2017 11:51:16 -0800 Subject: [PATCH 03/17] Replace bitwise calls to ~ with bitnot in base/. --- base/atomics.jl | 2 +- base/bitarray.jl | 84 +++++++++++++++++++-------------------- base/bitset.jl | 2 +- base/checked.jl | 4 +- base/exports.jl | 2 +- base/float.jl | 12 +++--- base/gmp.jl | 4 +- base/grisu/bignums.jl | 2 +- base/hashing.jl | 4 +- base/int.jl | 6 +-- base/libgit2/consts.jl | 2 +- base/libgit2/utils.jl | 2 +- base/linalg/bitarray.jl | 6 +-- base/math.jl | 18 ++++----- base/multidimensional.jl | 8 ++-- base/nullable.jl | 2 +- base/pcre.jl | 2 +- base/random/generation.jl | 2 +- base/regex.jl | 6 +-- base/special/exp.jl | 2 +- base/special/exp10.jl | 2 +- base/strings/string.jl | 6 +-- base/version.jl | 4 +- 23 files changed, 92 insertions(+), 92 deletions(-) diff --git a/base/atomics.jl b/base/atomics.jl index 51c6964a13e16..61785e2ff0626 100644 --- a/base/atomics.jl +++ b/base/atomics.jl @@ -203,7 +203,7 @@ function atomic_and! end Atomically bitwise-nand (not-and) `x` with `val` -Performs `x[] = ~(x[] & val)` atomically. Returns the **old** value. +Performs `x[] = bitnot(x[] & val)` atomically. Returns the **old** value. For further details, see LLVM's `atomicrmw nand` instruction. diff --git a/base/bitarray.jl b/base/bitarray.jl index a6d94b2152a39..c8f885771e1dd 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -79,7 +79,7 @@ IndexStyle(::Type{<:BitArray}) = IndexLinear() ## aux functions ## -const _msk64 = ~UInt64(0) +const _msk64 = bitnot(UInt64(0)) @inline _div64(l) = l >>> 6 @inline _mod64(l) = l & 63 @inline _msk_end(l::Integer) = _msk64 >>> _mod64(-l) @@ -106,7 +106,7 @@ function glue_src_bitchunks(src::Vector{UInt64}, k::Int, ks1::Int, msk_s0::UInt6 @inbounds begin chunk = ((src[k] & msk_s0) >>> ls0) if ks1 > k && ls0 > 0 - chunk_n = (src[k + 1] & ~msk_s0) + chunk_n = (src[k + 1] & bitnot(msk_s0)) chunk |= (chunk_n << (64 - ls0)) end end @@ -129,20 +129,20 @@ function copy_chunks!(dest::Vector{UInt64}, pos_d::Integer, src::Vector{UInt64}, u = _msk64 if delta_kd == 0 - msk_d0 = ~(u << ld0) | (u << (ld1+1)) + msk_d0 = bitnot(u << ld0) | (u << (ld1+1)) else - msk_d0 = ~(u << ld0) + msk_d0 = bitnot(u << ld0) msk_d1 = (u << (ld1+1)) end if delta_ks == 0 - msk_s0 = (u << ls0) & ~(u << (ls1+1)) + msk_s0 = (u << ls0) & bitnot(u << (ls1+1)) else msk_s0 = (u << ls0) end chunk_s0 = glue_src_bitchunks(src, ks0, ks1, msk_s0, ls0) - dest[kd0] = (dest[kd0] & msk_d0) | ((chunk_s0 << ld0) & ~msk_d0) + dest[kd0] = (dest[kd0] & msk_d0) | ((chunk_s0 << ld0) & bitnot(msk_d0)) delta_kd == 0 && return @@ -164,7 +164,7 @@ function copy_chunks!(dest::Vector{UInt64}, pos_d::Integer, src::Vector{UInt64}, chunk_s = (chunk_s0 >>> (64 - ld0)) | (chunk_s1 << ld0) - dest[kd1] = (dest[kd1] & msk_d1) | (chunk_s & ~msk_d1) + dest[kd1] = (dest[kd1] & msk_d1) | (chunk_s & bitnot(msk_d1)) return end @@ -189,24 +189,24 @@ function copy_chunks_rtol!(chunks::Vector{UInt64}, pos_d::Integer, pos_s::Intege delta_ks = ks1 - ks0 if delta_kd == 0 - msk_d0 = ~(u << ld0) | (u << (ld1+1)) + msk_d0 = bitnot(u << ld0) | (u << (ld1+1)) else - msk_d0 = ~(u << ld0) + msk_d0 = bitnot(u << ld0) msk_d1 = (u << (ld1+1)) end if delta_ks == 0 - msk_s0 = (u << ls0) & ~(u << (ls1+1)) + msk_s0 = (u << ls0) & bitnot(u << (ls1+1)) else msk_s0 = (u << ls0) end - chunk_s0 = glue_src_bitchunks(chunks, ks0, ks1, msk_s0, ls0) & ~(u << s) - chunks[kd0] = (chunks[kd0] & msk_d0) | ((chunk_s0 << ld0) & ~msk_d0) + chunk_s0 = glue_src_bitchunks(chunks, ks0, ks1, msk_s0, ls0) & bitnot(u << s) + chunks[kd0] = (chunks[kd0] & msk_d0) | ((chunk_s0 << ld0) & bitnot(msk_d0)) if delta_kd != 0 chunk_s = (chunk_s0 >>> (64 - ld0)) - chunks[kd1] = (chunks[kd1] & msk_d1) | (chunk_s & ~msk_d1) + chunks[kd1] = (chunks[kd1] & msk_d1) | (chunk_s & bitnot(msk_d1)) end left -= s @@ -224,10 +224,10 @@ function fill_chunks!(Bc::Array{UInt64}, x::Bool, pos::Integer, numbits::Integer u = _msk64 if k1 == k0 - msk0 = (u << l0) & ~(u << (l1+1)) + msk0 = (u << l0) & bitnot(u << (l1+1)) else msk0 = (u << l0) - msk1 = ~(u << (l1+1)) + msk1 = bitnot(u << (l1+1)) end @inbounds if x Bc[k0] |= msk0 @@ -236,11 +236,11 @@ function fill_chunks!(Bc::Array{UInt64}, x::Bool, pos::Integer, numbits::Integer end k1 > k0 && (Bc[k1] |= msk1) else - Bc[k0] &= ~msk0 + Bc[k0] &= bitnot(msk0) for k = k0+1:k1-1 Bc[k] = 0 end - k1 > k0 && (Bc[k1] &= ~msk1) + k1 > k0 && (Bc[k1] &= bitnot(msk1)) end end @@ -265,10 +265,10 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} u = _msk64 if delta_kd == 0 - msk_d0 = msk_d1 = ~(u << ld0) | (u << (ld1+1)) + msk_d0 = msk_d1 = bitnot(u << ld0) | (u << (ld1+1)) lt0 = ld1 else - msk_d0 = ~(u << ld0) + msk_d0 = bitnot(u << ld0) msk_d1 = (u << (ld1+1)) lt0 = 63 end @@ -281,7 +281,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} c |= (UInt64(C[ind]) << j) ind += 1 end - Bc[kd0] = (Bc[kd0] & msk_d0) | (c & ~msk_d0) + Bc[kd0] = (Bc[kd0] & msk_d0) | (c & bitnot(msk_d0)) bind += 1 end @@ -318,7 +318,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} c |= (UInt64(C[ind]) << j) ind += 1 end - Bc[kd1] = (Bc[kd1] & msk_d1) | (c & ~msk_d1) + Bc[kd1] = (Bc[kd1] & msk_d1) | (c & bitnot(msk_d1)) end end @@ -456,7 +456,7 @@ function copy!(dest::BitArray, src::BitArray) destc[nc] = srcc[nc] else msk_s = _msk_end(src) - msk_d = ~msk_s + msk_d = bitnot(msk_s) destc[nc] = (msk_d & destc[nc]) | (msk_s & srcc[nc]) end end @@ -688,7 +688,7 @@ end u = UInt64(1) << i2 @inbounds begin c = Bc[i1] - Bc[i1] = ifelse(x, c | u, c & ~u) + Bc[i1] = ifelse(x, c | u, c & bitnot(u)) end end @@ -730,7 +730,7 @@ function _unsafe_setindex!(B::BitArray, x, I::BitArray) end else for i = 1:length(Bc) - Bc[i] &= ~Ic[i] + Bc[i] &= bitnot(Ic[i]) end end return B @@ -759,7 +759,7 @@ function _unsafe_setindex!(B::BitArray, X::AbstractArray, I::BitArray) if Imsk & u != 0 lx < c && throw_setindex_mismatch(X, c) @inbounds x = convert(Bool, X[c]) - C = ifelse(x, C | u, C & ~u) + C = ifelse(x, C | u, C & bitnot(u)) c += 1 end u <<= 1 @@ -933,7 +933,7 @@ function insert!(B::BitVector, i::Integer, item) end msk_aft = (_msk64 << j) - msk_bef = ~msk_aft + msk_bef = bitnot(msk_aft) Bc[k] = (msk_bef & Bc[k]) | ((msk_aft & Bc[k]) << 1) B[i] = item B @@ -943,7 +943,7 @@ function _deleteat!(B::BitVector, i::Integer) k, j = get_chunks_id(i) msk_bef = _msk64 >>> (63 - j) - msk_aft = ~msk_bef + msk_aft = bitnot(msk_bef) msk_bef >>>= 1 Bc = B.chunks @@ -1142,13 +1142,13 @@ function (-)(B::BitArray) end broadcast(::typeof(sign), B::BitArray) = copy(B) -function broadcast(::typeof(~), B::BitArray) +function broadcast(::typeof(bitnot), B::BitArray) C = similar(B) Bc = B.chunks if !isempty(Bc) Cc = C.chunks for i = 1:length(Bc) - Cc[i] = ~Bc[i] + Cc[i] = bitnot(Bc[i]) end Cc[end] &= _msk_end(B) end @@ -1158,7 +1158,7 @@ end """ flipbits!(B::BitArray{N}) -> BitArray{N} -Performs a bitwise not operation on `B`. See [`~`](@ref). +Performs a bitwise not operation on `B`. See [`bitnot`](@ref). # Examples ```jldoctest @@ -1177,7 +1177,7 @@ function flipbits!(B::BitArray) Bc = B.chunks @inbounds if !isempty(Bc) for i = 1:length(Bc) - Bc[i] = ~Bc[i] + Bc[i] = bitnot(Bc[i]) end Bc[end] &= _msk_end(B) end @@ -1216,7 +1216,7 @@ broadcast(::typeof(&), B::BitArray, x::Bool) = x ? copy(B) : falses(size(B)) broadcast(::typeof(&), x::Bool, B::BitArray) = broadcast(&, B, x) broadcast(::typeof(|), B::BitArray, x::Bool) = x ? trues(size(B)) : copy(B) broadcast(::typeof(|), x::Bool, B::BitArray) = broadcast(|, B, x) -broadcast(::typeof(xor), B::BitArray, x::Bool) = x ? .~B : copy(B) +broadcast(::typeof(xor), B::BitArray, x::Bool) = x ? bitnot.(B) : copy(B) broadcast(::typeof(xor), x::Bool, B::BitArray) = broadcast(xor, B, x) for f in (:&, :|, :xor) @eval begin @@ -1522,7 +1522,7 @@ function findnext(B::BitArray, start::Integer) end #findfirst(B::BitArray) = findnext(B, 1) ## defined in array.jl -# aux function: same as findnext(~B, start), but performed without temporaries +# aux function: same as findnext(bitnot(B), start), but performed without temporaries function findnextnot(B::BitArray, start::Integer) start > 0 || throw(BoundsError(B, start)) start > length(B) && return 0 @@ -1533,7 +1533,7 @@ function findnextnot(B::BitArray, start::Integer) chunk_start = _div64(start-1)+1 within_chunk_start = _mod64(start-1) - mask = ~(_msk64 << within_chunk_start) + mask = bitnot(_msk64 << within_chunk_start) @inbounds if chunk_start < l if Bc[chunk_start] | mask != _msk64 @@ -1607,7 +1607,7 @@ function findprevnot(B::BitArray, start::Integer) Bc = B.chunks chunk_start = _div64(start-1)+1 - mask = ~_msk_end(start) + mask = bitnot(_msk_end(start)) @inbounds begin if Bc[chunk_start] | mask != _msk64 @@ -1738,12 +1738,12 @@ maximum(B::BitArray) = isempty(B) ? throw(ArgumentError("argument must be non-em # arrays since there can be a 64x speedup by working at the level of Int64 # instead of looping bit-by-bit. -map(::Union{typeof(~), typeof(!)}, A::BitArray) = bit_map!(~, similar(A), A) +map(::Union{typeof(bitnot), typeof(!)}, A::BitArray) = bit_map!(bitnot, similar(A), A) map(::typeof(zero), A::BitArray) = fill!(similar(A), false) map(::typeof(one), A::BitArray) = fill!(similar(A), true) map(::typeof(identity), A::BitArray) = copy(A) -map!(::Union{typeof(~), typeof(!)}, dest::BitArray, A::BitArray) = bit_map!(~, dest, A) +map!(::Union{typeof(bitnot), typeof(!)}, dest::BitArray, A::BitArray) = bit_map!(bitnot, dest, A) map!(::typeof(zero), dest::BitArray, A::BitArray) = fill!(dest, false) map!(::typeof(one), dest::BitArray, A::BitArray) = fill!(dest, true) map!(::typeof(identity), dest::BitArray, A::BitArray) = copy!(dest, A) @@ -1751,11 +1751,11 @@ map!(::typeof(identity), dest::BitArray, A::BitArray) = copy!(dest, A) for (T, f) in ((:(Union{typeof(&), typeof(*), typeof(min)}), :(&)), (:(Union{typeof(|), typeof(max)}), :(|)), (:(Union{typeof(xor), typeof(!=)}), :xor), - (:(Union{typeof(>=), typeof(^)}), :((p, q) -> p | ~q)), - (:(typeof(<=)), :((p, q) -> ~p | q)), - (:(typeof(==)), :((p, q) -> ~xor(p, q))), - (:(typeof(<)), :((p, q) -> ~p & q)), - (:(typeof(>)), :((p, q) -> p & ~q))) + (:(Union{typeof(>=), typeof(^)}), :((p, q) -> p | bitnot(q))), + (:(typeof(<=)), :((p, q) -> bitnot(p) | q)), + (:(typeof(==)), :((p, q) -> bitnot(xor(p, q)))), + (:(typeof(<)), :((p, q) -> bitnot(p) & q)), + (:(typeof(>)), :((p, q) -> p & bitnot(q)))) @eval map(::$T, A::BitArray, B::BitArray) = bit_map!($f, similar(A), A, B) @eval map!(::$T, dest::BitArray, A::BitArray, B::BitArray) = bit_map!($f, dest, A, B) end diff --git a/base/bitset.jl b/base/bitset.jl index 431df3f4ea9bf..62fd141b9ca2d 100644 --- a/base/bitset.jl +++ b/base/bitset.jl @@ -145,7 +145,7 @@ end setdiff(s::BitSet, ns) = setdiff!(copy(s), ns) setdiff!(s::BitSet, ns) = (for n in ns; delete!(s, n); end; s) function setdiff!(s1::BitSet, s2::BitSet) - _matched_map!((p, q) -> p & ~q, s1.bits, s2.bits) + _matched_map!((p, q) -> p & bitnot(q), s1.bits, s2.bits) s1 end diff --git a/base/checked.jl b/base/checked.jl index 2870461a43205..650fc58654a9d 100644 --- a/base/checked.jl +++ b/base/checked.jl @@ -148,8 +148,8 @@ end if BrokenUnsignedInt != Union{} function add_with_overflow(x::T, y::T) where T<:BrokenUnsignedInt # x + y > typemax(T) - # Note: ~y == -y-1 - x + y, x > ~y + # Note: bitnot(y) == -y-1 + x + y, x > bitnot(y) end end diff --git a/base/exports.jl b/base/exports.jl index 84e7e3ed29790..63ef52bd5cd51 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -215,7 +215,7 @@ export ^, |, |>, - ~, + bitnot, :, =>, ∘, diff --git a/base/float.jl b/base/float.jl index ddd3d194353a2..14e6d18d64d08 100644 --- a/base/float.jl +++ b/base/float.jl @@ -82,7 +82,7 @@ function convert(::Type{Float64}, x::UInt128) else y = ((x >> (n-54)) % UInt64) & 0x001f_ffff_ffff_ffff # keep 1 extra bit y = (y+1)>>1 # round, ties up (extra leading bit in case of next exponent) - y &= ~UInt64(trailing_zeros(x) == (n-54)) # fix last bit to round to even + y &= bitnot(UInt64(trailing_zeros(x) == (n-54))) # fix last bit to round to even end d = ((n+1022) % UInt64) << 52 reinterpret(Float64, d + y) @@ -98,7 +98,7 @@ function convert(::Type{Float64}, x::Int128) else y = ((x >> (n-54)) % UInt64) & 0x001f_ffff_ffff_ffff # keep 1 extra bit y = (y+1)>>1 # round, ties up (extra leading bit in case of next exponent) - y &= ~UInt64(trailing_zeros(x) == (n-54)) # fix last bit to round to even + y &= bitnot(UInt64(trailing_zeros(x) == (n-54))) # fix last bit to round to even end d = ((n+1022) % UInt64) << 52 reinterpret(Float64, s | d + y) @@ -112,7 +112,7 @@ function convert(::Type{Float32}, x::UInt128) else y = ((x >> (n-25)) % UInt32) & 0x00ff_ffff # keep 1 extra bit y = (y+one(UInt32))>>1 # round, ties up (extra leading bit in case of next exponent) - y &= ~UInt32(trailing_zeros(x) == (n-25)) # fix last bit to round to even + y &= bitnot(UInt32(trailing_zeros(x) == (n-25))) # fix last bit to round to even end d = ((n+126) % UInt32) << 23 reinterpret(Float32, d + y) @@ -128,7 +128,7 @@ function convert(::Type{Float32}, x::Int128) else y = ((x >> (n-25)) % UInt32) & 0x00ff_ffff # keep 1 extra bit y = (y+one(UInt32))>>1 # round, ties up (extra leading bit in case of next exponent) - y &= ~UInt32(trailing_zeros(x) == (n-25)) # fix last bit to round to even + y &= bitnot(UInt32(trailing_zeros(x) == (n-25))) # fix last bit to round to even end d = ((n+126) % UInt32) << 23 reinterpret(Float32, s | d + y) @@ -177,7 +177,7 @@ function convert(::Type{Float32}, val::Float16) end sign = sign << 31 exp = (-14 - n_bit + 127) << 23 - sig = ((sig & (~bit)) << n_bit) << (23 - 10) + sig = ((sig & bitnot(bit)) << n_bit) << (23 - 10) ret = sign | exp | sig end elseif exp == 0x1f @@ -870,7 +870,7 @@ uinttype(::Type{Float64}) = UInt64 uinttype(::Type{Float32}) = UInt32 uinttype(::Type{Float16}) = UInt16 -Base.iszero(x::Float16) = reinterpret(UInt16, x) & ~sign_mask(Float16) == 0x0000 +Base.iszero(x::Float16) = reinterpret(UInt16, x) & bitnot(sign_mask(Float16)) == 0x0000 ## Array operations on floating point numbers ## diff --git a/base/gmp.jl b/base/gmp.jl index 55a2580fd64aa..e8f0cdcf53e34 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -4,7 +4,7 @@ module GMP export BigInt -import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor, +import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, bitnot, (&), (|), xor, binomial, cmp, convert, div, divrem, factorial, fld, gcd, gcdx, lcm, mod, ndigits, promote_rule, rem, show, isqrt, string, powermod, sum, trailing_zeros, trailing_ones, count_ones, base, tryparse_internal, @@ -288,7 +288,7 @@ function convert(::Type{BigInt}, x::Integer) b = BigInt(0) shift = 0 while x < -1 - b += BigInt(~UInt32(x&0xffffffff))<>= 32 shift += 32 end diff --git a/base/grisu/bignums.jl b/base/grisu/bignums.jl index 7398028b81202..114607e76eeb2 100644 --- a/base/grisu/bignums.jl +++ b/base/grisu/bignums.jl @@ -397,7 +397,7 @@ function assignpoweruint16!(x::Bignum,base::UInt16,power_exponent::Int) while mask != 0 && this_value <= max_32bits this_value *= this_value if (power_exponent & mask) != 0 - base_bits_mask::UInt64 = ~(UInt64(1) << (64 - bit_size) - 1) + base_bits_mask::UInt64 = bitnot(UInt64(1) << (64 - bit_size) - 1) high_bits_zero = (this_value & base_bits_mask) == 0 if high_bits_zero this_value *= base diff --git a/base/hashing.jl b/base/hashing.jl index e2847342a8c57..d71eed5c023d2 100644 --- a/base/hashing.jl +++ b/base/hashing.jl @@ -24,7 +24,7 @@ hash(@nospecialize(x), h::UInt) = hash_uint(3h - object_id(x)) function hash_64_64(n::UInt64) local a::UInt64 = n - a = ~a + a << 21 + a = bitnot(a) + a << 21 a = a ⊻ a >> 24 a = a + a << 3 + a << 8 a = a ⊻ a >> 14 @@ -36,7 +36,7 @@ end function hash_64_32(n::UInt64) local a::UInt64 = n - a = ~a + a << 18 + a = bitnot(a) + a << 18 a = a ⊻ a >> 31 a = a * 21 a = a ⊻ a >> 11 diff --git a/base/int.jl b/base/int.jl index b91fe4d9affaf..d8b7faf05874a 100644 --- a/base/int.jl +++ b/base/int.jl @@ -363,7 +363,7 @@ julia> count_zeros(Int32(2 ^ 16 - 1)) 16 ``` """ -count_zeros(x::Integer) = count_ones(~x) +count_zeros(x::Integer) = count_ones(bitnot(x)) """ leading_ones(x::Integer) -> Integer @@ -375,7 +375,7 @@ julia> leading_ones(UInt32(2 ^ 32 - 2)) 31 ``` """ -leading_ones(x::Integer) = leading_zeros(~x) +leading_ones(x::Integer) = leading_zeros(bitnot(x)) """ trailing_ones(x::Integer) -> Integer @@ -387,7 +387,7 @@ julia> trailing_ones(3) 2 ``` """ -trailing_ones(x::Integer) = trailing_zeros(~x) +trailing_ones(x::Integer) = trailing_zeros(bitnot(x)) ## integer comparisons ## diff --git a/base/libgit2/consts.jl b/base/libgit2/consts.jl index 07f6f75c6df44..1273d47d5c80f 100644 --- a/base/libgit2/consts.jl +++ b/base/libgit2/consts.jl @@ -139,7 +139,7 @@ const IDXENTRY_NEW_SKIP_WORKTREE = Cint(1 << 9) const INDEXCAP_IGNORE_CASE = Cuint(1) const INDEXCAP_NO_FILEMODE = Cuint(2) const INDEXCAP_NO_SYMLINKS = Cuint(4) -const INDEXCAP_FROM_OWNER = ~Cuint(0) +const INDEXCAP_FROM_OWNER = bitnot(Cuint(0)) const INDEX_ADD_DEFAULT = Cuint(0) const INDEX_ADD_FORCE = Cuint(1 << 0) diff --git a/base/libgit2/utils.jl b/base/libgit2/utils.jl index ed455035b30d3..22cabf70572be 100644 --- a/base/libgit2/utils.jl +++ b/base/libgit2/utils.jl @@ -51,7 +51,7 @@ isset(val::Integer, flag::Integer) = (val & flag == flag) Unset the bits of `val` indexed by `flag`, returning them to `0`. """ -reset(val::Integer, flag::Integer) = (val &= ~flag) +reset(val::Integer, flag::Integer) = (val &= bitnot(flag)) """ toggle(val::Integer, flag::Integer) diff --git a/base/linalg/bitarray.jl b/base/linalg/bitarray.jl index ec4c879758879..816a063d11f97 100644 --- a/base/linalg/bitarray.jl +++ b/base/linalg/bitarray.jl @@ -133,12 +133,12 @@ function nonzero_chunks(chunks::Vector{UInt64}, pos0::Int, pos1::Int) delta_k = k1 - k0 z = UInt64(0) - u = ~z + u = bitnot(z) if delta_k == 0 - msk_0 = (u << l0) & ~(u << l1 << 1) + msk_0 = (u << l0) & bitnot(u << l1 << 1) else msk_0 = (u << l0) - msk_1 = ~(u << l1 << 1) + msk_1 = bitnot(u << l1 << 1) end @inbounds begin diff --git a/base/math.jl b/base/math.jl index 9b4b317cc34ee..f407ef2ec8de6 100644 --- a/base/math.jl +++ b/base/math.jl @@ -542,7 +542,7 @@ julia> ldexp(5., 2) """ function ldexp(x::T, e::Integer) where T<:IEEEFloat xu = reinterpret(Unsigned, x) - xs = xu & ~sign_mask(T) + xs = xu & bitnot(sign_mask(T)) xs >= exponent_mask(T) && return x # NaN or Inf k = Int(xs >> significand_bits(T)) if k == 0 # x is subnormal @@ -568,7 +568,7 @@ function ldexp(x::T, e::Integer) where T<:IEEEFloat return flipsign(T(Inf), x) end if k > 0 # normal case - xu = (xu & ~exponent_mask(T)) | (rem(k, uinttype(T)) << significand_bits(T)) + xu = (xu & bitnot(exponent_mask(T))) | (rem(k, uinttype(T)) << significand_bits(T)) return reinterpret(T, xu) else # subnormal case if k <= -significand_bits(T) # underflow @@ -578,7 +578,7 @@ function ldexp(x::T, e::Integer) where T<:IEEEFloat end k += significand_bits(T) z = T(2.0)^-significand_bits(T) - xu = (xu & ~exponent_mask(T)) | (rem(k, uinttype(T)) << significand_bits(T)) + xu = (xu & bitnot(exponent_mask(T))) | (rem(k, uinttype(T)) << significand_bits(T)) return z*reinterpret(T, xu) end end @@ -592,7 +592,7 @@ Get the exponent of a normalized floating-point number. function exponent(x::T) where T<:IEEEFloat @noinline throw1(x) = throw(DomainError(x, "Cannot be NaN or Inf.")) @noinline throw2(x) = throw(DomainError(x, "Cannot be subnormal converted to 0.")) - xs = reinterpret(Unsigned, x) & ~sign_mask(T) + xs = reinterpret(Unsigned, x) & bitnot(sign_mask(T)) xs >= exponent_mask(T) && throw1(x) k = Int(xs >> significand_bits(T)) if k == 0 # x is subnormal @@ -621,15 +621,15 @@ julia> significand(15.2)*8 """ function significand(x::T) where T<:IEEEFloat xu = reinterpret(Unsigned, x) - xs = xu & ~sign_mask(T) + xs = xu & bitnot(sign_mask(T)) xs >= exponent_mask(T) && return x # NaN or Inf - if xs <= (~exponent_mask(T) & ~sign_mask(T)) # x is subnormal + if xs <= (bitnot(exponent_mask(T)) & bitnot(sign_mask(T))) # x is subnormal xs == 0 && return x # +-0 m = unsigned(leading_zeros(xs) - exponent_bits(T)) xs <<= m xu = xs | (xu & sign_mask(T)) end - xu = (xu & ~exponent_mask(T)) | exponent_one(T) + xu = (xu & bitnot(exponent_mask(T))) | exponent_one(T) return reinterpret(T, xu) end @@ -641,7 +641,7 @@ and `val` is equal to ``x \\times 2^{exp}``. """ function frexp(x::T) where T<:IEEEFloat xu = reinterpret(Unsigned, x) - xs = xu & ~sign_mask(T) + xs = xu & bitnot(sign_mask(T)) xs >= exponent_mask(T) && return x, 0 # NaN or Inf k = Int(xs >> significand_bits(T)) if k == 0 # x is subnormal @@ -652,7 +652,7 @@ function frexp(x::T) where T<:IEEEFloat k = 1 - m end k -= (exponent_bias(T) - 1) - xu = (xu & ~exponent_mask(T)) | exponent_half(T) + xu = (xu & bitnot(exponent_mask(T))) | exponent_half(T) return reinterpret(T, xu), k end diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 598dd36ff7391..1e7376a8b742b 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -1199,10 +1199,10 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra u = _msk64 if delta_kd == 0 - msk_d0 = msk_d1 = ~(u << ld0) | (u << (ld1+1)) + msk_d0 = msk_d1 = bitnot(u << ld0) | (u << (ld1+1)) lt0 = ld1 else - msk_d0 = ~(u << ld0) + msk_d0 = bitnot(u << ld0) msk_d1 = (u << (ld1+1)) lt0 = 63 end @@ -1215,7 +1215,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra c |= (UInt64(unchecked_bool_convert(C[ind])) << j) ind += 1 end - Bc[kd0] = (Bc[kd0] & msk_d0) | (c & ~msk_d0) + Bc[kd0] = (Bc[kd0] & msk_d0) | (c & bitnot(msk_d0)) bind += 1 end @@ -1237,7 +1237,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra c |= (UInt64(unchecked_bool_convert(C[ind])) << j) ind += 1 end - Bc[kd1] = (Bc[kd1] & msk_d1) | (c & ~msk_d1) + Bc[kd1] = (Bc[kd1] & msk_d1) | (c & bitnot(msk_d1)) end end diff --git a/base/nullable.jl b/base/nullable.jl index bb3075576eb1e..a5b681ea62db5 100644 --- a/base/nullable.jl +++ b/base/nullable.jl @@ -394,7 +394,7 @@ for op in (+, -, abs, abs2) null_safe_op(::typeof(op), ::Type{Rational{S}}) where {S} = null_safe_op(op, S) end -null_safe_op(::typeof(~), ::NullSafeInts) = true +null_safe_op(::typeof(bitnot), ::NullSafeInts) = true null_safe_op(::typeof(!), ::Type{Bool}) = true # Binary operators diff --git a/base/pcre.jl b/base/pcre.jl index 361a325c80c45..6696e5b530039 100644 --- a/base/pcre.jl +++ b/base/pcre.jl @@ -67,7 +67,7 @@ const EXECUTE_MASK = const OPTIONS_MASK = COMPILE_MASK | EXECUTE_MASK -const UNSET = ~Csize_t(0) # Indicates that an output vector element is unset +const UNSET = bitnot(Csize_t(0)) # Indicates that an output vector element is unset function info(regex::Ptr{Void}, what::Integer, ::Type{T}) where T buf = Ref{T}() diff --git a/base/random/generation.jl b/base/random/generation.jl index 998a3fd6fc4ee..b83f841a476a9 100644 --- a/base/random/generation.jl +++ b/base/random/generation.jl @@ -233,7 +233,7 @@ function RangeGenerator(r::UnitRange{BigInt}) nd = ndigits(m, 2) nlimbs, highbits = divrem(nd, 8*sizeof(Limb)) highbits > 0 && (nlimbs += 1) - mask = highbits == 0 ? ~zero(Limb) : one(Limb)< exp(1.0) ``` """ function exp(x::T) where T<:Union{Float32,Float64} - xa = reinterpret(Unsigned, x) & ~sign_mask(T) + xa = reinterpret(Unsigned, x) & bitnot(sign_mask(T)) xsb = signbit(x) # filter out non-finite arguments diff --git a/base/special/exp10.jl b/base/special/exp10.jl index 711da3b04549b..3f53817e5495d 100644 --- a/base/special/exp10.jl +++ b/base/special/exp10.jl @@ -82,7 +82,7 @@ julia> exp10(0.2) ``` """ function exp10(x::T) where T<:Union{Float32,Float64} - xa = reinterpret(Unsigned, x) & ~sign_mask(T) + xa = reinterpret(Unsigned, x) & bitnot(sign_mask(T)) xsb = signbit(x) # filter out non-finite arguments diff --git a/base/strings/string.jl b/base/strings/string.jl index 45d1a05b352ca..71738b3a13b2a 100644 --- a/base/strings/string.jl +++ b/base/strings/string.jl @@ -185,9 +185,9 @@ isvalid(s::String) = isvalid(String, s) ## basic UTF-8 decoding & iteration ## -is_surrogate_lead(c::Unsigned) = ((c & ~0x003ff) == 0xd800) -is_surrogate_trail(c::Unsigned) = ((c & ~0x003ff) == 0xdc00) -is_surrogate_codeunit(c::Unsigned) = ((c & ~0x007ff) == 0xd800) +is_surrogate_lead(c::Unsigned) = ((c & bitnot(0x003ff)) == 0xd800) +is_surrogate_trail(c::Unsigned) = ((c & bitnot(0x003ff)) == 0xdc00) +is_surrogate_codeunit(c::Unsigned) = ((c & bitnot(0x007ff)) == 0xd800) is_valid_continuation(c) = ((c & 0xc0) == 0x80) const utf8_offset = [ diff --git a/base/version.jl b/base/version.jl index 9e18099faeae4..1ba752c6c87a5 100644 --- a/base/version.jl +++ b/base/version.jl @@ -171,8 +171,8 @@ function hash(v::VersionNumber, h::UInt) h = hash(v.major, h) h = hash(v.minor, h) h = hash(v.patch, h) - h = hash(v.prerelease, ~h) - h = hash(v.build, ~h) + h = hash(v.prerelease, bitnot(h)) + h = hash(v.build, bitnot(h)) end lowerbound(v::VersionNumber) = VersionNumber(v.major, v.minor, v.patch, ("",), ()) From 630c6f647597ec3cf09bee7c3468ab514700f28f Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Tue, 21 Nov 2017 12:10:43 -0800 Subject: [PATCH 04/17] Replace bitwise calls to ~ with bitnot in stdlib/. --- stdlib/FileWatching/src/FileWatching.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/FileWatching/src/FileWatching.jl b/stdlib/FileWatching/src/FileWatching.jl index 5d2735dac8244..aede724e7c2d2 100644 --- a/stdlib/FileWatching/src/FileWatching.jl +++ b/stdlib/FileWatching/src/FileWatching.jl @@ -378,11 +378,11 @@ function wait(fdw::_FDWatcher; readable=true, writable=true) events |= FDEvent(fdw.events) haveevent = false if readable && isreadable(events) - fdw.events &= ~UV_READABLE + fdw.events &= bitnot(UV_READABLE) haveevent = true end if writable && iswritable(events) - fdw.events &= ~UV_WRITABLE + fdw.events &= bitnot(UV_WRITABLE) haveevent = true end if haveevent From 3fd04e17aa32d7e23797c642e4984bd8089c7048 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Mon, 20 Nov 2017 14:04:28 -0800 Subject: [PATCH 05/17] Deprecate bitwise calls to | to bitor. --- base/bool.jl | 1 + base/deprecated.jl | 12 ++++++++++++ base/gmp.jl | 4 ++-- base/int.jl | 6 +++--- base/operators.jl | 4 ++-- base/promotion.jl | 2 +- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/base/bool.jl b/base/bool.jl index eef13a337cd07..eda9d89743002 100644 --- a/base/bool.jl +++ b/base/bool.jl @@ -39,6 +39,7 @@ function !(x::Bool) end bitnot(x::Bool) = !x +bitor(x::Bool, y::Bool) = or_int(x, y) (&)(x::Bool, y::Bool) = and_int(x, y) (|)(x::Bool, y::Bool) = or_int(x, y) diff --git a/base/deprecated.jl b/base/deprecated.jl index 2426d881ebf63..909f8d6c7bbff 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -2089,6 +2089,18 @@ end @deprecate (~)(x::BigInt) bitnot(x) @deprecate (~)(x::Bool) bitnot(x) +@deprecate (|)(a::BigInt, b::BigInt) bitor(a, b) +@deprecate (|)(a::BigInt, b::BigInt, c::BigInt) bitor(a, b, c) +@deprecate (|)(a::BigInt, b::BigInt, c::BigInt, d::BigInt) bitor(a, b, c, d) +@deprecate (|)(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) bitor(a, b, c, d, e) + +@deprecate (|)(x::Integer) bitor(x) +@deprecate (|)(a::Integer, b::Integer) bitor(a, b) +@deprecate (|)(x::T, y::T) where {T<:Integer} bitor(x, y) +@deprecate (|)(x::T, y::T) where {T<:BitInteger} bitor(x, y) + +@deprecate (|)(a, b, c, xs...) bitor(a, b, c, xs...) + # #24258 # Physical units define an equivalence class: there is no such thing as a step of "1" (is # it one day or one second or one nanosecond?). So require the user to specify the step diff --git a/base/gmp.jl b/base/gmp.jl index e8f0cdcf53e34..5ec33c838e00f 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -405,7 +405,7 @@ big(::Type{<:Rational}) = Rational{BigInt} for (fJ, fC) in ((:+, :add), (:-,:sub), (:*, :mul), (:fld, :fdiv_q), (:div, :tdiv_q), (:mod, :fdiv_r), (:rem, :tdiv_r), (:gcd, :gcd), (:lcm, :lcm), - (:&, :and), (:|, :ior), (:xor, :xor)) + (:&, :and), (:bitor, :ior), (:xor, :xor)) @eval begin ($fJ)(x::BigInt, y::BigInt) = MPZ.$fC(x, y) end @@ -433,7 +433,7 @@ function invmod(x::BigInt, y::BigInt) end # More efficient commutative operations -for (fJ, fC) in ((:+, :add), (:*, :mul), (:&, :and), (:|, :ior), (:xor, :xor)) +for (fJ, fC) in ((:+, :add), (:*, :mul), (:&, :and), (:bitor, :ior), (:xor, :xor)) fC! = Symbol(fC, :!) @eval begin ($fJ)(a::BigInt, b::BigInt, c::BigInt) = MPZ.$fC!(MPZ.$fC(a, b), c) diff --git a/base/int.jl b/base/int.jl index d8b7faf05874a..b01c27ced42f8 100644 --- a/base/int.jl +++ b/base/int.jl @@ -277,7 +277,7 @@ julia> 4 & 12 (&)(x::T, y::T) where {T<:BitInteger} = and_int(x, y) """ - |(x, y) + bitor(x, y) Bitwise or. @@ -290,7 +290,7 @@ julia> 4 | 1 5 ``` """ -(|)(x::T, y::T) where {T<:BitInteger} = or_int(x, y) +bitor(x::T, y::T) where {T<:BitInteger} = or_int(x, y) xor(x::T, y::T) where {T<:BitInteger} = xor_int(x, y) """ @@ -770,7 +770,7 @@ else end # issue #15489: since integer ops are unchecked, they shouldn't check promotion -for op in (:+, :-, :*, :&, :|, :xor) +for op in (:+, :-, :*, :&, :bitor, :xor) @eval function $op(a::Integer, b::Integer) T = promote_typeof(a, b) return $op(a % T, b % T) diff --git a/base/operators.jl b/base/operators.jl index 60860e71b3d08..9d00ae811ebe9 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -444,7 +444,7 @@ identity(x) = x +(x::Number) = x *(x::Number) = x (&)(x::Integer) = x -(|)(x::Integer) = x +bitor(x::Integer) = x xor(x::Integer) = x const ⊻ = xor @@ -461,7 +461,7 @@ function afoldl(op,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,qs...) y end -for op in (:+, :*, :&, :|, :xor, :min, :max, :kron) +for op in (:+, :*, :&, :bitor, :xor, :min, :max, :kron) @eval begin # note: these definitions must not cause a dispatch loop when +(a,b) is # not defined, and must only try to call 2-argument definitions, so diff --git a/base/promotion.jl b/base/promotion.jl index 180313aed8299..9a71a2136af1f 100644 --- a/base/promotion.jl +++ b/base/promotion.jl @@ -380,7 +380,7 @@ fma(x::Integer, y::Integer, z::Integer) = x*y+z muladd(x::T, y::T, z::T) where {T<:Number} = x*y+z (&)(x::T, y::T) where {T<:Integer} = no_op_err("&", T) -(|)(x::T, y::T) where {T<:Integer} = no_op_err("|", T) +bitor(x::T, y::T) where {T<:Integer} = no_op_err("bitor", T) xor(x::T, y::T) where {T<:Integer} = no_op_err("xor", T) (==)(x::T, y::T) where {T<:Number} = x === y From 0a6b9a5b25639e9c092ab51615c6c39089ba886b Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Mon, 20 Nov 2017 14:49:37 -0800 Subject: [PATCH 06/17] Replace bitwise calls to | with bitor in test/. --- test/TestHelpers.jl | 4 ++-- test/bigint.jl | 12 ++++++------ test/core.jl | 2 +- test/fastmath.jl | 2 +- test/file.jl | 2 +- test/int.jl | 2 +- test/numbers.jl | 6 +++--- test/operators.jl | 2 +- test/perf/shootout/mandelbrot.jl | 3 ++- test/perf/shootout/meteor_contest.jl | 8 ++++---- test/random.jl | 2 +- test/read.jl | 2 +- test/reduce.jl | 2 +- test/reducedim.jl | 2 +- test/show.jl | 10 +++++----- test/sorting.jl | 2 +- test/sparse/sparse.jl | 8 ++++---- 17 files changed, 36 insertions(+), 35 deletions(-) diff --git a/test/TestHelpers.jl b/test/TestHelpers.jl index d333c6a31b2d4..d105b15f6f2e9 100644 --- a/test/TestHelpers.jl +++ b/test/TestHelpers.jl @@ -27,7 +27,7 @@ function open_fake_pty() O_RDWR = Base.Filesystem.JL_O_RDWR O_NOCTTY = Base.Filesystem.JL_O_NOCTTY - fdm = ccall(:posix_openpt, Cint, (Cint,), O_RDWR|O_NOCTTY) + fdm = ccall(:posix_openpt, Cint, (Cint,), bitor(O_RDWR, O_NOCTTY)) fdm == -1 && error("Failed to open PTY master") rc = ccall(:grantpt, Cint, (Cint,), fdm) rc != 0 && error("grantpt failed") @@ -35,7 +35,7 @@ function open_fake_pty() rc != 0 && error("unlockpt") fds = ccall(:open, Cint, (Ptr{UInt8}, Cint), - ccall(:ptsname, Ptr{UInt8}, (Cint,), fdm), O_RDWR|O_NOCTTY) + ccall(:ptsname, Ptr{UInt8}, (Cint,), fdm), bitor(O_RDWR, O_NOCTTY)) # slave slave = RawFD(fds) diff --git a/test/bigint.jl b/test/bigint.jl index c9496d35384f8..704919dd9dc20 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -183,7 +183,7 @@ end @testset "boolean ops" begin @test bitnot(BigInt(123)) == -124 @test BigInt(123) & BigInt(234) == 106 - @test BigInt(123) | BigInt(234) == 251 + @test bitor(BigInt(123), BigInt(234)) == 251 @test BigInt(123) ⊻ BigInt(234) == 145 @test gcd(BigInt(48), BigInt(180)) == 12 @@ -235,11 +235,11 @@ end @test (&)(a, b, c, d, f) == parse(BigInt,"8") @test (&)(a, b, c, d, f, g) == parse(BigInt,"8") - @test (|)(a, b) == parse(BigInt,"327423") - @test (|)(a, b, c) == parse(BigInt,"3426495623485904783802111") - @test (|)(a, b, c, d) == parse(BigInt,"-1396834561") - @test (|)(a, b, c, d, f) == parse(BigInt,"-1358954753") - @test (|)(a, b, c, d, f, g) == parse(BigInt,"-1") + @test bitor(a, b) == parse(BigInt,"327423") + @test bitor(a, b, c) == parse(BigInt,"3426495623485904783802111") + @test bitor(a, b, c, d) == parse(BigInt,"-1396834561") + @test bitor(a, b, c, d, f) == parse(BigInt,"-1358954753") + @test bitor(a, b, c, d, f, g) == parse(BigInt,"-1") @test trailing_ones(a) == 8 @test trailing_zeros(b) == 2 diff --git a/test/core.jl b/test/core.jl index dad326f165282..c73e502d3aa47 100644 --- a/test/core.jl +++ b/test/core.jl @@ -1748,7 +1748,7 @@ f5254(a, b) = 1 let i = 0, x = 65 @test (i, i+=1, i+=1) === (0, 1, 2) @test i == 2 - @test [x, x|=0x20] == [65, 97] + @test [x, x = bitor(x, 0x20)] == [65, 97] end # issue #5312 diff --git a/test/fastmath.jl b/test/fastmath.jl index 274e3c794a8e3..6aaf32921866a 100644 --- a/test/fastmath.jl +++ b/test/fastmath.jl @@ -198,7 +198,7 @@ end # test fallthrough for unsupported ops local c = 0 - @test @fastmath(c |= 1) == 1 + @test @fastmath(c = bitor(c, 1)) == 1 end @testset "issue #23218" begin diff --git a/test/file.jl b/test/file.jl index 9b45dd0f7e7aa..872d253d56573 100644 --- a/test/file.jl +++ b/test/file.jl @@ -64,7 +64,7 @@ end @test filemode(file) & 0o222 > 0 # writable chmod(file, filemode(file) & 0o7555) @test filemode(file) & 0o222 == 0 -chmod(file, filemode(file) | 0o222) +chmod(file, bitor(filemode(file), 0o222)) @test filemode(file) & 0o111 == 0 @test filesize(file) == 0 diff --git a/test/int.jl b/test/int.jl index c988be1593f83..e25e725e9aee6 100644 --- a/test/int.jl +++ b/test/int.jl @@ -228,7 +228,7 @@ end @test UInt64(1) * Int64(-1) === typemax(UInt64) @test UInt(1) - (-1) == 2 @test UInt64(15) & -4 === UInt64(12) -@test UInt64(15) | -4 === typemax(UInt64) +@test bitor(UInt64(15), -4) === typemax(UInt64) @test UInt64(15) ⊻ -4 === 0xfffffffffffffff3 diff --git a/test/numbers.jl b/test/numbers.jl index 53d0418fc0068..adf2fbcb20d64 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2354,7 +2354,7 @@ end for T = (UInt8,Int8,UInt16,Int16,UInt32,Int32,UInt64,Int64,UInt128,Int128) for n = 1:2:1000 @test n*(n^typemax(T)) & typemax(T) == 1 - n = rand(T) | one(T) + n = bitor(rand(T), one(T)) @test n*(n^typemax(T)) == 1 end end @@ -2879,7 +2879,7 @@ end @test T === typeof(t) for R in types - for op in (&, |, <<, >>, (>>>), %, ÷) + for op in (&, bitor, <<, >>, (>>>), %, ÷) T = @inferred Base.promote_op(op, S, R) t = @inferred op(one(S), one(R)) @test T === typeof(t) @@ -3051,7 +3051,7 @@ end sig = [11, 24, 53] for i = 1:length(F), j = 1:length(F) for _ = 1:100 - nan = reinterpret(F[i], rand(U[i]) | reinterpret(U[i], nans[i])) + nan = reinterpret(F[i], bitor(rand(U[i]), reinterpret(U[i], nans[i]))) z = sig[i] - sig[j] nan′ = i <= j ? nan : reinterpret(F[i], reinterpret(U[i], nan) >> z << z) @test convert(F[i], convert(F[j], nan)) === nan′ diff --git a/test/operators.jl b/test/operators.jl index a349269d7e818..482b0061ef2e2 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -48,7 +48,7 @@ p = 1=>:foo @test endof(p) == 2 @test p[endof(p)] == p[end] == p[2] == :foo -@test (|)(2) == 2 +@test bitor(2) == 2 @test xor(2) == 2 @test (⊻)(2) == 2 diff --git a/test/perf/shootout/mandelbrot.jl b/test/perf/shootout/mandelbrot.jl index 62e76de8a89e0..6b934a5d8f233 100644 --- a/test/perf/shootout/mandelbrot.jl +++ b/test/perf/shootout/mandelbrot.jl @@ -24,7 +24,8 @@ function draw_mandel(M::Array{UInt8, 2}, n::Int) for x = 0:n-1 c = complex(2x/n - 1.5, ci) if ismandel(c) - M[div(x, 8) + 1, y + 1] |= 1 << UInt8(7 - x%8) + k = div(x, 8) + 1, y + 1 + M[k] = bitor(M[k], 1 << UInt8(7 - x%8)) end end end diff --git a/test/perf/shootout/meteor_contest.jl b/test/perf/shootout/meteor_contest.jl index 08ca2b9b2ae19..199b8cf8a431d 100644 --- a/test/perf/shootout/meteor_contest.jl +++ b/test/perf/shootout/meteor_contest.jl @@ -70,9 +70,9 @@ function floodFill(board::UInt64, fixme) return board end - board |= UInt64(1) << (x + width*y) + board = bitor(board, UInt64(1) << (x + width*y)) for f in values(move) - board |= floodFill(board, f(x, y)) + board = bitor(board, floodFill(board, f(x, y))) end return board @@ -105,7 +105,7 @@ function getBitmask(x, y, piece) for cell_ in piece x, y = move[cell_](x,y) if valid(x, y) - mask |= UInt64(1) << (x + width*y) + mask = bitor(mask, UInt64(1) << (x + width*y)) else return false, UInt64(0) end @@ -189,7 +189,7 @@ function solveCell(cell_, board::UInt64, n) for mask in masksAtCell[cell_ + 1, color + 1] if legal(mask, board) masks[color + 1] = mask - solveCell(cell_ - 1, UInt64(board | mask), n) + solveCell(cell_ - 1, UInt64(bitor(board, mask)), n) masks[color + 1] = 0 end end diff --git a/test/random.jl b/test/random.jl index 8472c54a177a9..57343d3ebddf3 100644 --- a/test/random.jl +++ b/test/random.jl @@ -315,7 +315,7 @@ end # make sure reading 128-bit ints from RandomDevice works let a = [rand(RandomDevice(), UInt128) for i=1:10] - @test reduce(|, a)>>>64 != 0 + @test reduce(bitor, a)>>>64 != 0 end # test all rand APIs diff --git a/test/read.jl b/test/read.jl index 8014affdc5f35..d57fa5f558cff 100644 --- a/test/read.jl +++ b/test/read.jl @@ -443,7 +443,7 @@ close(f1) close(f2) rm(f) -io = Base.Filesystem.open(f, Base.Filesystem.JL_O_WRONLY | Base.Filesystem.JL_O_CREAT | Base.Filesystem.JL_O_EXCL, 0o000) +io = Base.Filesystem.open(f, bitor(Base.Filesystem.JL_O_WRONLY, Base.Filesystem.JL_O_CREAT, Base.Filesystem.JL_O_EXCL), 0o000) @test write(io, "abc") == 3 close(io) if !Sys.iswindows() && get(ENV, "USER", "") != "root" && get(ENV, "HOME", "") != "/root" diff --git a/test/reduce.jl b/test/reduce.jl index e3c3273247dcf..92311bd28a823 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -49,7 +49,7 @@ @test mapreduce(abs2, Base.scalarmax, Float64[]) === 0.0 @test mapreduce(abs, max, Float64[]) === 0.0 @test_throws ArgumentError mapreduce(abs2, &, Float64[]) -@test_throws ArgumentError mapreduce(abs2, |, Float64[]) +@test_throws ArgumentError mapreduce(abs2, bitor, Float64[]) # mapreduce() type stability @test typeof(mapreduce(*, +, Int8[10])) === diff --git a/test/reducedim.jl b/test/reducedim.jl index 72e9b991a7c4a..110fdf05dbc36 100644 --- a/test/reducedim.jl +++ b/test/reducedim.jl @@ -109,7 +109,7 @@ end @test sum(Union{Float32, Float64}[1.0], 1) == [1.0] @test prod(Union{Float32, Float64}[1.0], 1) == [1.0] -@test reducedim((a,b) -> a|b, [true false; false false], 1, false) == [true false] +@test reducedim((a,b) -> bitor(a, b), [true false; false false], 1, false) == [true false] let R = reducedim((a,b) -> a+b, [1 2; 3 4], 2, 0.0) @test eltype(R) == Float64 @test R ≈ [3,7] diff --git a/test/show.jl b/test/show.jl index 745c388676c2c..674e8d85bfcd0 100644 --- a/test/show.jl +++ b/test/show.jl @@ -185,7 +185,7 @@ end""" # line meta if delta_kd == 0 # line meta - msk_d0 = bitnot(u << ld0) | (u << ld1 << 1) + msk_d0 = bitor(bitnot(u << ld0), u << ld1 << 1) else # line meta msk_d0 = bitnot(u << ld0) @@ -203,7 +203,7 @@ end""" # line meta chunk_s0 = glue_src_bitchunks(src, ks0, ks1, msk_s0, ls0) # line meta - dest[kd0] = (dest[kd0] & msk_d0) | ((chunk_s0 << ld0) & bitnot(msk_d0)) + dest[kd0] = bitor(dest[kd0] & msk_d0, (chunk_s0 << ld0) & bitnot(msk_d0)) # line meta if delta_kd == 0 # line meta @@ -214,7 +214,7 @@ end""" # line meta chunk_s1 = glue_src_bitchunks(src, ks0 + i, ks1, msk_s0, ls0) # line meta - chunk_s = (chunk_s0 >>> (63 - ld0) >>> 1) | (chunk_s1 << ld0) + chunk_s = bitor(chunk_s0 >>> (63 - ld0) >>> 1, chunk_s1 << ld0) # line meta dest[kd0 + i] = chunk_s # line meta @@ -229,9 +229,9 @@ end""" chunk_s1 = UInt64(0) end # line meta - chunk_s = (chunk_s0 >>> (63 - ld0) >>> 1) | (chunk_s1 << ld0) + chunk_s = bitor(chunk_s0 >>> (63 - ld0) >>> 1, chunk_s1 << ld0) # line meta - dest[kd1] = (dest[kd1] & msk_d1) | (chunk_s & bitnot(msk_d1)) + dest[kd1] = bitor(dest[kd1] & msk_d1, chunk_s & bitnot(msk_d1)) # line meta return end""" diff --git a/test/sorting.jl b/test/sorting.jl index 9626c5de9e9b1..d3c5f762a06b0 100644 --- a/test/sorting.jl +++ b/test/sorting.jl @@ -216,7 +216,7 @@ end end ## more advanced sorting tests ## -randnans(n) = reinterpret(Float64,[rand(UInt64)|0x7ff8000000000000 for i=1:n]) +randnans(n) = reinterpret(Float64, [bitor(rand(UInt64), 0x7ff8000000000000) for i=1:n]) function randn_with_nans(n,p) v = randn(n) diff --git a/test/sparse/sparse.jl b/test/sparse/sparse.jl index fa189d41e38a2..b24a22dc92fbc 100644 --- a/test/sparse/sparse.jl +++ b/test/sparse/sparse.jl @@ -66,7 +66,7 @@ do33 = ones(3) @test_throws DimensionMismatch map(max, sqrfloatmat, colfloatmat) sqrboolmat, colboolmat = sprand(Bool, 4, 4, 0.5), sprand(Bool, 4, 1, 0.5) @test_throws DimensionMismatch map(&, sqrboolmat, colboolmat) - @test_throws DimensionMismatch map(|, sqrboolmat, colboolmat) + @test_throws DimensionMismatch map(bitor, sqrboolmat, colboolmat) @test_throws DimensionMismatch map(xor, sqrboolmat, colboolmat) end end @@ -1708,8 +1708,8 @@ end @test broadcast(&, A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3)) @test typeof(broadcast(&, A13024, B13024)) == SparseMatrixCSC{Bool,Int} - @test broadcast(|, A13024, B13024) == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6)) - @test typeof(broadcast(|, A13024, B13024)) == SparseMatrixCSC{Bool,Int} + @test broadcast(bitor, A13024, B13024) == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6)) + @test typeof(broadcast(bitor, A13024, B13024)) == SparseMatrixCSC{Bool,Int} @test broadcast(⊻, A13024, B13024) == sparse([3,4,4], [3,3,4], fill(true,3), 5, 5) @test typeof(broadcast(⊻, A13024, B13024)) == SparseMatrixCSC{Bool,Int} @@ -1723,7 +1723,7 @@ end for op in (+, -) @test op(A13024, B13024) == op(Array(A13024), Array(B13024)) end - for op in (max, min, &, |, xor) + for op in (max, min, &, bitor, xor) @test op.(A13024, B13024) == op.(Array(A13024), Array(B13024)) end end From 71d50efed01313cb6e3f1f9aab45a9651acb6c6d Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Tue, 21 Nov 2017 12:00:15 -0800 Subject: [PATCH 07/17] Replace bitwise calls to | with bitor in base/. --- base/atomics.jl | 2 +- base/bitarray.jl | 110 +++++++++++++++++++------------------- base/bitset.jl | 2 +- base/c.jl | 22 ++++---- base/exports.jl | 1 + base/file.jl | 8 +-- base/float.jl | 62 ++++++++++----------- base/gmp.jl | 2 +- base/hashing2.jl | 6 +-- base/inference.jl | 8 +-- base/int.jl | 4 +- base/io.jl | 18 +++---- base/libc.jl | 2 +- base/libdl.jl | 8 +-- base/libgit2/libgit2.jl | 4 +- base/libgit2/utils.jl | 2 +- base/libgit2/walker.jl | 2 +- base/linalg/bitarray.jl | 8 +-- base/math.jl | 14 ++--- base/multidimensional.jl | 12 ++--- base/nullable.jl | 2 +- base/pcre.jl | 66 +++++++++++------------ base/process.jl | 11 ++-- base/random/RNGs.jl | 6 +-- base/random/generation.jl | 8 +-- base/random/misc.jl | 12 ++--- base/regex.jl | 13 ++--- base/serialize.jl | 6 +-- base/socket.jl | 37 ++++++------- base/special/log.jl | 8 +-- base/special/rem_pio2.jl | 12 ++--- base/strings/io.jl | 2 +- base/strings/search.jl | 4 +- base/strings/string.jl | 41 +++++++------- base/strings/utf8proc.jl | 40 +++++++------- base/subarray.jl | 2 +- base/util.jl | 4 +- 37 files changed, 285 insertions(+), 286 deletions(-) diff --git a/base/atomics.jl b/base/atomics.jl index 61785e2ff0626..705d8731a07fd 100644 --- a/base/atomics.jl +++ b/base/atomics.jl @@ -226,7 +226,7 @@ function atomic_nand! end Atomically bitwise-or `x` with `val` -Performs `x[] |= val` atomically. Returns the **old** value. +Performs `x[] = bitor(x[], val)` atomically. Returns the **old** value. For further details, see LLVM's `atomicrmw or` instruction. diff --git a/base/bitarray.jl b/base/bitarray.jl index c8f885771e1dd..cdee15c623f77 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -107,7 +107,7 @@ function glue_src_bitchunks(src::Vector{UInt64}, k::Int, ks1::Int, msk_s0::UInt6 chunk = ((src[k] & msk_s0) >>> ls0) if ks1 > k && ls0 > 0 chunk_n = (src[k + 1] & bitnot(msk_s0)) - chunk |= (chunk_n << (64 - ls0)) + chunk = bitor(chunk, chunk_n << (64 - ls0)) end end return chunk @@ -129,7 +129,7 @@ function copy_chunks!(dest::Vector{UInt64}, pos_d::Integer, src::Vector{UInt64}, u = _msk64 if delta_kd == 0 - msk_d0 = bitnot(u << ld0) | (u << (ld1+1)) + msk_d0 = bitor(bitnot(u << ld0), u << (ld1+1)) else msk_d0 = bitnot(u << ld0) msk_d1 = (u << (ld1+1)) @@ -142,14 +142,14 @@ function copy_chunks!(dest::Vector{UInt64}, pos_d::Integer, src::Vector{UInt64}, chunk_s0 = glue_src_bitchunks(src, ks0, ks1, msk_s0, ls0) - dest[kd0] = (dest[kd0] & msk_d0) | ((chunk_s0 << ld0) & bitnot(msk_d0)) + dest[kd0] = bitor(dest[kd0] & msk_d0, (chunk_s0 << ld0) & bitnot(msk_d0)) delta_kd == 0 && return for i = 1 : kd1 - kd0 - 1 chunk_s1 = glue_src_bitchunks(src, ks0 + i, ks1, msk_s0, ls0) - chunk_s = (chunk_s0 >>> (64 - ld0)) | (chunk_s1 << ld0) + chunk_s = bitor(chunk_s0 >>> (64 - ld0), chunk_s1 << ld0) dest[kd0 + i] = chunk_s @@ -162,9 +162,9 @@ function copy_chunks!(dest::Vector{UInt64}, pos_d::Integer, src::Vector{UInt64}, chunk_s1 = UInt64(0) end - chunk_s = (chunk_s0 >>> (64 - ld0)) | (chunk_s1 << ld0) + chunk_s = bitor(chunk_s0 >>> (64 - ld0), chunk_s1 << ld0) - dest[kd1] = (dest[kd1] & msk_d1) | (chunk_s & bitnot(msk_d1)) + dest[kd1] = bitor(dest[kd1] & msk_d1, chunk_s & bitnot(msk_d1)) return end @@ -189,7 +189,7 @@ function copy_chunks_rtol!(chunks::Vector{UInt64}, pos_d::Integer, pos_s::Intege delta_ks = ks1 - ks0 if delta_kd == 0 - msk_d0 = bitnot(u << ld0) | (u << (ld1+1)) + msk_d0 = bitor(bitnot(u << ld0), u << (ld1+1)) else msk_d0 = bitnot(u << ld0) msk_d1 = (u << (ld1+1)) @@ -201,12 +201,12 @@ function copy_chunks_rtol!(chunks::Vector{UInt64}, pos_d::Integer, pos_s::Intege end chunk_s0 = glue_src_bitchunks(chunks, ks0, ks1, msk_s0, ls0) & bitnot(u << s) - chunks[kd0] = (chunks[kd0] & msk_d0) | ((chunk_s0 << ld0) & bitnot(msk_d0)) + chunks[kd0] = bitor(chunks[kd0] & msk_d0, (chunk_s0 << ld0) & bitnot(msk_d0)) if delta_kd != 0 chunk_s = (chunk_s0 >>> (64 - ld0)) - chunks[kd1] = (chunks[kd1] & msk_d1) | (chunk_s & bitnot(msk_d1)) + chunks[kd1] = bitor(chunks[kd1] & msk_d1, chunk_s & bitnot(msk_d1)) end left -= s @@ -230,11 +230,11 @@ function fill_chunks!(Bc::Array{UInt64}, x::Bool, pos::Integer, numbits::Integer msk1 = bitnot(u << (l1+1)) end @inbounds if x - Bc[k0] |= msk0 + Bc[k0] = bitor(Bc[k0], msk0) for k = k0+1:k1-1 Bc[k] = u end - k1 > k0 && (Bc[k1] |= msk1) + k1 > k0 && (Bc[k1] = bitor(Bc[k1], msk1)) else Bc[k0] &= bitnot(msk0) for k = k0+1:k1-1 @@ -250,9 +250,9 @@ copy_to_bitarray_chunks!(dest::Vector{UInt64}, pos_d::Int, src::BitArray, pos_s: # pack 8 Bools encoded as one contiguous UIn64 into a single byte, e.g.: # 0000001:0000001:00000000:00000000:00000001:00000000:00000000:00000001 → 11001001 → 0xc9 function pack8bools(z::UInt64) - z |= z >>> 7 - z |= z >>> 14 - z |= z >>> 28 + z = bitor(z, z >>> 7) + z = bitor(z, z >>> 14) + z = bitor(z, z >>> 28) z &= 0xFF return z end @@ -265,7 +265,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} u = _msk64 if delta_kd == 0 - msk_d0 = msk_d1 = bitnot(u << ld0) | (u << (ld1+1)) + msk_d0 = msk_d1 = bitor(bitnot(u << ld0), u << (ld1+1)) lt0 = ld1 else msk_d0 = bitnot(u << ld0) @@ -278,10 +278,10 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} @inbounds if ld0 > 0 c = UInt64(0) for j = ld0:lt0 - c |= (UInt64(C[ind]) << j) + c = bitor(c, UInt64(C[ind]) << j) ind += 1 end - Bc[kd0] = (Bc[kd0] & msk_d0) | (c & bitnot(msk_d0)) + Bc[kd0] = bitor(Bc[kd0] & msk_d0, c & bitnot(msk_d0)) bind += 1 end @@ -294,7 +294,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} c = UInt64(0) for j = 0:7 # unaligned load - c |= (pack8bools(unsafe_load(P8, ind8)) << (j<<3)) + c = bitor(c, pack8bools(unsafe_load(P8, ind8)) << (j<<3)) ind8 += 1 end Bc[bind] = c @@ -305,7 +305,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} @inbounds for i = (nc8+1):nc c = UInt64(0) for j = 0:63 - c |= (UInt64(C[ind]) << j) + c = bitor(c, UInt64(C[ind]) << j) ind += 1 end Bc[bind] = c @@ -315,10 +315,10 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} @assert bind == kd1 c = UInt64(0) for j = 0:ld1 - c |= (UInt64(C[ind]) << j) + c = bitor(c, UInt64(C[ind]) << j) ind += 1 end - Bc[kd1] = (Bc[kd1] & msk_d1) | (c & bitnot(msk_d1)) + Bc[kd1] = bitor(Bc[kd1] & msk_d1, c & bitnot(msk_d1)) end end @@ -457,7 +457,7 @@ function copy!(dest::BitArray, src::BitArray) else msk_s = _msk_end(src) msk_d = bitnot(msk_s) - destc[nc] = (msk_d & destc[nc]) | (msk_s & srcc[nc]) + destc[nc] = bitor(msk_d & destc[nc], msk_s & srcc[nc]) end end return dest @@ -521,14 +521,14 @@ function convert(::Type{BitArray{N}}, A::AbstractArray{T,N}) where N where T for i = 1:length(Bc)-1 c = UInt64(0) for j = 0:63 - c |= (UInt64(convert(Bool, A[ind])) << j) + c = bitor(c, UInt64(convert(Bool, A[ind])) << j) ind += 1 end Bc[i] = c end c = UInt64(0) for j = 0:_mod64(l-1) - c |= (UInt64(convert(Bool, A[ind])) << j) + c = bitor(c, UInt64(convert(Bool, A[ind])) << j) ind += 1 end Bc[end] = c @@ -688,7 +688,7 @@ end u = UInt64(1) << i2 @inbounds begin c = Bc[i1] - Bc[i1] = ifelse(x, c | u, c & bitnot(u)) + Bc[i1] = ifelse(x, bitor(c, u), c & bitnot(u)) end end @@ -726,7 +726,7 @@ function _unsafe_setindex!(B::BitArray, x, I::BitArray) length(Bc) == length(Ic) || throw_boundserror(B, I) @inbounds if y for i = 1:length(Bc) - Bc[i] |= Ic[i] + Bc[i] = bitor(Bc[i], Ic[i]) end else for i = 1:length(Bc) @@ -759,7 +759,7 @@ function _unsafe_setindex!(B::BitArray, X::AbstractArray, I::BitArray) if Imsk & u != 0 lx < c && throw_setindex_mismatch(X, c) @inbounds x = convert(Bool, X[c]) - C = ifelse(x, C | u, C & bitnot(u)) + C = ifelse(x, bitor(C, u), C & bitnot(u)) c += 1 end u <<= 1 @@ -883,9 +883,9 @@ function unshift!(B::BitVector, item) return B end for i = length(Bc) : -1 : 2 - Bc[i] = (Bc[i] << 1) | (Bc[i-1] >>> 63) + Bc[i] = bitor(Bc[i] << 1, Bc[i-1] >>> 63) end - Bc[1] = UInt64(item) | (Bc[1] << 1) + Bc[1] = bitor(UInt64(item), Bc[1] << 1) return B end @@ -897,7 +897,7 @@ function shift!(B::BitVector) Bc = B.chunks for i = 1 : length(Bc) - 1 - Bc[i] = (Bc[i] >>> 1) | (Bc[i+1] << 63) + Bc[i] = bitor(Bc[i] >>> 1, Bc[i+1] << 63) end l = _mod64(length(B)) @@ -929,12 +929,12 @@ function insert!(B::BitVector, i::Integer, item) B.len += 1 for t = length(Bc) : -1 : k + 1 - Bc[t] = (Bc[t] << 1) | (Bc[t - 1] >>> 63) + Bc[t] = bitor(Bc[t] << 1, Bc[t - 1] >>> 63) end msk_aft = (_msk64 << j) msk_bef = bitnot(msk_aft) - Bc[k] = (msk_bef & Bc[k]) | ((msk_aft & Bc[k]) << 1) + Bc[k] = bitor(msk_bef & Bc[k], (msk_aft & Bc[k]) << 1) B[i] = item B end @@ -949,13 +949,13 @@ function _deleteat!(B::BitVector, i::Integer) Bc = B.chunks @inbounds begin - Bc[k] = (msk_bef & Bc[k]) | ((msk_aft & Bc[k]) >> 1) + Bc[k] = bitor(msk_bef & Bc[k], (msk_aft & Bc[k]) >> 1) if length(Bc) > k - Bc[k] |= (Bc[k + 1] << 63) + Bc[k] = bitor(Bc[k], Bc[k + 1] << 63) end for t = k + 1 : length(Bc) - 1 - Bc[t] = (Bc[t] >>> 1) | (Bc[t + 1] << 63) + Bc[t] = bitor(Bc[t] >>> 1, Bc[t + 1] << 63) end l = _mod64(length(B)) @@ -1302,12 +1302,12 @@ end function reverse_bits(src::UInt64) z = src - z = ((z >>> 1) & 0x5555555555555555) | ((z << 1) & 0xaaaaaaaaaaaaaaaa) - z = ((z >>> 2) & 0x3333333333333333) | ((z << 2) & 0xcccccccccccccccc) - z = ((z >>> 4) & 0x0f0f0f0f0f0f0f0f) | ((z << 4) & 0xf0f0f0f0f0f0f0f0) - z = ((z >>> 8) & 0x00ff00ff00ff00ff) | ((z << 8) & 0xff00ff00ff00ff00) - z = ((z >>> 16) & 0x0000ffff0000ffff) | ((z << 16) & 0xffff0000ffff0000) - return ((z >>> 32) & 0x00000000ffffffff) | ((z << 32) & 0xffffffff00000000) + z = bitor((z >>> 1) & 0x5555555555555555, (z << 1) & 0xaaaaaaaaaaaaaaaa) + z = bitor((z >>> 2) & 0x3333333333333333, (z << 2) & 0xcccccccccccccccc) + z = bitor((z >>> 4) & 0x0f0f0f0f0f0f0f0f, (z << 4) & 0xf0f0f0f0f0f0f0f0) + z = bitor((z >>> 8) & 0x00ff00ff00ff00ff, (z << 8) & 0xff00ff00ff00ff00) + z = bitor((z >>> 16) & 0x0000ffff0000ffff, (z << 16) & 0xffff0000ffff0000) + return bitor((z >>> 32) & 0x00000000ffffffff, (z << 32) & 0xffffffff00000000) end function reverse!(B::BitVector) @@ -1342,8 +1342,8 @@ function reverse!(B::BitVector) end u = reverse_bits(B.chunks[i]) B.chunks[i] = 0 - B.chunks[j] |= u >>> h - B.chunks[i] |= v >>> h + B.chunks[j] = bitor(B.chunks[j], u >>> h) + B.chunks[i] = bitor(B.chunks[i], v >>> h) j -= 1 if i == j @@ -1351,14 +1351,14 @@ function reverse!(B::BitVector) end v = reverse_bits(B.chunks[j]) B.chunks[j] = 0 - B.chunks[i] |= v << k - B.chunks[j] |= u << k + B.chunks[i] = bitor(B.chunks[i], v << k) + B.chunks[j] = bitor(B.chunks[j], u << k) end if isodd(length(B.chunks)) - B.chunks[i] |= v >>> h + B.chunks[i] = bitor(B.chunks[i], v >>> h) else - B.chunks[i] |= u << k + B.chunks[i] = bitor(B.chunks[i], u << k) end return B @@ -1536,8 +1536,8 @@ function findnextnot(B::BitArray, start::Integer) mask = bitnot(_msk64 << within_chunk_start) @inbounds if chunk_start < l - if Bc[chunk_start] | mask != _msk64 - return (chunk_start-1) << 6 + trailing_ones(Bc[chunk_start] | mask) + 1 + if bitor(Bc[chunk_start], mask) != _msk64 + return (chunk_start-1) << 6 + trailing_ones(bitor(Bc[chunk_start], mask)) + 1 end for i = chunk_start+1:l-1 if Bc[i] != _msk64 @@ -1547,8 +1547,8 @@ function findnextnot(B::BitArray, start::Integer) if Bc[l] != _msk_end(B) return (l-1) << 6 + trailing_ones(Bc[l]) + 1 end - elseif Bc[l] | mask != _msk_end(B) - return (l-1) << 6 + trailing_ones(Bc[l] | mask) + 1 + elseif bitor(Bc[l], mask) != _msk_end(B) + return (l-1) << 6 + trailing_ones(bitor(Bc[l], mask)) + 1 end return 0 end @@ -1610,8 +1610,8 @@ function findprevnot(B::BitArray, start::Integer) mask = bitnot(_msk_end(start)) @inbounds begin - if Bc[chunk_start] | mask != _msk64 - return (chunk_start-1) << 6 + (64 - leading_ones(Bc[chunk_start] | mask)) + if bitor(Bc[chunk_start], mask) != _msk64 + return (chunk_start-1) << 6 + (64 - leading_ones(bitor(Bc[chunk_start], mask))) end for i = chunk_start-1:-1:1 @@ -1751,8 +1751,8 @@ map!(::typeof(identity), dest::BitArray, A::BitArray) = copy!(dest, A) for (T, f) in ((:(Union{typeof(&), typeof(*), typeof(min)}), :(&)), (:(Union{typeof(|), typeof(max)}), :(|)), (:(Union{typeof(xor), typeof(!=)}), :xor), - (:(Union{typeof(>=), typeof(^)}), :((p, q) -> p | bitnot(q))), - (:(typeof(<=)), :((p, q) -> bitnot(p) | q)), + (:(Union{typeof(>=), typeof(^)}), :((p, q) -> bitor(p, bitnot(q)))), + (:(typeof(<=)), :((p, q) -> bitor(bitnot(p), q))), (:(typeof(==)), :((p, q) -> bitnot(xor(p, q)))), (:(typeof(<)), :((p, q) -> bitnot(p) & q)), (:(typeof(>)), :((p, q) -> p & bitnot(q)))) diff --git a/base/bitset.jl b/base/bitset.jl index 62fd141b9ca2d..e961844af80f5 100644 --- a/base/bitset.jl +++ b/base/bitset.jl @@ -116,7 +116,7 @@ union(s1::BitSet, ss::BitSet...) = union(s1, union(ss...)) union(s::BitSet, ns) = union!(copy(s), ns) union!(s::BitSet, ns) = (for n in ns; push!(s, n); end; s) function union!(s1::BitSet, s2::BitSet) - _matched_map!(|, s1.bits, s2.bits) + _matched_map!(bitor, s1.bits, s2.bits) s1 end diff --git a/base/c.jl b/base/c.jl index c57ce27d6130b..7ad73fefe18df 100644 --- a/base/c.jl +++ b/base/c.jl @@ -302,29 +302,29 @@ function transcode(::Type{UInt8}, src::Vector{UInt16}) if a < 0x80 # ASCII dst[j += 1] = a % UInt8 elseif a < 0x800 # 2-byte UTF-8 - dst[j += 1] = 0xc0 | ((a >> 6) % UInt8) - dst[j += 1] = 0x80 | ((a % UInt8) & 0x3f) + dst[j += 1] = bitor(0xc0, (a >> 6) % UInt8) + dst[j += 1] = bitor(0x80, (a % UInt8) & 0x3f) elseif a & 0xfc00 == 0xd800 && i < n b = src[i += 1] if (b & 0xfc00) == 0xdc00 # 2-unit UTF-16 sequence => 4-byte UTF-8 a += 0x2840 - dst[j += 1] = 0xf0 | ((a >> 8) % UInt8) - dst[j += 1] = 0x80 | ((a % UInt8) >> 2) + dst[j += 1] = bitor(0xf0, (a >> 8) % UInt8) + dst[j += 1] = bitor(0x80, (a % UInt8) >> 2) dst[j += 1] = xor(0xf0, ((a % UInt8) << 4) & 0x3f, (b >> 6) % UInt8) - dst[j += 1] = 0x80 | ((b % UInt8) & 0x3f) + dst[j += 1] = bitor(0x80, (b % UInt8) & 0x3f) else - dst[j += 1] = 0xe0 | ((a >> 12) % UInt8) - dst[j += 1] = 0x80 | (((a >> 6) % UInt8) & 0x3f) - dst[j += 1] = 0x80 | ((a % UInt8) & 0x3f) + dst[j += 1] = bitor(0xe0, (a >> 12) % UInt8) + dst[j += 1] = bitor(0x80, ((a >> 6) % UInt8) & 0x3f) + dst[j += 1] = bitor(0x80, (a % UInt8) & 0x3f) a = b; continue end else # 1-unit high UTF-16 or unpaired high surrogate # either way, encode as 3-byte UTF-8 code point - dst[j += 1] = 0xe0 | ((a >> 12) % UInt8) - dst[j += 1] = 0x80 | (((a >> 6) % UInt8) & 0x3f) - dst[j += 1] = 0x80 | ((a % UInt8) & 0x3f) + dst[j += 1] = bitor(0xe0, (a >> 12) % UInt8) + dst[j += 1] = bitor(0x80, ((a >> 6) % UInt8) & 0x3f) + dst[j += 1] = bitor(0x80, (a % UInt8) & 0x3f) end i < n || break a = src[i += 1] diff --git a/base/exports.jl b/base/exports.jl index 63ef52bd5cd51..ea724842c4231 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -215,6 +215,7 @@ export ^, |, |>, + bitor, bitnot, :, =>, diff --git a/base/file.jl b/base/file.jl index 5f0e15dce2b80..cea0ef93293e7 100644 --- a/base/file.jl +++ b/base/file.jl @@ -245,7 +245,7 @@ end Update the last-modified timestamp on a file to the current time. """ function touch(path::AbstractString) - f = open(path, JL_O_WRONLY | JL_O_CREAT, 0o0666) + f = open(path, bitor(JL_O_WRONLY, JL_O_CREAT), 0o0666) try t = time() futime(f,t,t) @@ -520,8 +520,8 @@ function sendfile(src::AbstractString, dst::AbstractString) try src_file = open(src, JL_O_RDONLY) src_open = true - dst_file = open(dst, JL_O_CREAT | JL_O_TRUNC | JL_O_WRONLY, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP| S_IROTH | S_IWOTH) + dst_file = open(dst, bitor(JL_O_CREAT, JL_O_TRUNC, JL_O_WRONLY), + bitor(S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, S_IWOTH)) dst_open = true bytes = filesize(stat(src_file)) @@ -558,7 +558,7 @@ function symlink(p::AbstractString, np::AbstractString) flags = 0 @static if Sys.iswindows() if isdir(p) - flags |= UV_FS_SYMLINK_JUNCTION + flags = bitor(flags, UV_FS_SYMLINK_JUNCTION) p = abspath(p) end end diff --git a/base/float.jl b/base/float.jl index 14e6d18d64d08..f87a73e778db1 100644 --- a/base/float.jl +++ b/base/float.jl @@ -101,7 +101,7 @@ function convert(::Type{Float64}, x::Int128) y &= bitnot(UInt64(trailing_zeros(x) == (n-54))) # fix last bit to round to even end d = ((n+1022) % UInt64) << 52 - reinterpret(Float64, s | d + y) + reinterpret(Float64, bitor(s, d) + y) end function convert(::Type{Float32}, x::UInt128) @@ -131,7 +131,7 @@ function convert(::Type{Float32}, x::Int128) y &= bitnot(UInt32(trailing_zeros(x) == (n-25))) # fix last bit to round to even end d = ((n+126) % UInt32) << 23 - reinterpret(Float32, s | d + y) + reinterpret(Float32, bitor(s, d) + y) end function convert(::Type{Float16}, val::Float32) @@ -167,7 +167,7 @@ function convert(::Type{Float32}, val::Float16) if exp == 0 if sig == 0 sign = sign << 31 - ret = sign | exp | sig + ret = bitor(sign, exp, sig) else n_bit = 1 bit = 0x0200 @@ -178,7 +178,7 @@ function convert(::Type{Float32}, val::Float16) sign = sign << 31 exp = (-14 - n_bit + 127) << 23 sig = ((sig & bitnot(bit)) << n_bit) << (23 - 10) - ret = sign | exp | sig + ret = bitor(sign, exp, sig) end elseif exp == 0x1f if sig == 0 # Inf @@ -188,13 +188,13 @@ function convert(::Type{Float32}, val::Float16) ret = 0xff800000 end else # NaN - ret = 0x7fc00000 | (sign<<31) | (sig<<(23-10)) + ret = bitor(0x7fc00000, sign << 31, sig << (23-10)) end else sign = sign << 31 exp = (exp - 15 + 127) << 23 sig = sig << (23 - 10) - ret = sign | exp | sig + ret = bitor(sign, exp, sig) end return reinterpret(Float32, ret) end @@ -209,30 +209,30 @@ const shifttable = Vector{UInt8}(512) for i = 0:255 e = i - 127 if e < -24 # Very small numbers map to zero - basetable[i|0x000+1] = 0x0000 - basetable[i|0x100+1] = 0x8000 - shifttable[i|0x000+1] = 24 - shifttable[i|0x100+1] = 24 + basetable[bitor(i, 0x000) + 1] = 0x0000 + basetable[bitor(i, 0x100) + 1] = 0x8000 + shifttable[bitor(i, 0x000) + 1] = 24 + shifttable[bitor(i, 0x100) + 1] = 24 elseif e < -14 # Small numbers map to denorms - basetable[i|0x000+1] = (0x0400>>(-e-14)) - basetable[i|0x100+1] = (0x0400>>(-e-14)) | 0x8000 - shifttable[i|0x000+1] = -e-1 - shifttable[i|0x100+1] = -e-1 + basetable[bitor(i, 0x000) + 1] = (0x0400>>(-e-14)) + basetable[bitor(i, 0x100) + 1] = bitor(0x0400>>(-e-14), 0x8000) + shifttable[bitor(i, 0x000) + 1] = -e-1 + shifttable[bitor(i, 0x100) + 1] = -e-1 elseif e <= 15 # Normal numbers just lose precision - basetable[i|0x000+1] = ((e+15)<<10) - basetable[i|0x100+1] = ((e+15)<<10) | 0x8000 - shifttable[i|0x000+1] = 13 - shifttable[i|0x100+1] = 13 + basetable[bitor(i, 0x000) + 1] = ((e+15)<<10) + basetable[bitor(i, 0x100) + 1] = bitor((e+15)<<10, 0x8000) + shifttable[bitor(i, 0x000) + 1] = 13 + shifttable[bitor(i, 0x100) + 1] = 13 elseif e < 128 # Large numbers map to Infinity - basetable[i|0x000+1] = 0x7C00 - basetable[i|0x100+1] = 0xFC00 - shifttable[i|0x000+1] = 24 - shifttable[i|0x100+1] = 24 + basetable[bitor(i, 0x000) + 1] = 0x7C00 + basetable[bitor(i, 0x100) + 1] = 0xFC00 + shifttable[bitor(i, 0x000) + 1] = 24 + shifttable[bitor(i, 0x100) + 1] = 24 else # Infinity and NaN's stay Infinity and NaN's - basetable[i|0x000+1] = 0x7C00 - basetable[i|0x100+1] = 0xFC00 - shifttable[i|0x000+1] = 13 - shifttable[i|0x100+1] = 13 + basetable[bitor(i, 0x000) + 1] = 0x7C00 + basetable[bitor(i, 0x100) + 1] = 0xFC00 + shifttable[bitor(i, 0x000) + 1] = 13 + shifttable[bitor(i, 0x100) + 1] = 13 end end #convert(::Type{Float16}, x::Float32) = fptrunc(Float16, x) @@ -307,7 +307,7 @@ end function unsafe_trunc(::Type{UInt128}, x::Float64) xu = reinterpret(UInt64,x) k = Int(xu >> 52) & 0x07ff - 1075 - xu = (xu & 0x000f_ffff_ffff_ffff) | 0x0010_0000_0000_0000 + xu = bitor(xu & 0x000f_ffff_ffff_ffff, 0x0010_0000_0000_0000) if k <= 0 UInt128(xu >> -k) else @@ -321,7 +321,7 @@ end function unsafe_trunc(::Type{UInt128}, x::Float32) xu = reinterpret(UInt32,x) k = Int(xu >> 23) & 0x00ff - 150 - xu = (xu & 0x007f_ffff) | 0x0080_0000 + xu = bitor(xu & 0x007f_ffff, 0x0080_0000) if k <= 0 UInt128(xu >> -k) else @@ -432,10 +432,10 @@ end function ==(x::Float16, y::Float16) ix = reinterpret(UInt16,x) iy = reinterpret(UInt16,y) - if (ix|iy)&0x7fff > 0x7c00 #isnan(x) || isnan(y) + if bitor(ix, iy) & 0x7fff > 0x7c00 #isnan(x) || isnan(y) return false end - if (ix|iy)&0x7fff == 0x0000 + if bitor(ix, iy) & 0x7fff == 0x0000 return true end return ix == iy @@ -640,7 +640,7 @@ function nextfloat(f::IEEEFloat, d::Integer) end end if fneg - fu |= sign_mask(F) + fu = bitor(fu, sign_mask(F)) end reinterpret(F, fu) end diff --git a/base/gmp.jl b/base/gmp.jl index 5ec33c838e00f..877f01dfda18b 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -4,7 +4,7 @@ module GMP export BigInt -import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, bitnot, (&), (|), xor, +import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, bitnot, (&), bitor, xor, binomial, cmp, convert, div, divrem, factorial, fld, gcd, gcdx, lcm, mod, ndigits, promote_rule, rem, show, isqrt, string, powermod, sum, trailing_zeros, trailing_ones, count_ones, base, tryparse_internal, diff --git a/base/hashing2.jl b/base/hashing2.jl index b4c548b2ccab1..c333962999673 100644 --- a/base/hashing2.jl +++ b/base/hashing2.jl @@ -102,7 +102,7 @@ function decompose(x::Float16)::NTuple{3,Int} n = reinterpret(UInt16, x) s = (n & 0x03ff) % Int16 e = (n & 0x7c00 >> 10) % Int - s |= Int16(e != 0) << 10 + s = bitor(s, Int16(e != 0) << 10) d = ifelse(signbit(x), -1, 1) s, e - 25 + (e == 0), d end @@ -113,7 +113,7 @@ function decompose(x::Float32)::NTuple{3,Int} n = reinterpret(UInt32, x) s = (n & 0x007fffff) % Int32 e = (n & 0x7f800000 >> 23) % Int - s |= Int32(e != 0) << 23 + s = bitor(s, Int32(e != 0) << 23) d = ifelse(signbit(x), -1, 1) s, e - 150 + (e == 0), d end @@ -124,7 +124,7 @@ function decompose(x::Float64)::Tuple{Int64, Int, Int} n = reinterpret(UInt64, x) s = (n & 0x000fffffffffffff) % Int64 e = (n & 0x7ff0000000000000 >> 52) % Int - s |= Int64(e != 0) << 52 + s = bitor(s, Int64(e != 0) << 52) d = ifelse(signbit(x), -1, 1) s, e - 1075 + (e == 0), d end diff --git a/base/inference.jl b/base/inference.jl index 50e1218edaed3..dfd647bff4caa 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -44,7 +44,7 @@ struct InferenceParams end end -# alloc_elim_pass! relies on `Slot_AssignedOnce | Slot_UsedUndef` being +# alloc_elim_pass! relies on `bitor(Slot_AssignedOnce, Slot_UsedUndef)` being # SSA. This should be true now but can break if we start to track conditional # constants. e.g. # @@ -3691,7 +3691,7 @@ function finish(me::InferenceState) # don't store inferred code if we've decided to interpret this function if !already_inferred && me.linfo.jlcall_api != 4 - const_flags = (me.const_ret) << 1 | me.const_api + const_flags = bitor((me.const_ret) << 1, me.const_api) if me.const_ret if isa(me.bestguess, Const) inferred_const = (me.bestguess::Const).val @@ -3870,7 +3870,7 @@ function type_annotate!(sv::InferenceState) # finish marking used-undef variables for j = 1:nslots if undefs[j] - src.slotflags[j] |= Slot_UsedUndef + src.slotflags[j] = bitor(src.slotflags[j], Slot_UsedUndef) end end @@ -6042,7 +6042,7 @@ function alloc_elim_pass!(sv::OptimizationState) sv.src.slotnames[slot_id(var)]) tmpv_id = slot_id(tmpv) new_slots[j] = tmpv_id - sv.src.slotflags[tmpv_id] |= Slot_UsedUndef + sv.src.slotflags[tmpv_id] = bitor(sv.src.slotflags[tmpv_id], Slot_UsedUndef) end tmp = Expr(:(=), tmpv, tupelt) insert!(body, i+n_ins, tmp) diff --git a/base/int.jl b/base/int.jl index b01c27ced42f8..6863b5ccfb93b 100644 --- a/base/int.jl +++ b/base/int.jl @@ -283,10 +283,10 @@ Bitwise or. # Examples ```jldoctest -julia> 4 | 10 +julia> bitor(4, 10) 14 -julia> 4 | 1 +julia> bitor(4, 1) 5 ``` """ diff --git a/base/io.jl b/base/io.jl index bd7b884e3f4ac..401ff76956456 100644 --- a/base/io.jl +++ b/base/io.jl @@ -406,17 +406,17 @@ function write(s::IO, ch::Char) if c < 0x80 return write(s, c%UInt8) elseif c < 0x800 - return (write(s, (( c >> 6 ) | 0xC0)%UInt8)) + - (write(s, (( c & 0x3F ) | 0x80)%UInt8)) + return (write(s, bitor(c >> 6 , 0xC0) % UInt8)) + + (write(s, bitor(c & 0x3F, 0x80) % UInt8)) elseif c < 0x10000 - return (write(s, (( c >> 12 ) | 0xE0)%UInt8)) + - (write(s, (((c >> 6) & 0x3F ) | 0x80)%UInt8)) + - (write(s, (( c & 0x3F ) | 0x80)%UInt8)) + return (write(s, bitor(c >> 12 , 0xE0) % UInt8)) + + (write(s, bitor((c >> 6) & 0x3F, 0x80) % UInt8)) + + (write(s, bitor(c & 0x3F, 0x80) % UInt8)) elseif c < 0x110000 - return (write(s, (( c >> 18 ) | 0xF0)%UInt8)) + - (write(s, (((c >> 12) & 0x3F ) | 0x80)%UInt8)) + - (write(s, (((c >> 6) & 0x3F ) | 0x80)%UInt8)) + - (write(s, (( c & 0x3F ) | 0x80)%UInt8)) + return (write(s, bitor(c >> 18 , 0xF0) % UInt8)) + + (write(s, bitor((c >> 12) & 0x3F, 0x80) % UInt8)) + + (write(s, bitor((c >> 6) & 0x3F, 0x80) % UInt8)) + + (write(s, bitor(c & 0x3F, 0x80) % UInt8)) else return write(s, '\ufffd') end diff --git a/base/libc.jl b/base/libc.jl index b6f76e3cb749f..1437feaf6d61b 100644 --- a/base/libc.jl +++ b/base/libc.jl @@ -303,7 +303,7 @@ if Sys.iswindows() lpMsgBuf = Ref{Ptr{UInt16}}() lpMsgBuf[] = 0 len = ccall(:FormatMessageW, stdcall, UInt32, (Cint, Ptr{Void}, Cint, Cint, Ptr{Ptr{UInt16}}, Cint, Ptr{Void}), - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, + bitor(FORMAT_MESSAGE_ALLOCATE_BUFFER, FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_MAX_WIDTH_MASK), C_NULL, e, 0, lpMsgBuf, 0, C_NULL) p = lpMsgBuf[] len == 0 && return "" diff --git a/base/libdl.jl b/base/libdl.jl index 9081709b971fb..5367ef545cb5c 100644 --- a/base/libdl.jl +++ b/base/libdl.jl @@ -94,10 +94,10 @@ between shared libraries. """ function dlopen end -dlopen(s::Symbol, flags::Integer = RTLD_LAZY | RTLD_DEEPBIND) = +dlopen(s::Symbol, flags::Integer = bitor(RTLD_LAZY, RTLD_DEEPBIND)) = dlopen(string(s), flags) -dlopen(s::AbstractString, flags::Integer = RTLD_LAZY | RTLD_DEEPBIND) = +dlopen(s::AbstractString, flags::Integer = bitor(RTLD_LAZY, RTLD_DEEPBIND)) = ccall(:jl_load_dynamic_library, Ptr{Void}, (Cstring,UInt32), s, flags) """ @@ -107,10 +107,10 @@ Similar to [`dlopen`](@ref), except returns a `NULL` pointer instead of raising """ function dlopen_e end -dlopen_e(s::Symbol, flags::Integer = RTLD_LAZY | RTLD_DEEPBIND) = +dlopen_e(s::Symbol, flags::Integer = bitor(RTLD_LAZY, RTLD_DEEPBIND)) = dlopen_e(string(s), flags) -dlopen_e(s::AbstractString, flags::Integer = RTLD_LAZY | RTLD_DEEPBIND) = +dlopen_e(s::AbstractString, flags::Integer = bitor(RTLD_LAZY, RTLD_DEEPBIND)) = ccall(:jl_load_dynamic_library_e, Ptr{Void}, (Cstring,UInt32), s, flags) """ diff --git a/base/libgit2/libgit2.jl b/base/libgit2/libgit2.jl index 3230725142fd4..436fcc9d45ef9 100644 --- a/base/libgit2/libgit2.jl +++ b/base/libgit2/libgit2.jl @@ -883,8 +883,8 @@ function restore(s::State, repo::GitRepo) with(GitIndex, repo) do idx read_tree!(idx, s.work) # move work tree to index opts = CheckoutOptions( - checkout_strategy = Consts.CHECKOUT_FORCE | # check the index out to work - Consts.CHECKOUT_REMOVE_UNTRACKED) # remove everything else + checkout_strategy = bitor(Consts.CHECKOUT_FORCE, # check the index out to work + Consts.CHECKOUT_REMOVE_UNTRACKED)) # remove everything else checkout_index(repo, Nullable(idx), options = opts) read_tree!(idx, s.index) # restore index diff --git a/base/libgit2/utils.jl b/base/libgit2/utils.jl index 22cabf70572be..9dfec6316d89a 100644 --- a/base/libgit2/utils.jl +++ b/base/libgit2/utils.jl @@ -59,7 +59,7 @@ reset(val::Integer, flag::Integer) = (val &= bitnot(flag)) Flip the bits of `val` indexed by `flag`, so that if a bit is `0` it will be `1` after the toggle, and vice-versa. """ -toggle(val::Integer, flag::Integer) = (val |= flag) +toggle(val::Integer, flag::Integer) = bitor(val, flag) """ features() diff --git a/base/libgit2/walker.jl b/base/libgit2/walker.jl index e1b15f68fd241..85fafeeeb9319 100644 --- a/base/libgit2/walker.jl +++ b/base/libgit2/walker.jl @@ -75,7 +75,7 @@ function Base.push!(w::GitRevWalker, range::AbstractString) end function Base.sort!(w::GitRevWalker; by::Cint = Consts.SORT_NONE, rev::Bool=false) - rev && (by |= Consts.SORT_REVERSE) + rev && (by = bitor(by, Consts.SORT_REVERSE)) ccall((:git_revwalk_sorting, :libgit2), Void, (Ptr{Void}, Cint), w.ptr, by) return w end diff --git a/base/linalg/bitarray.jl b/base/linalg/bitarray.jl index 816a063d11f97..dfa41f48f3677 100644 --- a/base/linalg/bitarray.jl +++ b/base/linalg/bitarray.jl @@ -220,10 +220,10 @@ function form_8x8_chunk(Bc::Vector{UInt64}, i1::Int, i2::Int, m::Int, cgap::Int, r = 0 for j = 1:8 k > nc && break - x |= ((Bc[k] >>> l) & msk8) << r + x = bitor(x, ((Bc[k] >>> l) & msk8) << r) if l + 8 >= 64 && nc > k r0 = 8 - Base._mod64(l + 8) - x |= (Bc[k + 1] & (msk8 >>> r0)) << (r + r0) + x = bitor(x, (Bc[k + 1] & (msk8 >>> r0)) << (r + r0)) end k += cgap + (l + cinc >= 64 ? 1 : 0) l = Base._mod64(l + cinc) @@ -238,10 +238,10 @@ function put_8x8_chunk(Bc::Vector{UInt64}, i1::Int, i2::Int, x::UInt64, m::Int, r = 0 for j = 1:8 k > nc && break - Bc[k] |= ((x >>> r) & msk8) << l + Bc[k] = bitor(Bc[k], ((x >>> r) & msk8) << l) if l + 8 >= 64 && nc > k r0 = 8 - Base._mod64(l + 8) - Bc[k + 1] |= ((x >>> (r + r0)) & (msk8 >>> r0)) + Bc[k + 1] = bitor(Bc[k + 1], (x >>> (r + r0)) & (msk8 >>> r0)) end k += cgap + (l + cinc >= 64 ? 1 : 0) l = Base._mod64(l + cinc) diff --git a/base/math.jl b/base/math.jl index f407ef2ec8de6..6ebc9276e7afd 100644 --- a/base/math.jl +++ b/base/math.jl @@ -549,7 +549,7 @@ function ldexp(x::T, e::Integer) where T<:IEEEFloat xs == 0 && return x # +-0 m = leading_zeros(xs) - exponent_bits(T) ys = xs << unsigned(m) - xu = ys | (xu & sign_mask(T)) + xu = bitor(ys, xu & sign_mask(T)) k = 1 - m # underflow, otherwise may have integer underflow in the following n + k e < -50000 && return flipsign(T(0.0), x) @@ -568,7 +568,7 @@ function ldexp(x::T, e::Integer) where T<:IEEEFloat return flipsign(T(Inf), x) end if k > 0 # normal case - xu = (xu & bitnot(exponent_mask(T))) | (rem(k, uinttype(T)) << significand_bits(T)) + xu = bitor(xu & bitnot(exponent_mask(T)), rem(k, uinttype(T)) << significand_bits(T)) return reinterpret(T, xu) else # subnormal case if k <= -significand_bits(T) # underflow @@ -578,7 +578,7 @@ function ldexp(x::T, e::Integer) where T<:IEEEFloat end k += significand_bits(T) z = T(2.0)^-significand_bits(T) - xu = (xu & bitnot(exponent_mask(T))) | (rem(k, uinttype(T)) << significand_bits(T)) + xu = bitor(xu & bitnot(exponent_mask(T)), rem(k, uinttype(T)) << significand_bits(T)) return z*reinterpret(T, xu) end end @@ -627,9 +627,9 @@ function significand(x::T) where T<:IEEEFloat xs == 0 && return x # +-0 m = unsigned(leading_zeros(xs) - exponent_bits(T)) xs <<= m - xu = xs | (xu & sign_mask(T)) + xu = bitor(xs, xu & sign_mask(T)) end - xu = (xu & bitnot(exponent_mask(T))) | exponent_one(T) + xu = bitor(xu & bitnot(exponent_mask(T)), exponent_one(T)) return reinterpret(T, xu) end @@ -648,11 +648,11 @@ function frexp(x::T) where T<:IEEEFloat xs == 0 && return x, 0 # +-0 m = leading_zeros(xs) - exponent_bits(T) xs <<= unsigned(m) - xu = xs | (xu & sign_mask(T)) + xu = bitor(xs, xu & sign_mask(T)) k = 1 - m end k -= (exponent_bias(T) - 1) - xu = (xu & bitnot(exponent_mask(T))) | exponent_half(T) + xu = bitor(xu & bitnot(exponent_mask(T)), exponent_half(T)) return reinterpret(T, xu), k end diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 1e7376a8b742b..7866ab87d1da0 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -1199,7 +1199,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra u = _msk64 if delta_kd == 0 - msk_d0 = msk_d1 = bitnot(u << ld0) | (u << (ld1+1)) + msk_d0 = msk_d1 = bitor(bitnot(u << ld0), u << (ld1+1)) lt0 = ld1 else msk_d0 = bitnot(u << ld0) @@ -1212,10 +1212,10 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra @inbounds if ld0 > 0 c = UInt64(0) for j = ld0:lt0 - c |= (UInt64(unchecked_bool_convert(C[ind])) << j) + c = bitor(c, UInt64(unchecked_bool_convert(C[ind])) << j) ind += 1 end - Bc[kd0] = (Bc[kd0] & msk_d0) | (c & bitnot(msk_d0)) + Bc[kd0] = bitor(Bc[kd0] & msk_d0, c & bitnot(msk_d0)) bind += 1 end @@ -1223,7 +1223,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra @inbounds for i = 1:nc c = UInt64(0) for j = 0:63 - c |= (UInt64(unchecked_bool_convert(C[ind])) << j) + c = bitor(c, UInt64(unchecked_bool_convert(C[ind])) << j) ind += 1 end Bc[bind] = c @@ -1234,10 +1234,10 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra @assert bind == kd1 c = UInt64(0) for j = 0:ld1 - c |= (UInt64(unchecked_bool_convert(C[ind])) << j) + c = bitor(c, UInt64(unchecked_bool_convert(C[ind])) << j) ind += 1 end - Bc[kd1] = (Bc[kd1] & msk_d1) | (c & bitnot(msk_d1)) + Bc[kd1] = bitor(Bc[kd1] & msk_d1, c & bitnot(msk_d1)) end end diff --git a/base/nullable.jl b/base/nullable.jl index a5b681ea62db5..38f29fa144b33 100644 --- a/base/nullable.jl +++ b/base/nullable.jl @@ -402,7 +402,7 @@ null_safe_op(::typeof(!), ::Type{Bool}) = true # Note this list does not include ^, ÷ and % # Operations between signed and unsigned types are not safe: promotion to unsigned # gives an InexactError for negative numbers -for op in (+, -, *, /, &, |, <<, >>, >>>, +for op in (+, -, *, /, &, bitor, <<, >>, >>>, scalarmin, scalarmax) # to fix ambiguities global null_safe_op diff --git a/base/pcre.jl b/base/pcre.jl index 6696e5b530039..dd7b3a7e80403 100644 --- a/base/pcre.jl +++ b/base/pcre.jl @@ -30,42 +30,42 @@ end # supported options for different use cases -const COMPILE_MASK = - ANCHORED | - CASELESS | - DOLLAR_ENDONLY | - DOTALL | - EXTENDED | - FIRSTLINE | - MULTILINE | - NEWLINE_ANY | - NEWLINE_ANYCRLF | - NEWLINE_CR | - NEWLINE_CRLF | - NEWLINE_LF | - NO_AUTO_CAPTURE | - NO_START_OPTIMIZE | - NO_UTF_CHECK | - UNGREEDY | +const COMPILE_MASK = bitor( + ANCHORED , + CASELESS , + DOLLAR_ENDONLY , + DOTALL , + EXTENDED , + FIRSTLINE , + MULTILINE , + NEWLINE_ANY , + NEWLINE_ANYCRLF , + NEWLINE_CR , + NEWLINE_CRLF , + NEWLINE_LF , + NO_AUTO_CAPTURE , + NO_START_OPTIMIZE , + NO_UTF_CHECK , + UNGREEDY ) UTF -const EXECUTE_MASK = - NEWLINE_ANY | - NEWLINE_ANYCRLF | - NEWLINE_CR | - NEWLINE_CRLF | - NEWLINE_LF | - NOTBOL | - NOTEMPTY | - NOTEMPTY_ATSTART | - NOTEOL | - NO_START_OPTIMIZE | - NO_UTF_CHECK | - PARTIAL_HARD | - PARTIAL_SOFT +const EXECUTE_MASK = bitor( + NEWLINE_ANY , + NEWLINE_ANYCRLF , + NEWLINE_CR , + NEWLINE_CRLF , + NEWLINE_LF , + NOTBOL , + NOTEMPTY , + NOTEMPTY_ATSTART , + NOTEOL , + NO_START_OPTIMIZE , + NO_UTF_CHECK , + PARTIAL_HARD , + PARTIAL_SOFT ) -const OPTIONS_MASK = COMPILE_MASK | EXECUTE_MASK +const OPTIONS_MASK = bitor(COMPILE_MASK, EXECUTE_MASK) const UNSET = bitnot(Csize_t(0)) # Indicates that an output vector element is unset @@ -173,7 +173,7 @@ function capture_names(re) # big-endian 16-bit value. high_byte = UInt16(unsafe_load(nametable_ptr, offset)) low_byte = UInt16(unsafe_load(nametable_ptr, offset+1)) - idx = (high_byte << 8) | low_byte + idx = bitor(high_byte << 8, low_byte) # The capture group name is a null-terminated string located directly # after the index. names[idx] = unsafe_string(nametable_ptr+offset+1) diff --git a/base/process.jl b/base/process.jl index 84b921e607748..c2bc8726e4c89 100644 --- a/base/process.jl +++ b/base/process.jl @@ -22,9 +22,9 @@ struct Cmd <: AbstractCmd detach::Bool = 0 != cmd.flags & UV_PROCESS_DETACHED, windows_verbatim::Bool = 0 != cmd.flags & UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS, windows_hide::Bool = 0 != cmd.flags & UV_PROCESS_WINDOWS_HIDE) - flags = detach*UV_PROCESS_DETACHED | - windows_verbatim*UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS | - windows_hide*UV_PROCESS_WINDOWS_HIDE + flags = bitor(detach * UV_PROCESS_DETACHED, + windows_hide * UV_PROCESS_WINDOWS_HIDE, + windows_verbatim * UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS) new(cmd.exec, ignorestatus, flags, byteenv(env), dir === cmd.dir ? dir : cstr(dir)) end @@ -468,9 +468,8 @@ function setup_stdio(stdio::FileRedirect, readable::Bool) attr = JL_O_RDONLY perm = zero(S_IRUSR) else - attr = JL_O_WRONLY | JL_O_CREAT - attr |= stdio.append ? JL_O_APPEND : JL_O_TRUNC - perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH + attr = bitor(JL_O_WRONLY, JL_O_CREAT, stdio.append ? JL_O_APPEND : JL_O_TRUNC) + perm = bitor(S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH) end io = Filesystem.open(stdio.filename, attr, perm) return (io, true) diff --git a/base/random/RNGs.jl b/base/random/RNGs.jl index e9f12b61d32f5..cd1064cbf9433 100644 --- a/base/random/RNGs.jl +++ b/base/random/RNGs.jl @@ -216,7 +216,7 @@ rand_ui52_raw(r::MersenneTwister) = (reserve_1(r); rand_ui52_raw_inbounds(r)) function rand_ui2x52_raw(r::MersenneTwister) reserve(r, 2) - rand_ui52_raw_inbounds(r) % UInt128 << 64 | rand_ui52_raw_inbounds(r) + bitor(rand_ui52_raw_inbounds(r) % UInt128 << 64, rand_ui52_raw_inbounds(r)) end function rand_ui104_raw(r::MersenneTwister) @@ -318,10 +318,10 @@ function rand!(r::MersenneTwister, A::Array{Float64}, n::Int=length(A), end mask128(u::UInt128, ::Type{Float16}) = - (u & 0x03ff03ff03ff03ff03ff03ff03ff03ff) | 0x3c003c003c003c003c003c003c003c00 + bitor(u & 0x03ff03ff03ff03ff03ff03ff03ff03ff, 0x3c003c003c003c003c003c003c003c00) mask128(u::UInt128, ::Type{Float32}) = - (u & 0x007fffff007fffff007fffff007fffff) | 0x3f8000003f8000003f8000003f800000 + bitor(u & 0x007fffff007fffff007fffff007fffff, 0x3f8000003f8000003f8000003f800000) function rand!(r::MersenneTwister, A::Union{Array{Float16},Array{Float32}}, ::Close1Open2_64) diff --git a/base/random/generation.jl b/base/random/generation.jl index b83f841a476a9..f13682e9d20bc 100644 --- a/base/random/generation.jl +++ b/base/random/generation.jl @@ -19,13 +19,13 @@ rand(r::AbstractRNG=GLOBAL_RNG, ::Type{T}=Float64) where {T<:AbstractFloat} = rand_generic(r::AbstractRNG, ::CloseOpen{Float16}) = Float16(reinterpret(Float32, - (rand_ui10_raw(r) % UInt32 << 13) & 0x007fe000 | 0x3f800000) - 1) + bitor((rand_ui10_raw(r) % UInt32 << 13) & 0x007fe000, 0x3f800000) - 1) rand_generic(r::AbstractRNG, ::CloseOpen{Float32}) = - reinterpret(Float32, rand_ui23_raw(r) % UInt32 & 0x007fffff | 0x3f800000) - 1 + reinterpret(Float32, bitor(rand_ui23_raw(r) % UInt32 & 0x007fffff, 0x3f800000) - 1 rand_generic(r::AbstractRNG, ::Close1Open2_64) = - reinterpret(Float64, 0x3ff0000000000000 | rand(r, UInt64) & 0x000fffffffffffff) + reinterpret(Float64, bitor(0x3ff0000000000000, rand(r, UInt64) & 0x000fffffffffffff)) rand_generic(r::AbstractRNG, ::CloseOpen_64) = rand(r, Close1Open2()) - 1.0 @@ -55,7 +55,7 @@ function _rand(rng::AbstractRNG, gen::BigFloatRandGenerator) @inbounds begin limbs[1] <<= gen.shift randbool = iszero(limbs[end] & Limb_high_bit) - limbs[end] |= Limb_high_bit + limbs[end] = bitor(limbs[end], Limb_high_bit) end z.sign = 1 Base.@gc_preserve limbs unsafe_copy!(z.d, pointer(limbs), gen.nlimbs) diff --git a/base/random/misc.jl b/base/random/misc.jl index c749211aed81b..a42bf308173ff 100644 --- a/base/random/misc.jl +++ b/base/random/misc.jl @@ -381,7 +381,7 @@ function uuid1(rng::AbstractRNG=GLOBAL_RNG) u &= 0x00000000000000003fffffffffffffff # set the unicast/multicast bit and version - u |= 0x00000000000010000000010000000000 + u = bitor(u, 0x00000000000010000000010000000000) # 0x01b21dd213814000 is the number of 100 nanosecond intervals # between the UUID epoch and Unix epoch @@ -390,9 +390,9 @@ function uuid1(rng::AbstractRNG=GLOBAL_RNG) ts_mid = (timestamp >> 32) & typemax(UInt16) ts_hi = (timestamp >> 48) & 0x0fff - u |= UInt128(ts_low) << 96 - u |= UInt128(ts_mid) << 80 - u |= UInt128(ts_hi) << 64 + u = bitor(u, UInt128(ts_low) << 96) + u = bitor(u, UInt128(ts_mid) << 80) + u = bitor(u, UInt128(ts_hi) << 64) UUID(u) end @@ -414,7 +414,7 @@ julia> Base.Random.uuid4(rng) function uuid4(rng::AbstractRNG=GLOBAL_RNG) u = rand(rng, UInt128) u &= 0xffffffffffff0fff3fffffffffffffff - u |= 0x00000000000040008000000000000000 + u = bitor(u, 0x00000000000040008000000000000000) UUID(u) end @@ -447,7 +447,7 @@ let groupings = [1:8; 10:13; 15:18; 20:23; 25:36] for i in groupings u <<= 4 d = s[i] - '0' - u |= 0xf & (d - 39*(d > 9)) + u = bitor(u, 0xf & (d - 39*(d > 9))) end return UUID(u) end diff --git a/base/regex.jl b/base/regex.jl index b5699b4885971..898855ccf110e 100644 --- a/base/regex.jl +++ b/base/regex.jl @@ -4,7 +4,7 @@ include("pcre.jl") -const DEFAULT_COMPILER_OPTS = PCRE.UTF | PCRE.NO_UTF_CHECK | PCRE.ALT_BSUX +const DEFAULT_COMPILER_OPTS = bitor(PCRE.UTF, PCRE.NO_UTF_CHECK, PCRE.ALT_BSUX) const DEFAULT_MATCH_OPTS = PCRE.NO_UTF_CHECK mutable struct Regex @@ -40,11 +40,12 @@ end function Regex(pattern::AbstractString, flags::AbstractString) options = DEFAULT_COMPILER_OPTS for f in flags - options |= f=='i' ? PCRE.CASELESS : + flagbits = f=='i' ? PCRE.CASELESS : f=='m' ? PCRE.MULTILINE : f=='s' ? PCRE.DOTALL : f=='x' ? PCRE.EXTENDED : throw(ArgumentError("unknown regex flag: $f")) + options = bitor(options, flagbits) end Regex(pattern, options, DEFAULT_MATCH_OPTS) end @@ -83,7 +84,7 @@ RegexMatch("angry,\\nBad world") macro r_str(pattern, flags...) Regex(pattern, flags...) end function show(io::IO, re::Regex) - imsx = PCRE.CASELESS|PCRE.MULTILINE|PCRE.DOTALL|PCRE.EXTENDED + imsx = bitor(PCRE.CASELESS, PCRE.MULTILINE, PCRE.DOTALL, PCRE.EXTENDED) opts = re.compile_options if (opts & bitnot(imsx)) == DEFAULT_COMPILER_OPTS print(io, 'r') @@ -206,7 +207,7 @@ function match end function match(re::Regex, str::Union{SubString{String}, String}, idx::Integer, add_opts::UInt32=UInt32(0)) compile(re) - opts = re.match_options | add_opts + opts = bitor(re.match_options, add_opts) if !PCRE.exec(re.regex, str, idx-1, opts, re.match_data) return nothing end @@ -254,7 +255,7 @@ function matchall(re::Regex, str::String, overlap::Bool=false) matches = SubString{String}[] offset = UInt32(0) opts = re.match_options - opts_nonempty = opts | PCRE.ANCHORED | PCRE.NOTEMPTY_ATSTART + opts_nonempty = bitor(opts, PCRE.ANCHORED, PCRE.NOTEMPTY_ATSTART) prevempty = false ovec = re.ovec while true @@ -411,7 +412,7 @@ function next(itr::RegexMatchIterator, prev_match) offset = prev_match.offset + endof(prev_match.match) end - opts_nonempty = UInt32(PCRE.ANCHORED | PCRE.NOTEMPTY_ATSTART) + opts_nonempty = UInt32(bitor(PCRE.ANCHORED, PCRE.NOTEMPTY_ATSTART)) while true mat = match(itr.regex, itr.string, offset, prevempty ? opts_nonempty : UInt32(0)) diff --git a/base/serialize.jl b/base/serialize.jl index 53f01f2a51a73..39f85df757a0d 100644 --- a/base/serialize.jl +++ b/base/serialize.jl @@ -227,14 +227,14 @@ function serialize_array_data(s::IO, a) count = 1 for i = 2:length(a) if a[i] != last || count == 127 - write(s, UInt8((UInt8(last) << 7) | count)) + write(s, UInt8(bitor(UInt8(last) << 7, count)) last = a[i] count = 1 else count += 1 end end - write(s, UInt8((UInt8(last) << 7) | count)) + write(s, UInt8(bitor(UInt8(last) << 7, count)) else write(s, a) end @@ -673,7 +673,7 @@ function writeheader(s::AbstractSerializer) machine = (sizeof(Int) == 4 ? 0 : sizeof(Int) == 8 ? 1 : error("unsupported word size in serializer")) - write(io, UInt8(endianness) | (UInt8(machine) << 2)) + write(io, bitor(UInt8(endianness), UInt8(machine) << 2)) write(io, b"\x00\x00\x00") # 3 reserved bytes nothing end diff --git a/base/socket.jl b/base/socket.jl index 15330cd493556..bd8a8bd4a2372 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -9,10 +9,8 @@ Base.convert(dt::Type{<:Integer}, ip::IPAddr) = dt(ip.host) struct IPv4 <: IPAddr host::UInt32 IPv4(host::UInt32) = new(host) - IPv4(a::UInt8,b::UInt8,c::UInt8,d::UInt8) = new(UInt32(a)<<24| - UInt32(b)<<16| - UInt32(c)<<8| - d) + IPv4(a::UInt8,b::UInt8,c::UInt8,d::UInt8) = + new(bitor(UInt32(a) << 24, UInt32(b) << 16, UInt32(c) << 8, d)) function IPv4(a::Integer,b::Integer,c::Integer,d::Integer) if !(0<=a<=255 && 0<=b<=255 && 0<=c<=255 && 0<=d<=255) throw(ArgumentError("IPv4 field out of range (must be 0-255)")) @@ -53,15 +51,14 @@ print(io::IO,ip::IPv4) = print(io,dec((ip.host&(0xFF000000))>>24),".", struct IPv6 <: IPAddr host::UInt128 IPv6(host::UInt128) = new(host) - IPv6(a::UInt16,b::UInt16,c::UInt16,d::UInt16, - e::UInt16,f::UInt16,g::UInt16,h::UInt16) = new(UInt128(a)<<(7*16)| - UInt128(b)<<(6*16)| - UInt128(c)<<(5*16)| - UInt128(d)<<(4*16)| - UInt128(e)<<(3*16)| - UInt128(f)<<(2*16)| - UInt128(g)<<(1*16)| - h) + IPv6(a::UInt16,b::UInt16,c::UInt16,d::UInt16,e::UInt16,f::UInt16,g::UInt16,h::UInt16) = + new(bitor(UInt128(a) << (7*16), + UInt128(b) << (6*16), + UInt128(c) << (5*16), + UInt128(d) << (4*16), + UInt128(e) << (3*16), + UInt128(f) << (2*16), + UInt128(g) << (1*16), h)) function IPv6(a::Integer,b::Integer,c::Integer,d::Integer, e::Integer,f::Integer,g::Integer,h::Integer) if !(0<=a<=0xFFFF && 0<=b<=0xFFFF && 0<=c<=0xFFFF && 0<=d<=0xFFFF && @@ -180,12 +177,12 @@ function parse(::Type{IPv4}, str::AbstractString) if r < 0 || r > 255 throw(ArgumentError("IPv4 field out of range (must be 0-255)")) end - ret |= UInt32(r) << ((4-i)*8) + ret = bitor(ret, UInt32(r) << ((4-i)*8)) else if r > ((UInt64(1)<<((5-length(fields))*8))-1) throw(ArgumentError("IPv4 field too large")) end - ret |= r + ret = bitor(ret, r) end i+=1 end @@ -207,7 +204,7 @@ function parseipv6fields(fields,num_fields) cf -= 1 continue end - ret |= UInt128(parse(Int,f,16))<<(cf*16) + ret = bitor(ret, UInt128(parse(Int,f,16))<<(cf*16)) cf -= 1 end ret @@ -221,8 +218,8 @@ function parse(::Type{IPv6}, str::AbstractString) elseif length(fields) == 8 return IPv6(parseipv6fields(fields)) elseif in('.',fields[end]) - return IPv6((parseipv6fields(fields[1:(end-1)],6)) - | parse(IPv4, fields[end]).host ) + return IPv6(bitor(parseipv6fields(fields[1:(end-1)], 6), + parse(IPv4, fields[end]).host )) else return IPv6(parseipv6fields(fields)) end @@ -439,10 +436,10 @@ function bind(sock::Union{TCPServer, UDPSocket}, host::IPAddr, port::Integer; ip end flags = 0 if isa(host,IPv6) && ipv6only - flags |= isa(sock, UDPSocket) ? UV_UDP_IPV6ONLY : UV_TCP_IPV6ONLY + flags = bitor(flags, isa(sock, UDPSocket) ? UV_UDP_IPV6ONLY : UV_TCP_IPV6ONLY) end if isa(sock, UDPSocket) && reuseaddr - flags |= UV_UDP_REUSEADDR + flags = bitor(flags, UV_UDP_REUSEADDR) end err = _bind(sock, host, UInt16(port), UInt32(flags)) if err < 0 diff --git a/base/special/log.jl b/base/special/log.jl index e62ddf541705e..3627269a9da36 100644 --- a/base/special/log.jl +++ b/base/special/log.jl @@ -269,7 +269,7 @@ function log(x::Float64) m = Int(xu >> 52) & 0x07ff - 54 end m -= 1023 - y = reinterpret(Float64,(xu & 0x000f_ffff_ffff_ffff) | 0x3ff0_0000_0000_0000) + y = reinterpret(Float64, bitor(xu & 0x000f_ffff_ffff_ffff, 0x3ff0_0000_0000_0000)) mf = Float64(m) F = (y + 3.5184372088832e13) - 3.5184372088832e13 # 0x1p-7*round(0x1p7*y) @@ -305,7 +305,7 @@ function log(x::Float32) m = Int(xu >> 23) & 0x00ff - 25 end m -= 127 - y = reinterpret(Float32,(xu & 0x007f_ffff) | 0x3f80_0000) + y = reinterpret(Float32, bitor(xu & 0x007f_ffff, 0x3f80_0000)) mf = Float32(m) F = (y + 65536.0f0) - 65536.0f0 # 0x1p-7*round(0x1p7*y) @@ -340,7 +340,7 @@ function log1p(x::Float64) s = reinterpret(Float64,0x7fe0_0000_0000_0000 - (zu & 0xfff0_0000_0000_0000)) # 2^-m m = Int(zu >> 52) & 0x07ff - 1023 # z cannot be subnormal c = m > 0 ? 1.0-(z-x) : x-(z-1.0) # 1+x = z+c exactly - y = reinterpret(Float64,(zu & 0x000f_ffff_ffff_ffff) | 0x3ff0_0000_0000_0000) + y = reinterpret(Float64, bitor(zu & 0x000f_ffff_ffff_ffff, 0x3ff0_0000_0000_0000)) mf = Float64(m) F = (y + 3.5184372088832e13) - 3.5184372088832e13 # 0x1p-7*round(0x1p7*y) @@ -373,7 +373,7 @@ function log1p(x::Float32) s = reinterpret(Float32,0x7f000000 - (zu & 0xff80_0000)) # 2^-m m = Int(zu >> 23) & 0x00ff - 127 # z cannot be subnormal c = m > 0 ? 1f0-(z-x) : x-(z-1f0) # 1+x = z+c - y = reinterpret(Float32,(zu & 0x007f_ffff) | 0x3f80_0000) + y = reinterpret(Float32, bitor(zu & 0x007f_ffff, 0x3f80_0000)) mf = Float32(m) F = (y + 65536.0f0) - 65536.0f0 # 0x1p-7*round(0x1p7*y) diff --git a/base/special/rem_pio2.jl b/base/special/rem_pio2.jl index c2cdaab22f37a..1d7b300c0f94b 100644 --- a/base/special/rem_pio2.jl +++ b/base/special/rem_pio2.jl @@ -128,7 +128,7 @@ function fromfraction(f::Int128) n1 = 128-leading_zeros(x) # ndigits0z(x,2) m1 = ((x >> (n1-26)) % UInt64) << 27 d1 = ((n1-128+1021) % UInt64) << 52 - z1 = reinterpret(Float64, s | (d1 + m1)) + z1 = reinterpret(Float64, bitor(s, d1 + m1)) # 2. compute remaining term x2 = (x - (UInt128(m1) << (n1-53))) @@ -138,7 +138,7 @@ function fromfraction(f::Int128) n2 = 128-leading_zeros(x2) m2 = (x2 >> (n2-53)) % UInt64 d2 = ((n2-128+1021) % UInt64) << 52 - z2 = reinterpret(Float64, s | (d2 + m2)) + z2 = reinterpret(Float64, bitor(s, d2 + m2)) return (z1,z2) end @@ -152,7 +152,7 @@ function paynehanek(x::Float64) # Computations are integer based, so reinterpret x as UInt64 u = reinterpret(UInt64, x) # Strip x of exponent bits and replace with ^1 - X = (u & significand_mask(Float64)) | (one(UInt64) << significand_bits(Float64)) + X = bitor(u & significand_mask(Float64), one(UInt64) << significand_bits(Float64)) # Get k from formula above # k = exponent(x)-52 k = Int((u & exponent_mask(Float64)) >> significand_bits(Float64)) - exponent_bias(Float64) - significand_bits(Float64) @@ -186,9 +186,9 @@ function paynehanek(x::Float64) @inbounds a3 = INV_2PI[idx+3] else # use shifts to extract the relevant 64 bit window - @inbounds a1 = (idx < 0 ? zero(UInt64) : INV_2PI[idx+1] << shift) | (INV_2PI[idx+2] >> (64 - shift)) - @inbounds a2 = (INV_2PI[idx+2] << shift) | (INV_2PI[idx+3] >> (64 - shift)) - @inbounds a3 = (INV_2PI[idx+3] << shift) | (INV_2PI[idx+4] >> (64 - shift)) + @inbounds a1 = bitor(idx < 0 ? zero(UInt64) : INV_2PI[idx+1] << shift, INV_2PI[idx+2] >> (64 - shift)) + @inbounds a2 = bitor(INV_2PI[idx+2] << shift, INV_2PI[idx+3] >> (64 - shift)) + @inbounds a3 = bitor(INV_2PI[idx+3] << shift, INV_2PI[idx+4] >> (64 - shift)) end # 3. Perform the multiplication: diff --git a/base/strings/io.jl b/base/strings/io.jl index c43f191585be9..247fb4fc0d08e 100644 --- a/base/strings/io.jl +++ b/base/strings/io.jl @@ -496,7 +496,7 @@ function convert(::Type{String}, chars::AbstractVector{Char}) if '\ud7ff' < c && c + 1024 < '\ue000' d, state = next(chars, state) if '\ud7ff' < d - 1024 && d < '\ue000' - c = Char(0x10000 + ((UInt32(c) & 0x03ff) << 10) | (UInt32(d) & 0x03ff)) + c = Char(bitor(0x10000 + ((UInt32(c) & 0x03ff) << 10), (UInt32(d) & 0x03ff))) else write(io, c) c = d diff --git a/base/strings/search.jl b/base/strings/search.jl index 23f813ea28b26..5f3dd62579060 100644 --- a/base/strings/search.jl +++ b/base/strings/search.jl @@ -107,7 +107,7 @@ function _searchindex(s::Union{String,ByteArray}, t::Union{String,ByteArray}, i) skip = n - 1 tlast = _nthbyte(t,n) for j in 1:n - bloom_mask |= _search_bloom_mask(_nthbyte(t,j)) + bloom_mask = bitor(bloom_mask, _search_bloom_mask(_nthbyte(t,j))) if _nthbyte(t,j) == tlast && j < n skip = n - j - 1 end @@ -274,7 +274,7 @@ function _rsearchindex(s::Union{String,ByteArray}, t::Union{String,ByteArray}, k skip = n - 1 tfirst = _nthbyte(t,1) for j in n:-1:1 - bloom_mask |= _search_bloom_mask(_nthbyte(t,j)) + bloom_mask = bitor(bloom_mask, _search_bloom_mask(_nthbyte(t,j))) if _nthbyte(t,j) == tfirst && j > 1 skip = j - 2 end diff --git a/base/strings/string.jl b/base/strings/string.jl index 71738b3a13b2a..9fcee8391e4cc 100644 --- a/base/strings/string.jl +++ b/base/strings/string.jl @@ -263,10 +263,10 @@ end function first_utf8_byte(ch::Char) c = UInt32(ch) - b = c < 0x80 ? c%UInt8 : - c < 0x800 ? ((c>>6) | 0xc0)%UInt8 : - c < 0x10000 ? ((c>>12) | 0xe0)%UInt8 : - ((c>>18) | 0xf0)%UInt8 + b = c < 0x80 ? c % UInt8 : + c < 0x800 ? bitor(c >> 6, 0xc0) % UInt8 : + c < 0x10000 ? bitor(c >> 12, 0xe0) % UInt8 : + bitor(c >> 18), 0xf0) % UInt8 return b end @@ -426,17 +426,17 @@ function string(a::Union{String,Char}...) if c < 0x80 unsafe_store!(p, c%UInt8, offs); offs += 1 elseif c < 0x800 - unsafe_store!(p, (( c >> 6 ) | 0xC0)%UInt8, offs); offs += 1 - unsafe_store!(p, (( c & 0x3F ) | 0x80)%UInt8, offs); offs += 1 + unsafe_store!(p, bitor(c >> 6 , 0xC0) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor(c & 0x3F, 0x80) % UInt8, offs); offs += 1 elseif c < 0x10000 - unsafe_store!(p, (( c >> 12 ) | 0xE0)%UInt8, offs); offs += 1 - unsafe_store!(p, (((c >> 6) & 0x3F ) | 0x80)%UInt8, offs); offs += 1 - unsafe_store!(p, (( c & 0x3F ) | 0x80)%UInt8, offs); offs += 1 + unsafe_store!(p, bitor(c >> 12 , 0xE0) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor((c >> 6) & 0x3F, 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor(c & 0x3F , 0x80) % UInt8, offs); offs += 1 elseif c < 0x110000 - unsafe_store!(p, (( c >> 18 ) | 0xF0)%UInt8, offs); offs += 1 - unsafe_store!(p, (((c >> 12) & 0x3F ) | 0x80)%UInt8, offs); offs += 1 - unsafe_store!(p, (((c >> 6) & 0x3F ) | 0x80)%UInt8, offs); offs += 1 - unsafe_store!(p, (( c & 0x3F ) | 0x80)%UInt8, offs); offs += 1 + unsafe_store!(p, bitor(c >> 18 , 0xF0) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor((c >> 12) & 0x3F, 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor((c >> 6) & 0x3F, 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor(c & 0x3F , 0x80) % UInt8, offs); offs += 1 else # '\ufffd' unsafe_store!(p, 0xef, offs); offs += 1 @@ -519,7 +519,7 @@ function repeat(c::Char, r::Integer) elseif ch < 0x800 out = _string_n(2r) p16 = reinterpret(Ptr{UInt16}, pointer(out)) - u16 = ((ch >> 0x6) | (ch & 0x3f) << 0x8) % UInt16 | 0x80c0 + u16 = bitor(bitor(ch >> 0x6, (ch & 0x3f) << 0x8) % UInt16, 0x80c0) @inbounds for i = 1:r unsafe_store!(p16, u16, i) end @@ -527,9 +527,9 @@ function repeat(c::Char, r::Integer) (0xd800 ≥ ch ≤ 0xdfff) || throw(ArgumentError("invalid character 0x$(hex(ch))")) out = _string_n(3r) p = pointer(out) - b1 = (ch >> 0xc) % UInt8 | 0xe0 - b2 = ((ch >> 0x6) & 0x3f) % UInt8 | 0x80 - b3 = (ch & 0x3f) % UInt8 | 0x80 + b1 = bitor((ch >> 0xc) % UInt8, 0xe0) + b2 = bitor(((ch >> 0x6) & 0x3f) % UInt8, 0x80) + b3 = bitor((ch & 0x3f) % UInt8, 0x80) @inbounds for i = 1:r unsafe_store!(p, b1) unsafe_store!(p, b2, 2) @@ -539,8 +539,11 @@ function repeat(c::Char, r::Integer) elseif ch < 0x110000 out = _string_n(4r) p32 = reinterpret(Ptr{UInt32}, pointer(out)) - u32 = ((ch >> 0x12) | ((ch >> 0x4) & 0x03f00) | - ((ch << 0xa) & 0x3f0000) | ((ch & 0x3f) << 0x18)) % UInt32 | 0x808080f0 + u32 = bitor(ch >> 0x12, + (ch >> 0x4) & 0x03f00, + (ch << 0xa) & 0x3f0000, + (ch & 0x3f) << 0x18 ) + u32 = bitor(u32 % UInt32, 0x808080f0) @inbounds for i = 1:r unsafe_store!(p32, u32) p32 += 4 diff --git a/base/strings/utf8proc.jl b/base/strings/utf8proc.jl index cf30ec5b3aa6f..fb9f8c6911271 100644 --- a/base/strings/utf8proc.jl +++ b/base/strings/utf8proc.jl @@ -49,7 +49,7 @@ true """ isvalid(T,value) -isvalid(::Type{Char}, ch::Unsigned) = !((ch - 0xd800 < 0x800) | (ch > 0x10ffff)) +isvalid(::Type{Char}, ch::Unsigned) = !bitor((ch - 0xd800 < 0x800), (ch > 0x10ffff)) isvalid(::Type{Char}, ch::Integer) = isvalid(Char, Unsigned(ch)) isvalid(::Type{Char}, ch::Char) = isvalid(Char, UInt32(ch)) @@ -129,7 +129,7 @@ const UTF8PROC_IGNORE = (1<<5) const UTF8PROC_REJECTNA = (1<<6) const UTF8PROC_NLF2LS = (1<<7) const UTF8PROC_NLF2PS = (1<<8) -const UTF8PROC_NLF2LF = (UTF8PROC_NLF2LS | UTF8PROC_NLF2PS) +const UTF8PROC_NLF2LF = bitor(UTF8PROC_NLF2LS, UTF8PROC_NLF2PS) const UTF8PROC_STRIPCC = (1<<9) const UTF8PROC_CASEFOLD = (1<<10) const UTF8PROC_CHARBOUND = (1<<11) @@ -157,25 +157,25 @@ utf8proc_map(s::AbstractString, flags::Integer) = utf8proc_map(String(s), flags) function normalize_string(s::AbstractString; stable::Bool=false, compat::Bool=false, compose::Bool=true, decompose::Bool=false, stripignore::Bool=false, rejectna::Bool=false, newline2ls::Bool=false, newline2ps::Bool=false, newline2lf::Bool=false, stripcc::Bool=false, casefold::Bool=false, lump::Bool=false, stripmark::Bool=false) flags = 0 - stable && (flags = flags | UTF8PROC_STABLE) - compat && (flags = flags | UTF8PROC_COMPAT) + stable && (flags = bitor(flags, UTF8PROC_STABLE)) + compat && (flags = bitor(flags, UTF8PROC_COMPAT)) if decompose - flags = flags | UTF8PROC_DECOMPOSE + flags = bitor(flags, UTF8PROC_DECOMPOSE) elseif compose - flags = flags | UTF8PROC_COMPOSE + flags = bitor(flags, UTF8PROC_COMPOSE) elseif compat || stripmark throw(ArgumentError("compat=true or stripmark=true require compose=true or decompose=true")) end - stripignore && (flags = flags | UTF8PROC_IGNORE) - rejectna && (flags = flags | UTF8PROC_REJECTNA) + stripignore && (flags = bitor(flags, UTF8PROC_IGNORE)) + rejectna && (flags = bitor(flags, UTF8PROC_REJECTNA)) newline2ls + newline2ps + newline2lf > 1 && throw(ArgumentError("only one newline conversion may be specified")) - newline2ls && (flags = flags | UTF8PROC_NLF2LS) - newline2ps && (flags = flags | UTF8PROC_NLF2PS) - newline2lf && (flags = flags | UTF8PROC_NLF2LF) - stripcc && (flags = flags | UTF8PROC_STRIPCC) - casefold && (flags = flags | UTF8PROC_CASEFOLD) - lump && (flags = flags | UTF8PROC_LUMP) - stripmark && (flags = flags | UTF8PROC_STRIPMARK) + newline2ls && (flags = bitor(flags, UTF8PROC_NLF2LS)) + newline2ps && (flags = bitor(flags, UTF8PROC_NLF2PS)) + newline2lf && (flags = bitor(flags, UTF8PROC_NLF2LF)) + stripcc && (flags = bitor(flags, UTF8PROC_STRIPCC)) + casefold && (flags = bitor(flags, UTF8PROC_CASEFOLD)) + lump && (flags = bitor(flags, UTF8PROC_LUMP)) + stripmark && (flags = bitor(flags, UTF8PROC_STRIPMARK)) utf8proc_map(s, flags) end @@ -227,12 +227,10 @@ julia> normalize_string("JúLiA", stripmark=true) ``` """ function normalize_string(s::AbstractString, nf::Symbol) - utf8proc_map(s, nf == :NFC ? (UTF8PROC_STABLE | UTF8PROC_COMPOSE) : - nf == :NFD ? (UTF8PROC_STABLE | UTF8PROC_DECOMPOSE) : - nf == :NFKC ? (UTF8PROC_STABLE | UTF8PROC_COMPOSE - | UTF8PROC_COMPAT) : - nf == :NFKD ? (UTF8PROC_STABLE | UTF8PROC_DECOMPOSE - | UTF8PROC_COMPAT) : + utf8proc_map(s, nf == :NFC ? bitor(UTF8PROC_STABLE, UTF8PROC_COMPOSE) : + nf == :NFD ? bitor(UTF8PROC_STABLE, UTF8PROC_DECOMPOSE) : + nf == :NFKC ? bitor(UTF8PROC_STABLE, UTF8PROC_COMPOSE, UTF8PROC_COMPAT) : + nf == :NFKD ? bitor(UTF8PROC_STABLE, UTF8PROC_DECOMPOSE, UTF8PROC_COMPAT) : throw(ArgumentError(":$nf is not one of :NFC, :NFD, :NFKC, :NFKD"))) end diff --git a/base/subarray.jl b/base/subarray.jl index 608a2395d0963..c3d956e39cd47 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -407,7 +407,7 @@ function replace_ref_end_!(ex, withex) J = endof(ex.args) for j = 2:J exj, used = replace_ref_end_!(ex.args[j],:($size($S,$n))) - used_S |= used + used_S = bitor(used_S, used) ex.args[j] = exj if isa(exj,Expr) && exj.head == :... # splatted object diff --git a/base/util.jl b/base/util.jl index b0d63bbf6d875..58fabd0884304 100644 --- a/base/util.jl +++ b/base/util.jl @@ -664,10 +664,10 @@ if Sys.iswindows() captionArr = Base.cwstring(caption) pfSave = Ref{Bool}(false) cred = Ref{CREDUI_INFO}(CREDUI_INFO(sizeof(CREDUI_INFO), C_NULL, pointer(messageArr), pointer(captionArr), C_NULL)) - dwflags = CREDUIWIN_GENERIC | CREDUIWIN_ENUMERATE_CURRENT_USER + dwflags = bitor(CREDUIWIN_GENERIC, CREDUIWIN_ENUMERATE_CURRENT_USER) if !prompt_username # Disable setting anything other than default_username - dwflags |= CREDUIWIN_IN_CRED_ONLY + dwflags = bitor(dwflags, CREDUIWIN_IN_CRED_ONLY) end authPackage = Ref{Culong}(0) outbuf_data = Ref{Ptr{Void}}(C_NULL) From 9fb00e15e74447dddeeb0d1f3becb9c4c8d459ab Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Tue, 21 Nov 2017 12:09:46 -0800 Subject: [PATCH 08/17] Replace bitwise calls to | with bitor in stdlib/. --- stdlib/Base64/src/decode.jl | 12 ++++++------ stdlib/Base64/src/encode.jl | 22 +++++++++++----------- stdlib/FileWatching/src/FileWatching.jl | 6 +++--- stdlib/Mmap/src/Mmap.jl | 6 +++--- stdlib/SharedArrays/src/SharedArrays.jl | 6 +++--- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/stdlib/Base64/src/decode.jl b/stdlib/Base64/src/decode.jl index ec1ae553a2682..e536394cbb811 100644 --- a/stdlib/Base64/src/decode.jl +++ b/stdlib/Base64/src/decode.jl @@ -66,9 +66,9 @@ function read_until_end(pipe::Base64DecodePipe, ptr::Ptr{UInt8}, n::UInt) while true if b1 < 0x40 && b2 < 0x40 && b3 < 0x40 && b4 < 0x40 && p + 2 < p_end # fast path to decode - unsafe_store!(p , b1 << 2 | b2 >> 4) - unsafe_store!(p + 1, b2 << 4 | b3 >> 2) - unsafe_store!(p + 2, b3 << 6 | b4 ) + unsafe_store!(p , bitor(b1 << 2, b2 >> 4)) + unsafe_store!(p + 1, bitor(b2 << 4, b3 >> 2)) + unsafe_store!(p + 2, bitor(b3 << 6, b4 )) p += 3 else i, p, ended = decode_slow(b1, b2, b3, b4, buffer, i, pipe.io, p, p_end - p, pipe.rest) @@ -177,9 +177,9 @@ function decode_slow(b1, b2, b3, b4, buffer, i, input, ptr, n, rest) push!(rest, b) end end - k ≥ 1 && output(b1 << 2 | b2 >> 4) - k ≥ 2 && output(b2 << 4 | b3 >> 2) - k ≥ 3 && output(b3 << 6 | b4 ) + k ≥ 1 && output(bitor(b1 << 2, b2 >> 4)) + k ≥ 2 && output(bitor(b2 << 4, b3 >> 2)) + k ≥ 3 && output(bitor(b3 << 6, b4 )) return i, p, k == 0 end diff --git a/stdlib/Base64/src/encode.jl b/stdlib/Base64/src/encode.jl index 37dda446cd525..2d2f78820c664 100644 --- a/stdlib/Base64/src/encode.jl +++ b/stdlib/Base64/src/encode.jl @@ -66,10 +66,10 @@ function Base.unsafe_write(pipe::Base64EncodePipe, ptr::Ptr{UInt8}, n::UInt)::In i = 0 p_end = ptr + n while true - buffer[i+1] = encode(b1 >> 2 ) - buffer[i+2] = encode(b1 << 4 | b2 >> 4) - buffer[i+3] = encode(b2 << 2 | b3 >> 6) - buffer[i+4] = encode( b3 ) + buffer[i+1] = encode(b1 >> 2) + buffer[i+2] = encode(bitor(b1 << 4, b2 >> 4)) + buffer[i+3] = encode(bitor(b2 << 2, b3 >> 6) + buffer[i+4] = encode(b3) i += 4 if p + 2 < p_end b1 = unsafe_load(p, 1) @@ -116,17 +116,17 @@ function Base.close(pipe::Base64EncodePipe) encodepadding()) elseif k == 2 write(pipe.io, - encode( b1 >> 2), - encode(b1 << 4 | b2 >> 4), - encode(b2 << 2 ), + encode(b1 >> 2), + encode(bitor(b1 << 4, b2 >> 4)), + encode(b2 << 2), encodepadding()) else @assert k == 3 write(pipe.io, - encode(b1 >> 2 ), - encode(b1 << 4 | b2 >> 4), - encode(b2 << 2 | b3 >> 6), - encode( b3 )) + encode(b1 >> 2), + encode(bitor(b1 << 4, b2 >> 4)), + encode(bitor(b2 << 2, b3 >> 6)), + encode(b3)) end return nothing end diff --git a/stdlib/FileWatching/src/FileWatching.jl b/stdlib/FileWatching/src/FileWatching.jl index aede724e7c2d2..9720dd67b5494 100644 --- a/stdlib/FileWatching/src/FileWatching.jl +++ b/stdlib/FileWatching/src/FileWatching.jl @@ -288,7 +288,7 @@ function uv_pollcb(handle::Ptr{Void}, status::Int32, events::Int32) if status != 0 notify_error(t.notify, UVError("FDWatcher", status)) else - t.events |= events + t.events = bitor(t.events, events) if t.active[1] || t.active[2] if isempty(t.notify.waitq) # if we keep hearing about events when nobody appears to be listening, @@ -322,7 +322,7 @@ function start_watching(t::_FDWatcher) uv_error("start_watching (File Handle)", ccall(:uv_poll_start, Int32, (Ptr{Void}, Int32, Ptr{Void}), t.handle, - (readable ? UV_READABLE : 0) | (writable ? UV_WRITABLE : 0), + bitor(readable ? UV_READABLE : 0, writable ? UV_WRITABLE : 0), uv_jl_pollcb::Ptr{Void})) t.active = (readable, writable) end @@ -375,7 +375,7 @@ function wait(fdw::_FDWatcher; readable=true, writable=true) while true if isa(events, FDEvent) events = events::FDEvent - events |= FDEvent(fdw.events) + events = bitor(events, FDEvent(fdw.events)) haveevent = false if readable && isreadable(events) fdw.events &= bitnot(UV_READABLE) diff --git a/stdlib/Mmap/src/Mmap.jl b/stdlib/Mmap/src/Mmap.jl index 93c06ced89d1b..5367684ad9c83 100644 --- a/stdlib/Mmap/src/Mmap.jl +++ b/stdlib/Mmap/src/Mmap.jl @@ -46,13 +46,13 @@ gethandle(io::IO) = fd(io) function settings(s::Int, shared::Bool) flags = shared ? MAP_SHARED : MAP_PRIVATE if s == INVALID_HANDLE_VALUE - flags |= MAP_ANONYMOUS - prot = PROT_READ | PROT_WRITE + flags = bitor(flags, MAP_ANONYMOUS) + prot = bitor(PROT_READ, PROT_WRITE) else mode = ccall(:fcntl,Cint,(Cint,Cint),s,F_GETFL) systemerror("fcntl F_GETFL", mode == -1) mode = mode & 3 - prot = mode == 0 ? PROT_READ : mode == 1 ? PROT_WRITE : PROT_READ | PROT_WRITE + prot = mode == 0 ? PROT_READ : mode == 1 ? PROT_WRITE : bitor(PROT_READ, PROT_WRITE) if prot & PROT_READ == 0 throw(ArgumentError("mmap requires read permissions on the file (open with \"r+\" mode to override)")) end diff --git a/stdlib/SharedArrays/src/SharedArrays.jl b/stdlib/SharedArrays/src/SharedArrays.jl index 585a10a8049de..38e51b84cc371 100644 --- a/stdlib/SharedArrays/src/SharedArrays.jl +++ b/stdlib/SharedArrays/src/SharedArrays.jl @@ -113,12 +113,12 @@ function SharedArray{T,N}(dims::Dims{N}; init=false, pids=Int[]) where {T,N} shm_seg_name = @sprintf("/jl%06u%s", getpid() % 10^6, randstring(20)) if onlocalhost shmmem_create_pid = myid() - s = shm_mmap_array(T, dims, shm_seg_name, JL_O_CREAT | JL_O_RDWR) + s = shm_mmap_array(T, dims, shm_seg_name, bitor(JL_O_CREAT, JL_O_RDWR)) else # The shared array is created on a remote machine shmmem_create_pid = pids[1] remotecall_fetch(pids[1]) do - shm_mmap_array(T, dims, shm_seg_name, JL_O_CREAT | JL_O_RDWR) + shm_mmap_array(T, dims, shm_seg_name, bitor(JL_O_CREAT, JL_O_RDWR)) nothing end end @@ -659,7 +659,7 @@ shm_unlink(shm_seg_name) = 0 else # !windows function _shm_mmap_array(T, dims, shm_seg_name, mode) - fd_mem = shm_open(shm_seg_name, mode, S_IRUSR | S_IWUSR) + fd_mem = shm_open(shm_seg_name, mode, bitor(S_IRUSR, S_IWUSR)) systemerror("shm_open() failed for " * shm_seg_name, fd_mem < 0) s = fdio(fd_mem, true) From d8f3d611719d7bc921c9e02b1d63d9304b425119 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Tue, 21 Nov 2017 13:33:34 -0800 Subject: [PATCH 09/17] Deprecate bitwise calls to & to bitand. --- base/bool.jl | 1 + base/deprecated.jl | 15 ++++++++++++++- base/gmp.jl | 4 ++-- base/int.jl | 10 +++++----- base/operators.jl | 4 ++-- base/promotion.jl | 2 +- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/base/bool.jl b/base/bool.jl index eda9d89743002..d5273c367ae6b 100644 --- a/base/bool.jl +++ b/base/bool.jl @@ -39,6 +39,7 @@ function !(x::Bool) end bitnot(x::Bool) = !x +bitand(x::Bool, y::Bool) = and_int(x, y) bitor(x::Bool, y::Bool) = or_int(x, y) (&)(x::Bool, y::Bool) = and_int(x, y) (|)(x::Bool, y::Bool) = or_int(x, y) diff --git a/base/deprecated.jl b/base/deprecated.jl index 909f8d6c7bbff..e4629903ca27c 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -2098,9 +2098,22 @@ end @deprecate (|)(a::Integer, b::Integer) bitor(a, b) @deprecate (|)(x::T, y::T) where {T<:Integer} bitor(x, y) @deprecate (|)(x::T, y::T) where {T<:BitInteger} bitor(x, y) - @deprecate (|)(a, b, c, xs...) bitor(a, b, c, xs...) +@deprecate (&)(x::BigInt, y::BigInt) bitand(x, y) +@deprecate (&)(a::BigInt, b::BigInt, c::BigInt) bitand(a, b, c) +@deprecate (&)(a::BigInt, b::BigInt, c::BigInt, d::BigInt) bitand(a, b, c, d) +@deprecate (&)(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) bitand(a, b, c, d, e) + +@deprecate (&)(x::Integer) bitand(x) +@deprecate (&)(a::Integer, b::Integer) bitand(a, b) +@deprecate (&)(x::T, y::T) where {T<:Integer} bitand(x, y) +@deprecate (&)(x::T, y::T) where {T<:BitInteger} bitand(x, y) +@deprecate (&)(a, b, c, xs...) bitand(a, b, c, xs...) + + + + # #24258 # Physical units define an equivalence class: there is no such thing as a step of "1" (is # it one day or one second or one nanosecond?). So require the user to specify the step diff --git a/base/gmp.jl b/base/gmp.jl index 877f01dfda18b..9b0981013ded5 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -405,7 +405,7 @@ big(::Type{<:Rational}) = Rational{BigInt} for (fJ, fC) in ((:+, :add), (:-,:sub), (:*, :mul), (:fld, :fdiv_q), (:div, :tdiv_q), (:mod, :fdiv_r), (:rem, :tdiv_r), (:gcd, :gcd), (:lcm, :lcm), - (:&, :and), (:bitor, :ior), (:xor, :xor)) + (:bitand, :and), (:bitor, :ior), (:xor, :xor)) @eval begin ($fJ)(x::BigInt, y::BigInt) = MPZ.$fC(x, y) end @@ -433,7 +433,7 @@ function invmod(x::BigInt, y::BigInt) end # More efficient commutative operations -for (fJ, fC) in ((:+, :add), (:*, :mul), (:&, :and), (:bitor, :ior), (:xor, :xor)) +for (fJ, fC) in ((:+, :add), (:*, :mul), (:bitand, :and), (:bitor, :ior), (:xor, :xor)) fC! = Symbol(fC, :!) @eval begin ($fJ)(a::BigInt, b::BigInt, c::BigInt) = MPZ.$fC!(MPZ.$fC(a, b), c) diff --git a/base/int.jl b/base/int.jl index 6863b5ccfb93b..efea6b77b2fae 100644 --- a/base/int.jl +++ b/base/int.jl @@ -261,20 +261,20 @@ false bitnot(x::BitInteger) = not_int(x) """ - &(x, y) + bitand(x, y) Bitwise and. # Examples ```jldoctest -julia> 4 & 10 +julia> bitand(4, 10) 0 -julia> 4 & 12 +julia> bitand(4, 12) 4 ``` """ -(&)(x::T, y::T) where {T<:BitInteger} = and_int(x, y) +bitand(x::T, y::T) where {T<:BitInteger} = and_int(x, y) """ bitor(x, y) @@ -770,7 +770,7 @@ else end # issue #15489: since integer ops are unchecked, they shouldn't check promotion -for op in (:+, :-, :*, :&, :bitor, :xor) +for op in (:+, :-, :*, bitand, :bitor, :xor) @eval function $op(a::Integer, b::Integer) T = promote_typeof(a, b) return $op(a % T, b % T) diff --git a/base/operators.jl b/base/operators.jl index 9d00ae811ebe9..1044487bf7b0b 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -443,7 +443,7 @@ identity(x) = x +(x::Number) = x *(x::Number) = x -(&)(x::Integer) = x +bitand(x::Integer) = x bitor(x::Integer) = x xor(x::Integer) = x @@ -461,7 +461,7 @@ function afoldl(op,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,qs...) y end -for op in (:+, :*, :&, :bitor, :xor, :min, :max, :kron) +for op in (:+, :*, :bitand, :bitor, :xor, :min, :max, :kron) @eval begin # note: these definitions must not cause a dispatch loop when +(a,b) is # not defined, and must only try to call 2-argument definitions, so diff --git a/base/promotion.jl b/base/promotion.jl index 9a71a2136af1f..4a7f39f88dbc4 100644 --- a/base/promotion.jl +++ b/base/promotion.jl @@ -379,7 +379,7 @@ fma(x::T, y::T, z::T) where {T<:Number} = no_op_err("fma", T) fma(x::Integer, y::Integer, z::Integer) = x*y+z muladd(x::T, y::T, z::T) where {T<:Number} = x*y+z -(&)(x::T, y::T) where {T<:Integer} = no_op_err("&", T) +bitand(x::T, y::T) where {T<:Integer} = no_op_err("bitand", T) bitor(x::T, y::T) where {T<:Integer} = no_op_err("bitor", T) xor(x::T, y::T) where {T<:Integer} = no_op_err("xor", T) From a4118d4e60ca576d6a63f2ad7baed8c7bb12f56f Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Tue, 21 Nov 2017 13:20:42 -0800 Subject: [PATCH 10/17] Replace bitwise calls to & with bitand in test/. --- test/bigint.jl | 14 ++++----- test/file.jl | 44 ++++++++++++++-------------- test/int.jl | 2 +- test/nullable.jl | 2 +- test/numbers.jl | 4 +-- test/perf/kernel/ziggurat.jl | 6 ++-- test/perf/shootout/meteor_contest.jl | 12 ++++---- test/reduce.jl | 8 ++--- test/serialize.jl | 6 ++-- test/show.jl | 6 ++-- test/sparse/sparse.jl | 8 ++--- 11 files changed, 56 insertions(+), 56 deletions(-) diff --git a/test/bigint.jl b/test/bigint.jl index 704919dd9dc20..f28ab75876de6 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -182,7 +182,7 @@ end end @testset "boolean ops" begin @test bitnot(BigInt(123)) == -124 - @test BigInt(123) & BigInt(234) == 106 + @test bitand(BigInt(123), BigInt(234)) == 106 @test bitor(BigInt(123), BigInt(234)) == 251 @test BigInt(123) ⊻ BigInt(234) == 145 @@ -229,11 +229,11 @@ end @test xor(a, b, c, d, f) == parse(BigInt,"-2413804710837418037418307081437316711364709261074607933698") @test xor(a, b, c, d, f, g) == parse(BigInt,"2413804710837418037418307081437316711364709261074607933697") - @test (&)(a, b) == parse(BigInt,"124") - @test (&)(a, b, c) == parse(BigInt,"72") - @test (&)(a, b, c, d) == parse(BigInt,"8") - @test (&)(a, b, c, d, f) == parse(BigInt,"8") - @test (&)(a, b, c, d, f, g) == parse(BigInt,"8") + @test bitand(a, b) == parse(BigInt,"124") + @test bitand(a, b, c) == parse(BigInt,"72") + @test bitand(a, b, c, d) == parse(BigInt,"8") + @test bitand(a, b, c, d, f) == parse(BigInt,"8") + @test bitand(a, b, c, d, f, g) == parse(BigInt,"8") @test bitor(a, b) == parse(BigInt,"327423") @test bitor(a, b, c) == parse(BigInt,"3426495623485904783802111") @@ -263,7 +263,7 @@ function bigfib(n) r = [BigInt(1), BigInt(1), BigInt(0)] s = [BigInt(1), BigInt(0), BigInt(1)] while true - (n & 1) == 1 && (s = mul(s,r)) + bitand(n, 1) == 1 && (s = mul(s,r)) (n >>= 1) == 0 && return s[1] r = mul(r,r) end diff --git a/test/file.jl b/test/file.jl index 872d253d56573..9207cb4538d90 100644 --- a/test/file.jl +++ b/test/file.jl @@ -60,23 +60,23 @@ end @test isfile(file) @test !islink(file) -@test filemode(file) & 0o444 > 0 # readable -@test filemode(file) & 0o222 > 0 # writable -chmod(file, filemode(file) & 0o7555) -@test filemode(file) & 0o222 == 0 +@test bitand(filemode(file), 0o444) > 0 # readable +@test bitand(filemode(file), 0o222) > 0 # writable +chmod(file, bitand(filemode(file), 0o7555)) +@test bitand(filemode(file), 0o222) == 0 chmod(file, bitor(filemode(file), 0o222)) -@test filemode(file) & 0o111 == 0 +@test bitand(filemode(file), 0o111) == 0 @test filesize(file) == 0 if Sys.iswindows() permissions = 0o444 - @test filemode(dir) & 0o777 != permissions - @test filemode(subdir) & 0o777 != permissions - @test filemode(file) & 0o777 != permissions + @test bitand(filemode(dir), 0o777) != permissions + @test bitand(filemode(subdir), 0o777) != permissions + @test bitand(filemode(file), 0o777) != permissions chmod(dir, permissions, recursive=true) - @test filemode(dir) & 0o777 == permissions - @test filemode(subdir) & 0o777 == permissions - @test filemode(file) & 0o777 == permissions + @test bitand(filemode(dir), 0o777) == permissions + @test bitand(filemode(subdir), 0o777) == permissions + @test bitand(filemode(file), 0o777) == permissions chmod(dir, 0o666, recursive=true) # Reset permissions in case someone wants to use these later else mktempdir() do tmpdir @@ -86,18 +86,18 @@ else linkfile=joinpath(dir, "tempfile.txt") symlink(tmpfile, linkfile) permissions=0o776 - @test filemode(dir) & 0o777 != permissions - @test filemode(subdir) & 0o777 != permissions - @test filemode(file) & 0o777 != permissions - @test filemode(linkfile) & 0o777 != permissions - @test filemode(tmpfile) & 0o777 != permissions + @test bitand(filemode(dir), 0o777) != permissions + @test bitand(filemode(subdir), 0o777) != permissions + @test bitand(filemode(file), 0o777) != permissions + @test bitand(filemode(linkfile), 0o777) != permissions + @test bitand(filemode(tmpfile), 0o777) != permissions chmod(dir, permissions, recursive=true) - @test filemode(dir) & 0o777 == permissions - @test filemode(subdir) & 0o777 == permissions - @test filemode(file) & 0o777 == permissions - @test lstat(link).mode & 0o777 != permissions # Symbolic links are not modified. - @test filemode(linkfile) & 0o777 != permissions # Symbolic links are not followed. - @test filemode(tmpfile) & 0o777 != permissions + @test bitand(filemode(dir), 0o777) == permissions + @test bitand(filemode(subdir), 0o777) == permissions + @test bitand(filemode(file), 0o777) == permissions + @test bitand(lstat(link).mode, 0o777) != permissions # Symbolic links are not modified. + @test bitand(filemode(linkfile), 0o777) != permissions # Symbolic links are not followed. + @test bitand(filemode(tmpfile), 0o777) != permissions rm(linkfile) end end diff --git a/test/int.jl b/test/int.jl index e25e725e9aee6..710d84218c246 100644 --- a/test/int.jl +++ b/test/int.jl @@ -227,7 +227,7 @@ end @test 0x00007ffea27edaa0 + (-40) === (-40) + 0x00007ffea27edaa0 === 0x00007ffea27eda78 @test UInt64(1) * Int64(-1) === typemax(UInt64) @test UInt(1) - (-1) == 2 -@test UInt64(15) & -4 === UInt64(12) +@test bitand(UInt64(15), -4) === UInt64(12) @test bitor(UInt64(15), -4) === typemax(UInt64) @test UInt64(15) ⊻ -4 === 0xfffffffffffffff3 diff --git a/test/nullable.jl b/test/nullable.jl index fcc180ccc907a..43c9432ddfeb4 100644 --- a/test/nullable.jl +++ b/test/nullable.jl @@ -511,7 +511,7 @@ end for op in (+, *, -) for b1 in (false, true) for b2 in (false, true) - @test Nullable{Int}(op(1, 2), b1 & b2) === + @test Nullable{Int}(op(1, 2), bitand(b1, b2)) === @inferred(broadcast(op, Nullable{Int}(1, b1), Nullable{Int}(2, b2))) end diff --git a/test/numbers.jl b/test/numbers.jl index adf2fbcb20d64..d004b95de997e 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2353,7 +2353,7 @@ end for T = (UInt8,Int8,UInt16,Int16,UInt32,Int32,UInt64,Int64,UInt128,Int128) for n = 1:2:1000 - @test n*(n^typemax(T)) & typemax(T) == 1 + @test bitand(n*(n^typemax(T)), typemax(T)) == 1 n = bitor(rand(T), one(T)) @test n*(n^typemax(T)) == 1 end @@ -2879,7 +2879,7 @@ end @test T === typeof(t) for R in types - for op in (&, bitor, <<, >>, (>>>), %, ÷) + for op in (bitand, bitor, <<, >>, (>>>), %, ÷) T = @inferred Base.promote_op(op, S, R) t = @inferred op(one(S), one(R)) @test T === typeof(t) diff --git a/test/perf/kernel/ziggurat.jl b/test/perf/kernel/ziggurat.jl index 1ed2529ba05d0..706bfcb0e8bf3 100644 --- a/test/perf/kernel/ziggurat.jl +++ b/test/perf/kernel/ziggurat.jl @@ -115,9 +115,9 @@ function randn_zig() while (true) U = rand(UInt32) - i = 1 + (U & 0x0000007F) # 7 bit to choose the step - sign = U & 0x00000080 # 1 bit for the sign - j = U>>8 # 24 bit for the x-value + i = 1 + bitand(U, 0x0000007F) # 7 bit to choose the step + sign = bitand(U, 0x00000080) # 1 bit for the sign + j = U>>8 # 24 bit for the x-value x = j*wtab[i] if j < ktab[i]; break; end diff --git a/test/perf/shootout/meteor_contest.jl b/test/perf/shootout/meteor_contest.jl index 199b8cf8a431d..f1b1ffaeb2160 100644 --- a/test/perf/shootout/meteor_contest.jl +++ b/test/perf/shootout/meteor_contest.jl @@ -47,13 +47,13 @@ const masks = zeros(UInt64, 10) const masksAtCell = Array{Any}(width*height, height) valid(x, y) = (0 <= x < width) && (0 <= y < height) -legal(mask::UInt64, board::UInt64) = (mask & board) == 0 +legal(mask::UInt64, board::UInt64) = bitand(mask, board) == 0 zerocount(mask::UInt64) = 50 - count_ones(mask) function findFreeCell(board::UInt64) for y in 0:height-1 for x in 0:width-1 - if board & (UInt64(1) << (x + width*y)) == 0 + if bitand(board, UInt64(1) << (x + width*y)) == 0 return x, y end end @@ -66,7 +66,7 @@ function floodFill(board::UInt64, fixme) return board end - if board & (UInt64(1) << (x + width*y)) != 0 + if bitand(board, UInt64(1) << (x + width*y)) != 0 return board end @@ -148,7 +148,7 @@ function generateBitmasks() j = length(masks) - 1 while j >= 0 - if (masks[j + 1] & cellMask) == cellMask + if bitand(masks[j + 1], cellMask) == cellMask push!(masksAtCell[cellCounter + 1, color + 1], masks[j + 1]) j -= 1 else @@ -173,7 +173,7 @@ function solveCell(cell_, board::UInt64, n) return end - if board & (UInt64(1) << cell_) != 0 + if bitand(board, UInt64(1) << cell_) != 0 # Cell full solveCell(cell_ - 1, UInt64(board), n) return @@ -208,7 +208,7 @@ function stringOfMasks(masks) for y in 0:height-1 for x in 0:width-1 for color in 0:9 - if (masks[color+1] & mask) != 0 + if bitand(masks[color+1], mask) != 0 s = string(s, color) break elseif color == 9 diff --git a/test/reduce.jl b/test/reduce.jl index 92311bd28a823..4c6128ea6df35 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -48,7 +48,7 @@ @test mapreduce(abs2, +, Float64[]) === 0.0 @test mapreduce(abs2, Base.scalarmax, Float64[]) === 0.0 @test mapreduce(abs, max, Float64[]) === 0.0 -@test_throws ArgumentError mapreduce(abs2, &, Float64[]) +@test_throws ArgumentError mapreduce(abs2, bitand, Float64[]) @test_throws ArgumentError mapreduce(abs2, bitor, Float64[]) # mapreduce() type stability @@ -401,6 +401,6 @@ test18695(r) = sum( t^2 for t in r ) # issue #21107 @test foldr(-,2:2) == 2 -# test neutral element not picked incorrectly for &, | -@test @inferred(foldl(&, Int[1])) === 1 -@test_throws ArgumentError foldl(&, Int[]) +# test neutral element not picked incorrectly for bitand, bitor +@test @inferred(foldl(bitand, Int[1])) === 1 +@test_throws ArgumentError foldl(bitand, Int[]) diff --git a/test/serialize.jl b/test/serialize.jl index ca8aa059c7bda..005ef5798397c 100644 --- a/test/serialize.jl +++ b/test/serialize.jl @@ -507,8 +507,8 @@ let io = IOBuffer() @test b[1] == Serializer.HEADER_TAG @test b[2:3] == b"JL" @test b[4] == Serializer.ser_version - @test (b[5] & 0x3) == (ENDIAN_BOM == 0x01020304) - @test ((b[5] & 0xc)>>2) == (sizeof(Int) == 8) - @test (b[5] & 0xf0) == 0 + @test bitand(b[5], 0x3) == (ENDIAN_BOM == 0x01020304) + @test bitand(b[5], 0xc) >> 2 == (sizeof(Int) == 8) + @test bitand(b[5], 0xf0) == 0 @test all(b[6:8] .== 0) end diff --git a/test/show.jl b/test/show.jl index 674e8d85bfcd0..ee1a596146ce8 100644 --- a/test/show.jl +++ b/test/show.jl @@ -195,7 +195,7 @@ end""" # line meta if delta_ks == 0 # line meta - msk_s0 = (u << ls0) & bitnot(u << ls1 << 1) + msk_s0 = bitand(u << ls0, bitnot(u << ls1 << 1)) else # line meta msk_s0 = (u << ls0) @@ -203,7 +203,7 @@ end""" # line meta chunk_s0 = glue_src_bitchunks(src, ks0, ks1, msk_s0, ls0) # line meta - dest[kd0] = bitor(dest[kd0] & msk_d0, (chunk_s0 << ld0) & bitnot(msk_d0)) + dest[kd0] = bitor(bitand(dest[kd0], msk_d0), bitand(chunk_s0 << ld0, bitnot(msk_d0))) # line meta if delta_kd == 0 # line meta @@ -231,7 +231,7 @@ end""" # line meta chunk_s = bitor(chunk_s0 >>> (63 - ld0) >>> 1, chunk_s1 << ld0) # line meta - dest[kd1] = bitor(dest[kd1] & msk_d1, chunk_s & bitnot(msk_d1)) + dest[kd1] = bitor(bitand(dest[kd1], msk_d1), bitand(chunk_s, bitnot(msk_d1))) # line meta return end""" diff --git a/test/sparse/sparse.jl b/test/sparse/sparse.jl index b24a22dc92fbc..c1763de9199b7 100644 --- a/test/sparse/sparse.jl +++ b/test/sparse/sparse.jl @@ -65,7 +65,7 @@ do33 = ones(3) @test_throws DimensionMismatch map(min, sqrfloatmat, colfloatmat) @test_throws DimensionMismatch map(max, sqrfloatmat, colfloatmat) sqrboolmat, colboolmat = sprand(Bool, 4, 4, 0.5), sprand(Bool, 4, 1, 0.5) - @test_throws DimensionMismatch map(&, sqrboolmat, colboolmat) + @test_throws DimensionMismatch map(bitand, sqrboolmat, colboolmat) @test_throws DimensionMismatch map(bitor, sqrboolmat, colboolmat) @test_throws DimensionMismatch map(xor, sqrboolmat, colboolmat) end @@ -1705,8 +1705,8 @@ end A13024 = sparse([1,2,3,4,5], [1,2,3,4,5], fill(true,5)) B13024 = sparse([1,2,4,5], [1,2,3,5], fill(true,4)) - @test broadcast(&, A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3)) - @test typeof(broadcast(&, A13024, B13024)) == SparseMatrixCSC{Bool,Int} + @test broadcast(bitand, A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3)) + @test typeof(broadcast(bitand, A13024, B13024)) == SparseMatrixCSC{Bool,Int} @test broadcast(bitor, A13024, B13024) == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6)) @test typeof(broadcast(bitor, A13024, B13024)) == SparseMatrixCSC{Bool,Int} @@ -1723,7 +1723,7 @@ end for op in (+, -) @test op(A13024, B13024) == op(Array(A13024), Array(B13024)) end - for op in (max, min, &, bitor, xor) + for op in (max, min, bitand, bitor, xor) @test op.(A13024, B13024) == op.(Array(A13024), Array(B13024)) end end From bc4857f5f1d78789d748e28e0a810d655696564b Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Tue, 21 Nov 2017 15:09:17 -0800 Subject: [PATCH 11/17] Replace bitwise calls to & with bitand in base/. --- base/atomics.jl | 4 +- base/bitarray.jl | 106 ++++++++++++++++++------------------ base/bitset.jl | 4 +- base/c.jl | 24 ++++---- base/char.jl | 2 +- base/codevalidation.jl | 2 +- base/dict.jl | 12 ++-- base/exports.jl | 1 + base/file.jl | 4 +- base/float.jl | 72 ++++++++++++------------ base/gmp.jl | 6 +- base/grisu/bignum.jl | 4 +- base/grisu/bignums.jl | 42 +++++++------- base/grisu/fastfixed.jl | 6 +- base/grisu/fastprecision.jl | 4 +- base/grisu/fastshortest.jl | 4 +- base/grisu/float.jl | 20 +++---- base/hashing2.jl | 12 ++-- base/inference.jl | 12 ++-- base/int.jl | 28 +++++----- base/intfuncs.jl | 6 +- base/io.jl | 18 +++--- base/libgit2/callbacks.jl | 7 ++- base/libgit2/utils.jl | 4 +- base/linalg/bitarray.jl | 26 ++++----- base/math.jl | 40 +++++++------- base/multidimensional.jl | 6 +- base/nullable.jl | 2 +- base/printf.jl | 14 ++--- base/process.jl | 6 +- base/random/RNGs.jl | 8 +-- base/random/dSFMT.jl | 6 +- base/random/generation.jl | 12 ++-- base/random/misc.jl | 20 +++---- base/random/normal.jl | 4 +- base/reflection.jl | 8 +-- base/regex.jl | 14 ++--- base/repl/LineEdit.jl | 2 +- base/serialize.jl | 2 +- base/show.jl | 4 +- base/socket.jl | 12 ++-- base/special/exp.jl | 4 +- base/special/exp10.jl | 4 +- base/special/gamma.jl | 2 +- base/special/log.jl | 26 ++++----- base/special/rem_pio2.jl | 14 ++--- base/special/trig.jl | 12 ++-- base/stat.jl | 28 +++++----- base/strings/io.jl | 2 +- base/strings/search.jl | 10 ++-- base/strings/string.jl | 38 ++++++------- base/strings/util.jl | 2 +- base/sysinfo.jl | 2 +- base/twiceprecision.jl | 2 +- 54 files changed, 369 insertions(+), 367 deletions(-) diff --git a/base/atomics.jl b/base/atomics.jl index 705d8731a07fd..fa37273758429 100644 --- a/base/atomics.jl +++ b/base/atomics.jl @@ -180,7 +180,7 @@ function atomic_sub! end Atomically bitwise-and `x` with `val` -Performs `x[] &= val` atomically. Returns the **old** value. +Performs `x[] = bitand(x[]mval` atomically. Returns the **old** value. For further details, see LLVM's `atomicrmw and` instruction. @@ -203,7 +203,7 @@ function atomic_and! end Atomically bitwise-nand (not-and) `x` with `val` -Performs `x[] = bitnot(x[] & val)` atomically. Returns the **old** value. +Performs `x[] = bitnot(bitand(x[], val))` atomically. Returns the **old** value. For further details, see LLVM's `atomicrmw nand` instruction. diff --git a/base/bitarray.jl b/base/bitarray.jl index cdee15c623f77..44d6755542492 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -81,7 +81,7 @@ IndexStyle(::Type{<:BitArray}) = IndexLinear() const _msk64 = bitnot(UInt64(0)) @inline _div64(l) = l >>> 6 -@inline _mod64(l) = l & 63 +@inline _mod64(l) = bitand(l, 63) @inline _msk_end(l::Integer) = _msk64 >>> _mod64(-l) @inline _msk_end(B::BitArray) = _msk_end(length(B)) num_bit_chunks(n::Int) = _div64(n+63) @@ -96,7 +96,7 @@ function _check_bitarray_consistency(B::BitArray{N}) where N nc = length(Bc) nc == num_bit_chunks(n) || (warn("incorrect chunks length for length $n: expected=$(num_bit_chunks(n)) actual=$nc"); return false) n == 0 && return true - Bc[end] & _msk_end(n) == Bc[end] || (warn("nonzero bits in chunk after BitArray end"); return false) + bitand(Bc[end], _msk_end(n)) == Bc[end] || (warn("nonzero bits in chunk after BitArray end"); return false) return true end @@ -104,9 +104,9 @@ end function glue_src_bitchunks(src::Vector{UInt64}, k::Int, ks1::Int, msk_s0::UInt64, ls0::Int) @inbounds begin - chunk = ((src[k] & msk_s0) >>> ls0) + chunk = bitand(src[k], msk_s0) >>> ls0 if ks1 > k && ls0 > 0 - chunk_n = (src[k + 1] & bitnot(msk_s0)) + chunk_n = bitand(src[k + 1], bitnot(msk_s0)) chunk = bitor(chunk, chunk_n << (64 - ls0)) end end @@ -135,14 +135,14 @@ function copy_chunks!(dest::Vector{UInt64}, pos_d::Integer, src::Vector{UInt64}, msk_d1 = (u << (ld1+1)) end if delta_ks == 0 - msk_s0 = (u << ls0) & bitnot(u << (ls1+1)) + msk_s0 = bitand(u << ls0, bitnot(u << (ls1+1))) else msk_s0 = (u << ls0) end chunk_s0 = glue_src_bitchunks(src, ks0, ks1, msk_s0, ls0) - dest[kd0] = bitor(dest[kd0] & msk_d0, (chunk_s0 << ld0) & bitnot(msk_d0)) + dest[kd0] = bitor(bitand(dest[kd0], msk_d0), bitand(chunk_s0 << ld0, bitnot(msk_d0))) delta_kd == 0 && return @@ -164,7 +164,7 @@ function copy_chunks!(dest::Vector{UInt64}, pos_d::Integer, src::Vector{UInt64}, chunk_s = bitor(chunk_s0 >>> (64 - ld0), chunk_s1 << ld0) - dest[kd1] = bitor(dest[kd1] & msk_d1, chunk_s & bitnot(msk_d1)) + dest[kd1] = bitor(bitand(dest[kd1], msk_d1), bitand(chunk_s, bitnot(msk_d1))) return end @@ -195,18 +195,18 @@ function copy_chunks_rtol!(chunks::Vector{UInt64}, pos_d::Integer, pos_s::Intege msk_d1 = (u << (ld1+1)) end if delta_ks == 0 - msk_s0 = (u << ls0) & bitnot(u << (ls1+1)) + msk_s0 = bitand(u << ls0, bitnot(u << (ls1+1))) else msk_s0 = (u << ls0) end - chunk_s0 = glue_src_bitchunks(chunks, ks0, ks1, msk_s0, ls0) & bitnot(u << s) - chunks[kd0] = bitor(chunks[kd0] & msk_d0, (chunk_s0 << ld0) & bitnot(msk_d0)) + chunk_s0 = bitand(glue_src_bitchunks(chunks, ks0, ks1, msk_s0, ls0), bitnot(u << s)) + chunks[kd0] = bitor(bitand(chunks[kd0], msk_d0), bitand(chunk_s0 << ld0, bitnot(msk_d0))) if delta_kd != 0 chunk_s = (chunk_s0 >>> (64 - ld0)) - chunks[kd1] = bitor(chunks[kd1] & msk_d1, chunk_s & bitnot(msk_d1)) + chunks[kd1] = bitor(bitand(chunks[kd1], msk_d1), bitand(chunk_s, bitnot(msk_d1))) end left -= s @@ -224,7 +224,7 @@ function fill_chunks!(Bc::Array{UInt64}, x::Bool, pos::Integer, numbits::Integer u = _msk64 if k1 == k0 - msk0 = (u << l0) & bitnot(u << (l1+1)) + msk0 = bitand(u << l0, bitnot(u << (l1+1))) else msk0 = (u << l0) msk1 = bitnot(u << (l1+1)) @@ -236,11 +236,11 @@ function fill_chunks!(Bc::Array{UInt64}, x::Bool, pos::Integer, numbits::Integer end k1 > k0 && (Bc[k1] = bitor(Bc[k1], msk1)) else - Bc[k0] &= bitnot(msk0) + Bc[k0] = bitand(Bc[k0], bitnot(msk0)) for k = k0+1:k1-1 Bc[k] = 0 end - k1 > k0 && (Bc[k1] &= bitnot(msk1)) + k1 > k0 && (Bc[k1] = bitand(Bc[k1], bitnot(msk1))) end end @@ -253,7 +253,7 @@ function pack8bools(z::UInt64) z = bitor(z, z >>> 7) z = bitor(z, z >>> 14) z = bitor(z, z >>> 28) - z &= 0xFF + z = bitand(z, 0xFF) return z end @@ -281,7 +281,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} c = bitor(c, UInt64(C[ind]) << j) ind += 1 end - Bc[kd0] = bitor(Bc[kd0] & msk_d0, c & bitnot(msk_d0)) + Bc[kd0] = bitor(bitand(Bc[kd0], msk_d0), bitand(c, bitnot(msk_d0))) bind += 1 end @@ -318,7 +318,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} c = bitor(c, UInt64(C[ind]) << j) ind += 1 end - Bc[kd1] = bitor(Bc[kd1] & msk_d1, c & bitnot(msk_d1)) + Bc[kd1] = bitor(bitand(Bc[kd1], msk_d1), bitand(c, bitnot(msk_d1))) end end @@ -336,7 +336,7 @@ dumpbitcache(Bc::Vector{UInt64}, bind::Int, C::Vector{Bool}) = ## custom iterator ## start(B::BitArray) = 0 -next(B::BitArray, i::Int) = (B.chunks[_div64(i)+1] & (UInt64(1)<<_mod64(i)) != 0, i+1) +next(B::BitArray, i::Int) = !iszero(bitand(B.chunks[_div64(i)+1], UInt64(1) << _mod64(i))), i+1 done(B::BitArray, i::Int) = i >= length(B) ## similar, fill!, copy! etc ## @@ -358,7 +358,7 @@ function fill!(B::BitArray, x) fill!(Bc, 0) else fill!(Bc, _msk64) - Bc[end] &= _msk_end(B) + Bc[end] = bitand(Bc[end], _msk_end(B)) end return B end @@ -457,7 +457,7 @@ function copy!(dest::BitArray, src::BitArray) else msk_s = _msk_end(src) msk_d = bitnot(msk_s) - destc[nc] = bitor(msk_d & destc[nc], msk_s & srcc[nc]) + destc[nc] = bitor(bitand(msk_d, destc[nc]), bitand(msk_s, srcc[nc])) end end return dest @@ -672,7 +672,7 @@ end @inline function unsafe_bitgetindex(Bc::Vector{UInt64}, i::Int) i1, i2 = get_chunks_id(i) u = UInt64(1) << i2 - @inbounds r = (Bc[i1] & u) != 0 + @inbounds r = bitand(Bc[i1], u) != 0 return r end @@ -688,7 +688,7 @@ end u = UInt64(1) << i2 @inbounds begin c = Bc[i1] - Bc[i1] = ifelse(x, bitor(c, u), c & bitnot(u)) + Bc[i1] = ifelse(x, bitor(c, u), bitand(c, bitnot(u))) end end @@ -730,7 +730,7 @@ function _unsafe_setindex!(B::BitArray, x, I::BitArray) end else for i = 1:length(Bc) - Bc[i] &= bitnot(Ic[i]) + Bc[i] = bitand(Bc[i], bitnot(Ic[i])) end end return B @@ -756,10 +756,10 @@ function _unsafe_setindex!(B::BitArray, X::AbstractArray, I::BitArray) @inbounds C = Bc[i] u = UInt64(1) for j = 1:(i < lc ? 64 : last_chunk_len) - if Imsk & u != 0 + if bitand(Imsk, u) != 0 lx < c && throw_setindex_mismatch(X, c) @inbounds x = convert(Bool, X[c]) - C = ifelse(x, bitor(C, u), C & bitnot(u)) + C = ifelse(x, bitor(C, u), bitand(C, bitnot(u))) c += 1 end u <<= 1 @@ -934,7 +934,7 @@ function insert!(B::BitVector, i::Integer, item) msk_aft = (_msk64 << j) msk_bef = bitnot(msk_aft) - Bc[k] = bitor(msk_bef & Bc[k], (msk_aft & Bc[k]) << 1) + Bc[k] = bitor(bitand(msk_bef, Bc[k]), bitand(msk_aft, Bc[k]) << 1) B[i] = item B end @@ -949,7 +949,7 @@ function _deleteat!(B::BitVector, i::Integer) Bc = B.chunks @inbounds begin - Bc[k] = bitor(msk_bef & Bc[k], (msk_aft & Bc[k]) >> 1) + Bc[k] = bitor(bitand(msk_bef, Bc[k]), bitand(msk_aft, Bc[k]) >> 1) if length(Bc) > k Bc[k] = bitor(Bc[k], Bc[k + 1] << 63) end @@ -997,7 +997,7 @@ function deleteat!(B::BitVector, r::UnitRange{Int}) B.len = new_l if new_l > 0 - Bc[end] &= _msk_end(new_l) + Bc[end] = bitand(Bc[end], _msk_end(new_l)) end return B @@ -1035,7 +1035,7 @@ function deleteat!(B::BitVector, inds) B.len = new_l if new_l > 0 - Bc[end] &= _msk_end(new_l) + Bc[end] = bitand(Bc[end], _msk_end(new_l)) end return B @@ -1087,7 +1087,7 @@ function splice!(B::BitVector, r::Union{UnitRange{Int}, Integer}, ins::AbstractA B.len = new_l if new_l > 0 - Bc[end] &= _msk_end(new_l) + Bc[end] = bitand(Bc[end], _msk_end(new_l)) end return v @@ -1122,7 +1122,7 @@ function (-)(B::BitArray) u = UInt64(1) c = Bc[i] for j = 1:64 - if c & u != 0 + if bitand(c, u) != 0 A[ind] = -1 end ind += 1 @@ -1132,7 +1132,7 @@ function (-)(B::BitArray) u = UInt64(1) c = Bc[end] for j = 0:_mod64(l-1) - if c & u != 0 + if bitand(c, u) != 0 A[ind] = -1 end ind += 1 @@ -1150,7 +1150,7 @@ function broadcast(::typeof(bitnot), B::BitArray) for i = 1:length(Bc) Cc[i] = bitnot(Bc[i]) end - Cc[end] &= _msk_end(B) + Cc[end] = bitand(Cc[end], _msk_end(B)) end return C end @@ -1179,7 +1179,7 @@ function flipbits!(B::BitArray) for i = 1:length(Bc) Bc[i] = bitnot(Bc[i]) end - Bc[end] &= _msk_end(B) + Bc[end] = bitand(Bc[end], _msk_end(B)) end return B end @@ -1229,7 +1229,7 @@ for f in (:&, :|, :xor) for i = 1:length(Fc) Fc[i] = ($f)(Ac[i], Bc[i]) end - Fc[end] &= _msk_end(F) + Fc[end] = bitand(Fc[end], _msk_end(F)) return F end broadcast(::typeof($f), A::DenseArray{Bool}, B::BitArray) = broadcast($f, BitArray(A), B) @@ -1302,12 +1302,12 @@ end function reverse_bits(src::UInt64) z = src - z = bitor((z >>> 1) & 0x5555555555555555, (z << 1) & 0xaaaaaaaaaaaaaaaa) - z = bitor((z >>> 2) & 0x3333333333333333, (z << 2) & 0xcccccccccccccccc) - z = bitor((z >>> 4) & 0x0f0f0f0f0f0f0f0f, (z << 4) & 0xf0f0f0f0f0f0f0f0) - z = bitor((z >>> 8) & 0x00ff00ff00ff00ff, (z << 8) & 0xff00ff00ff00ff00) - z = bitor((z >>> 16) & 0x0000ffff0000ffff, (z << 16) & 0xffff0000ffff0000) - return bitor((z >>> 32) & 0x00000000ffffffff, (z << 32) & 0xffffffff00000000) + z = bitor(bitand(z >>> 1, 0x5555555555555555), bitand(z << 1, 0xaaaaaaaaaaaaaaaa)) + z = bitor(bitand(z >>> 2, 0x3333333333333333), bitand(z << 2, 0xcccccccccccccccc)) + z = bitor(bitand(z >>> 4, 0x0f0f0f0f0f0f0f0f), bitand(z << 4, 0xf0f0f0f0f0f0f0f0)) + z = bitor(bitand(z >>> 8, 0x00ff00ff00ff00ff), bitand(z << 8, 0xff00ff00ff00ff00)) + z = bitor(bitand(z >>> 16, 0x0000ffff0000ffff), bitand(z << 16, 0xffff0000ffff0000)) + return bitor(bitand(z >>> 32, 0x00000000ffffffff), bitand(z << 32, 0xffffffff00000000)) end function reverse!(B::BitVector) @@ -1508,8 +1508,8 @@ function findnext(B::BitArray, start::Integer) mask = _msk64 << within_chunk_start @inbounds begin - if Bc[chunk_start] & mask != 0 - return (chunk_start-1) << 6 + trailing_zeros(Bc[chunk_start] & mask) + 1 + if bitand(Bc[chunk_start], mask) != 0 + return (chunk_start-1) << 6 + trailing_zeros(bitand(Bc[chunk_start], mask)) + 1 end for i = chunk_start+1:length(Bc) @@ -1587,8 +1587,8 @@ function findprev(B::BitArray, start::Integer) mask = _msk_end(start) @inbounds begin - if Bc[chunk_start] & mask != 0 - return (chunk_start-1) << 6 + (64 - leading_zeros(Bc[chunk_start] & mask)) + if bitand(Bc[chunk_start], mask) != 0 + return (chunk_start-1) << 6 + (64 - leading_zeros(bitand(Bc[chunk_start], mask))) end for i = (chunk_start-1):-1:1 @@ -1658,7 +1658,7 @@ function find(B::BitArray) u = UInt64(1) c = Bc[i] for j = 1:64 - if c & u != 0 + if bitand(c, u) != 0 I[Icount] = Bcount Icount += 1 end @@ -1669,7 +1669,7 @@ function find(B::BitArray) u = UInt64(1) c = Bc[end] for j = 0:_mod64(l-1) - if c & u != 0 + if bitand(c, u) != 0 I[Icount] = Bcount Icount += 1 end @@ -1754,8 +1754,8 @@ for (T, f) in ((:(Union{typeof(&), typeof(*), typeof(min)}), :(&)), (:(Union{typeof(>=), typeof(^)}), :((p, q) -> bitor(p, bitnot(q)))), (:(typeof(<=)), :((p, q) -> bitor(bitnot(p), q))), (:(typeof(==)), :((p, q) -> bitnot(xor(p, q)))), - (:(typeof(<)), :((p, q) -> bitnot(p) & q)), - (:(typeof(>)), :((p, q) -> p & bitnot(q)))) + (:(typeof(<)), :((p, q) -> bitand(bitnot(p), q))), + (:(typeof(>)), :((p, q) -> bitand(p, bitnot(q))))) @eval map(::$T, A::BitArray, B::BitArray) = bit_map!($f, similar(A), A, B) @eval map!(::$T, dest::BitArray, A::BitArray, B::BitArray) = bit_map!($f, dest, A, B) end @@ -1771,7 +1771,7 @@ function bit_map!(f::F, dest::BitArray, A::BitArray) where F for i = 1:(length(Ac)-1) destc[i] = f(Ac[i]) end - destc[end] = f(Ac[end]) & _msk_end(A) + destc[end] = bitand(f(Ac[end]), _msk_end(A)) dest end function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F @@ -1783,7 +1783,7 @@ function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F for i = 1:(length(Ac)-1) destc[i] = f(Ac[i], Bc[i]) end - destc[end] = f(Ac[end], Bc[end]) & _msk_end(A) + destc[end] = bitand(f(Ac[end], Bc[end]), _msk_end(A)) dest end @@ -1889,8 +1889,8 @@ function read!(s::IO, B::BitArray) n = length(B) Bc = B.chunks nc = length(read!(s, Bc)) - if length(Bc) > 0 && Bc[end] & _msk_end(n) ≠ Bc[end] - Bc[end] &= _msk_end(n) # ensure that the BitArray is not broken + if length(Bc) > 0 && bitand(Bc[end], _msk_end(n)) ≠ Bc[end] + Bc[end] = bitand(Bc[end], _msk_end(n)) # ensure that the BitArray is not broken throw(DimensionMismatch("read mismatch, found non-zero bits after BitArray length")) end return B diff --git a/base/bitset.jl b/base/bitset.jl index e961844af80f5..016de396b4f91 100644 --- a/base/bitset.jl +++ b/base/bitset.jl @@ -138,14 +138,14 @@ Intersects sets `s1` and `s2` and overwrites the set `s1` with the result. If ne will be expanded to the size of `s2`. """ function intersect!(s1::BitSet, s2::BitSet) - _matched_map!(&, s1.bits, s2.bits) + _matched_map!(bitand, s1.bits, s2.bits) s1 end setdiff(s::BitSet, ns) = setdiff!(copy(s), ns) setdiff!(s::BitSet, ns) = (for n in ns; delete!(s, n); end; s) function setdiff!(s1::BitSet, s2::BitSet) - _matched_map!((p, q) -> p & bitnot(q), s1.bits, s2.bits) + _matched_map!((p, q) -> bitand(p, bitnot(q)), s1.bits, s2.bits) s1 end diff --git a/base/c.jl b/base/c.jl index 7ad73fefe18df..50de51162586e 100644 --- a/base/c.jl +++ b/base/c.jl @@ -242,7 +242,7 @@ function transcode(::Type{UInt16}, src::Vector{UInt8}) push!(dst, xor(0x2080, UInt16(b) << 12, UInt16(c) << 6, d)) else # 4-byte UTF-8 push!(dst, 0xe5b8 + (UInt16(a) << 8) + (UInt16(b) << 2) + (c >> 4), - xor(0xdc80, UInt16(c & 0xf) << 6, d)) + xor(0xdc80, UInt16(bitand(c, 0xf)) << 6, d)) end else # too short push!(dst, a, b, c) @@ -278,9 +278,9 @@ function transcode(::Type{UInt8}, src::Vector{UInt16}) m += 1 elseif a < 0x800 # 2-byte UTF-8 m += 2 - elseif a & 0xfc00 == 0xd800 && i < length(src) + elseif bitand(a, 0xfc00) == 0xd800 && i < length(src) b = src[i += 1] - if (b & 0xfc00) == 0xdc00 # 2-unit UTF-16 sequence => 4-byte UTF-8 + if bitand(b, 0xfc00) == 0xdc00 # 2-unit UTF-16 sequence => 4-byte UTF-8 m += 4 else m += 3 @@ -303,28 +303,28 @@ function transcode(::Type{UInt8}, src::Vector{UInt16}) dst[j += 1] = a % UInt8 elseif a < 0x800 # 2-byte UTF-8 dst[j += 1] = bitor(0xc0, (a >> 6) % UInt8) - dst[j += 1] = bitor(0x80, (a % UInt8) & 0x3f) - elseif a & 0xfc00 == 0xd800 && i < n + dst[j += 1] = bitor(0x80, bitand(a % UInt8, 0x3f)) + elseif bitand(a, 0xfc00) == 0xd800 && i < n b = src[i += 1] - if (b & 0xfc00) == 0xdc00 + if bitand(b, 0xfc00) == 0xdc00 # 2-unit UTF-16 sequence => 4-byte UTF-8 a += 0x2840 dst[j += 1] = bitor(0xf0, (a >> 8) % UInt8) dst[j += 1] = bitor(0x80, (a % UInt8) >> 2) - dst[j += 1] = xor(0xf0, ((a % UInt8) << 4) & 0x3f, (b >> 6) % UInt8) - dst[j += 1] = bitor(0x80, (b % UInt8) & 0x3f) + dst[j += 1] = xor(0xf0, bitand((a % UInt8) << 4, 0x3f), (b >> 6) % UInt8) + dst[j += 1] = bitor(0x80, bitand(b % UInt8, 0x3f)) else dst[j += 1] = bitor(0xe0, (a >> 12) % UInt8) - dst[j += 1] = bitor(0x80, ((a >> 6) % UInt8) & 0x3f) - dst[j += 1] = bitor(0x80, (a % UInt8) & 0x3f) + dst[j += 1] = bitor(0x80, bitand((a >> 6) % UInt8, 0x3f)) + dst[j += 1] = bitor(0x80, bitand(a % UInt8, 0x3f)) a = b; continue end else # 1-unit high UTF-16 or unpaired high surrogate # either way, encode as 3-byte UTF-8 code point dst[j += 1] = bitor(0xe0, (a >> 12) % UInt8) - dst[j += 1] = bitor(0x80, ((a >> 6) % UInt8) & 0x3f) - dst[j += 1] = bitor(0x80, (a % UInt8) & 0x3f) + dst[j += 1] = bitor(0x80, bitand((a >> 6) % UInt8, 0x3f)) + dst[j += 1] = bitor(0x80, bitand(a % UInt8, 0x3f)) end i < n || break a = src[i += 1] diff --git a/base/char.jl b/base/char.jl index ea7334eb0679e..0c184e1e990ab 100644 --- a/base/char.jl +++ b/base/char.jl @@ -71,7 +71,7 @@ function show(io::IO, c::Char) write(io, 0x27, 0x5c, c <= '\x7f' ? 0x78 : c <= '\uffff' ? 0x75 : 0x55) d = max(2, 8 - (leading_zeros(u) >> 2)) while 0 < d - write(io, hex_chars[((u >> ((d -= 1) << 2)) & 0xf) + 1]) + write(io, hex_chars[bitand(u >> ((d -= 1) << 2), 0xf) + 1]) end write(io, 0x27) end diff --git a/base/codevalidation.jl b/base/codevalidation.jl index 7c0daf76aca5f..b7ca04916c553 100644 --- a/base/codevalidation.jl +++ b/base/codevalidation.jl @@ -146,4 +146,4 @@ function is_valid_rvalue(x) return !isa(x, GotoNode) && !isa(x, LabelNode) && !isa(x, LineNumberNode) end -is_flag_set(byte::UInt8, flag::UInt8) = (byte & flag) == flag +is_flag_set(byte::UInt8, flag::UInt8) = bitand(byte, flag) == flag diff --git a/base/dict.jl b/base/dict.jl index 67f8fbfd98d34..d72fa24f6d281 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -207,7 +207,7 @@ function convert(::Type{Dict{K,V}},d::Associative) where V where K end convert(::Type{Dict{K,V}},d::Dict{K,V}) where {K,V} = d -hashindex(key, sz) = (((hash(key)%Int) & (sz-1)) + 1)::Int +hashindex(key, sz) = (bitand(hash(key) % Int, sz - 1) + 1)::Int @propagate_inbounds isslotempty(h::Dict, i::Int) = h.slots[i] == 0x0 @propagate_inbounds isslotfilled(h::Dict, i::Int) = h.slots[i] == 0x1 @@ -243,9 +243,9 @@ function rehash!(h::Dict{K,V}, newsz = length(h.keys)) where V where K v = oldv[i] index0 = index = hashindex(k, newsz) while slots[index] != 0 - index = (index & (newsz-1)) + 1 + index = bitand(index, newsz - 1) + 1 end - probe = (index - index0) & (newsz-1) + probe = bitand(index - index0, newsz - 1) probe > maxprobe && (maxprobe = probe) slots[index] = 0x1 keys[index] = k @@ -336,7 +336,7 @@ function ht_keyindex(h::Dict{K,V}, key) where V where K return index end - index = (index & (sz-1)) + 1 + index = bitand(index, sz - 1) + 1 iter += 1 iter > maxprobe && break end @@ -373,7 +373,7 @@ function ht_keyindex2(h::Dict{K,V}, key) where V where K return index end - index = (index & (sz-1)) + 1 + index = bitand(index, sz - 1) + 1 iter += 1 iter > maxprobe && break end @@ -387,7 +387,7 @@ function ht_keyindex2(h::Dict{K,V}, key) where V where K h.maxprobe = iter return -index end - index = (index & (sz-1)) + 1 + index = bitand(index, sz - 1) + 1 iter += 1 end diff --git a/base/exports.jl b/base/exports.jl index ea724842c4231..1ed977cf15b8a 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -215,6 +215,7 @@ export ^, |, |>, + bitand, bitor, bitnot, :, diff --git a/base/file.jl b/base/file.jl index cea0ef93293e7..63e778f3b52ee 100644 --- a/base/file.jl +++ b/base/file.jl @@ -138,7 +138,7 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false) try @static if Sys.iswindows() # is writable on windows actually means "is deletable" - if (filemode(path) & 0o222) == 0 + if bitand(filemode(path), 0o222) == 0 chmod(path, 0o777) end end @@ -287,7 +287,7 @@ end function mktempdir(parent=tempdir()) seed::UInt32 = rand(UInt32) while true - if (seed & typemax(UInt16)) == 0 + if bitand(seed, typemax(UInt16)) == 0 seed += 1 end filename = tempname(parent, seed) diff --git a/base/float.jl b/base/float.jl index f87a73e778db1..e81d78802930c 100644 --- a/base/float.jl +++ b/base/float.jl @@ -78,11 +78,11 @@ function convert(::Type{Float64}, x::UInt128) x == 0 && return 0.0 n = 128-leading_zeros(x) # ndigits0z(x,2) if n <= 53 - y = ((x % UInt64) << (53-n)) & 0x000f_ffff_ffff_ffff + y = bitand((x % UInt64) << (53-n), 0x000f_ffff_ffff_ffff) else - y = ((x >> (n-54)) % UInt64) & 0x001f_ffff_ffff_ffff # keep 1 extra bit + y = bitand((x >> (n-54)) % UInt64, 0x001f_ffff_ffff_ffff) # keep 1 extra bit y = (y+1)>>1 # round, ties up (extra leading bit in case of next exponent) - y &= bitnot(UInt64(trailing_zeros(x) == (n-54))) # fix last bit to round to even + y = bitand(y, bitnot(UInt64(trailing_zeros(x) == (n-54)))) # fix last bit to round to even end d = ((n+1022) % UInt64) << 52 reinterpret(Float64, d + y) @@ -90,15 +90,15 @@ end function convert(::Type{Float64}, x::Int128) x == 0 && return 0.0 - s = ((x >>> 64) % UInt64) & 0x8000_0000_0000_0000 # sign bit + s = bitand((x >>> 64) % UInt64, 0x8000_0000_0000_0000) # sign bit x = abs(x) % UInt128 n = 128-leading_zeros(x) # ndigits0z(x,2) if n <= 53 - y = ((x % UInt64) << (53-n)) & 0x000f_ffff_ffff_ffff + y = bitand((x % UInt64) << (53-n), 0x000f_ffff_ffff_ffff) else - y = ((x >> (n-54)) % UInt64) & 0x001f_ffff_ffff_ffff # keep 1 extra bit + y = bitand((x >> (n-54)) % UInt64, 0x001f_ffff_ffff_ffff) # keep 1 extra bit y = (y+1)>>1 # round, ties up (extra leading bit in case of next exponent) - y &= bitnot(UInt64(trailing_zeros(x) == (n-54))) # fix last bit to round to even + y = bitand(y, bitnot(UInt64(trailing_zeros(x) == (n-54)))) # fix last bit to round to even end d = ((n+1022) % UInt64) << 52 reinterpret(Float64, bitor(s, d) + y) @@ -108,11 +108,11 @@ function convert(::Type{Float32}, x::UInt128) x == 0 && return 0f0 n = 128-leading_zeros(x) # ndigits0z(x,2) if n <= 24 - y = ((x % UInt32) << (24-n)) & 0x007f_ffff + y = bitand(((x % UInt32) << (24-n), 0x007f_ffff) else - y = ((x >> (n-25)) % UInt32) & 0x00ff_ffff # keep 1 extra bit + y = bitand(((x >> (n-25)) % UInt32, 0x00ff_ffff) # keep 1 extra bit y = (y+one(UInt32))>>1 # round, ties up (extra leading bit in case of next exponent) - y &= bitnot(UInt32(trailing_zeros(x) == (n-25))) # fix last bit to round to even + y = bitand(y, bitnot(UInt32(trailing_zeros(x) == (n-25)))) # fix last bit to round to even end d = ((n+126) % UInt32) << 23 reinterpret(Float32, d + y) @@ -120,15 +120,15 @@ end function convert(::Type{Float32}, x::Int128) x == 0 && return 0f0 - s = ((x >>> 96) % UInt32) & 0x8000_0000 # sign bit + s = bitand((x >>> 96) % UInt32, 0x8000_0000) # sign bit x = abs(x) % UInt128 n = 128-leading_zeros(x) # ndigits0z(x,2) if n <= 24 - y = ((x % UInt32) << (24-n)) & 0x007f_ffff + y = bitand((x % UInt32) << (24-n), 0x007f_ffff) else - y = ((x >> (n-25)) % UInt32) & 0x00ff_ffff # keep 1 extra bit + y = bitand((x >> (n-25)) % UInt32, 0x00ff_ffff) # keep 1 extra bit y = (y+one(UInt32))>>1 # round, ties up (extra leading bit in case of next exponent) - y &= bitnot(UInt32(trailing_zeros(x) == (n-25))) # fix last bit to round to even + y = bitand(y, bitnot(UInt32(trailing_zeros(x) == (n-25)))) # fix last bit to round to even end d = ((n+126) % UInt32) << 23 reinterpret(Float32, bitor(s, d) + y) @@ -137,20 +137,20 @@ end function convert(::Type{Float16}, val::Float32) f = reinterpret(UInt32, val) if isnan(val) - t = 0x8000 ⊻ (0x8000 & ((f >> 0x10) % UInt16)) + t = 0x8000 ⊻ bitand(0x8000, (f >> 0x10) % UInt16) return reinterpret(Float16, t ⊻ ((f >> 0xd) % UInt16)) end - i = (f >> 23) & 0x1ff + 1 + i = bitand(f >> 23, 0x1ff) + 1 sh = shifttable[i] - f &= 0x007fffff + f = bitand(f, 0x007fffff) h::UInt16 = basetable[i] + (f >> sh) # round # NOTE: we maybe should ignore NaNs here, but the payload is # getting truncated anyway so "rounding" it might not matter - nextbit = (f >> (sh-1)) & 1 + nextbit = bitand(f >> (sh-1), 1) if nextbit != 0 # Round halfway to even or check lower bits - if h&1 == 1 || (f & ((1<<(sh-1))-1)) != 0 + if bitand(h, 1) == 1 || bitand(f, (1 << (sh-1)) - 1) != 0 h += 1 end end @@ -159,9 +159,9 @@ end function convert(::Type{Float32}, val::Float16) local ival::UInt32 = reinterpret(UInt16, val) - local sign::UInt32 = (ival & 0x8000) >> 15 - local exp::UInt32 = (ival & 0x7c00) >> 10 - local sig::UInt32 = (ival & 0x3ff) >> 0 + local sign::UInt32 = bitand(ival, 0x8000) >> 15 + local exp::UInt32 = bitand(ival, 0x7c00) >> 10 + local sig::UInt32 = bitand(ival, 0x3ff) >> 0 local ret::UInt32 if exp == 0 @@ -171,13 +171,13 @@ function convert(::Type{Float32}, val::Float16) else n_bit = 1 bit = 0x0200 - while (bit & sig) == 0 + while bitand(bit, sig) == 0 n_bit = n_bit + 1 bit = bit >> 1 end sign = sign << 31 exp = (-14 - n_bit + 127) << 23 - sig = ((sig & bitnot(bit)) << n_bit) << (23 - 10) + sig = (bitand(sig, bitnot(bit)) << n_bit) << (23 - 10) ret = bitor(sign, exp, sig) end elseif exp == 0x1f @@ -306,8 +306,8 @@ end function unsafe_trunc(::Type{UInt128}, x::Float64) xu = reinterpret(UInt64,x) - k = Int(xu >> 52) & 0x07ff - 1075 - xu = bitor(xu & 0x000f_ffff_ffff_ffff, 0x0010_0000_0000_0000) + k = bitand(Int(xu >> 52), 0x07ff) - 1075 + xu = bitor(bitand(xu, 0x000f_ffff_ffff_ffff), 0x0010_0000_0000_0000) if k <= 0 UInt128(xu >> -k) else @@ -320,8 +320,8 @@ end function unsafe_trunc(::Type{UInt128}, x::Float32) xu = reinterpret(UInt32,x) - k = Int(xu >> 23) & 0x00ff - 150 - xu = bitor(xu & 0x007f_ffff, 0x0080_0000) + k = bitand(Int(xu >> 23), 0x00ff) - 150 + xu = bitor(bitand(xu, 0x007f_ffff), 0x0080_0000) if k <= 0 UInt128(xu >> -k) else @@ -432,10 +432,10 @@ end function ==(x::Float16, y::Float16) ix = reinterpret(UInt16,x) iy = reinterpret(UInt16,y) - if bitor(ix, iy) & 0x7fff > 0x7c00 #isnan(x) || isnan(y) + if bitand(bitor(ix, iy), 0x7fff) > 0x7c00 #isnan(x) || isnan(y) return false end - if bitor(ix, iy) & 0x7fff == 0x0000 + if bitand(bitor(ix, iy), 0x7fff) == 0x0000 return true end return ix == iy @@ -526,7 +526,7 @@ end <=(x::Union{Int32,UInt32}, y::Float32) = Float64(x)<=Float64(y) -abs(x::Float16) = reinterpret(Float16, reinterpret(UInt16, x) & 0x7fff) +abs(x::Float16) = reinterpret(Float16, bitand(reinterpret(UInt16, x), 0x7fff)) abs(x::Float32) = abs_float(x) abs(x::Float64) = abs_float(x) @@ -536,7 +536,7 @@ abs(x::Float64) = abs_float(x) Test whether a floating point number is not a number (NaN). """ isnan(x::AbstractFloat) = x != x -isnan(x::Float16) = reinterpret(UInt16,x)&0x7fff > 0x7c00 +isnan(x::Float16) = bitand(reinterpret(UInt16,x), 0x7fff) > 0x7c00 isnan(x::Real) = false """ @@ -553,7 +553,7 @@ false ``` """ isfinite(x::AbstractFloat) = x - x == 0 -isfinite(x::Float16) = reinterpret(UInt16,x)&0x7c00 != 0x7c00 +isfinite(x::Float16) = bitand(reinterpret(UInt16,x), 0x7c00) != 0x7c00 isfinite(x::Real) = decompose(x)[3] != 0 isfinite(x::Integer) = true @@ -615,7 +615,7 @@ function nextfloat(f::IEEEFloat, d::Integer) isnan(f) && return f fi = reinterpret(Signed, f) fneg = fi < 0 - fu = unsigned(fi & typemax(fi)) + fu = unsigned(bitand(fi, typemax(fi))) dneg = d < 0 da = uabs(d) @@ -715,7 +715,7 @@ Test whether a floating point number is subnormal. """ function issubnormal(x::T) where {T<:IEEEFloat} y = reinterpret(Unsigned, x) - (y & exponent_mask(T) == 0) & (y & significand_mask(T) != 0) + iszero(bitand(y, exponent_mask(T))) & !iszero(bitand(y, significand_mask(T))) end @eval begin @@ -870,7 +870,7 @@ uinttype(::Type{Float64}) = UInt64 uinttype(::Type{Float32}) = UInt32 uinttype(::Type{Float16}) = UInt16 -Base.iszero(x::Float16) = reinterpret(UInt16, x) & bitnot(sign_mask(Float16)) == 0x0000 +Base.iszero(x::Float16) = bitand(reinterpret(UInt16, x), bitnot(sign_mask(Float16))) == 0x0000 ## Array operations on floating point numbers ## diff --git a/base/gmp.jl b/base/gmp.jl index 9b0981013ded5..da142ddaefacf 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -4,7 +4,7 @@ module GMP export BigInt -import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, bitnot, (&), bitor, xor, +import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, bitnot, bitand, bitor, xor, binomial, cmp, convert, div, divrem, factorial, fld, gcd, gcdx, lcm, mod, ndigits, promote_rule, rem, show, isqrt, string, powermod, sum, trailing_zeros, trailing_ones, count_ones, base, tryparse_internal, @@ -288,7 +288,7 @@ function convert(::Type{BigInt}, x::Integer) b = BigInt(0) shift = 0 while x < -1 - b += BigInt(bitnot(UInt32(x&0xffffffff)))<>= 32 shift += 32 end @@ -300,7 +300,7 @@ function convert(::Type{BigInt}, x::Integer) b = BigInt(0) shift = 0 while x > 0 - b += BigInt(UInt32(x&0xffffffff))<>>= 32 shift += 32 end diff --git a/base/grisu/bignum.jl b/base/grisu/bignum.jl index 2f1d67ce292ed..71cff5af13ff1 100644 --- a/base/grisu/bignum.jl +++ b/base/grisu/bignum.jl @@ -30,7 +30,7 @@ function normalizedexponent(significand, exponent::Int32) significand = UInt64(significand) - while (significand & HiddenBit(Float64)) == 0 + while bitand(significand, HiddenBit(Float64)) == 0 significand <<= UInt64(1) exponent -= Int32(1) end @@ -43,7 +43,7 @@ function bignumdtoa(v,mode,requested_digits::Int,buffer,bignums) lower_boundary_is_closer = lowerboundaryiscloser(v) need_boundary_deltas = mode == SHORTEST - is_even = (significand & 1) == 0 + is_even = bitand(significand, 1) == 0 normalized_exponent = normalizedexponent(significand, exponent) estimated_power = estimatepower(Int(normalized_exponent)) diff --git a/base/grisu/bignums.jl b/base/grisu/bignums.jl index 114607e76eeb2..302a8d5e068a6 100644 --- a/base/grisu/bignums.jl +++ b/base/grisu/bignums.jl @@ -116,7 +116,7 @@ function bigitshiftleft!(x::Bignum,shift_amount) @inbounds begin for i = 1:x.used_digits new_carry::Chunk = x.bigits[i] >> (kBigitSize - shift_amount) - x.bigits[i] = ((x.bigits[i] << shift_amount) + carry) & kBigitMask + x.bigits[i] = bitand((x.bigits[i] << shift_amount) + carry, kBigitMask) carry = new_carry end if carry != 0 @@ -140,14 +140,14 @@ function subtracttimes!(x::Bignum,other::Bignum,factor) for i = 1:other.used_digits product::DoubleChunk = DoubleChunk(factor) * other.bigits[i] remove::DoubleChunk = borrow + product - difference::Chunk = (x.bigits[i+exponent_diff] - (remove & kBigitMask)) % Chunk - x.bigits[i+exponent_diff] = difference & kBigitMask + difference::Chunk = (x.bigits[i+exponent_diff] - bitand(remove, kBigitMask)) % Chunk + x.bigits[i+exponent_diff] = bitand(difference, kBigitMask) borrow = ((difference >> (kChunkSize - 1)) + (remove >> kBigitSize)) % Chunk end for i = (other.used_digits + exponent_diff + 1):x.used_digits borrow == 0 && return difference::Chunk = x.bigits[i] - borrow - x.bigits[i] = difference & kBigitMask + x.bigits[i] = bitand(difference, kBigitMask) borrow = difference >> (kChunkSize - 1) end end @@ -168,7 +168,7 @@ function assignuint64!(x::Bignum,value::UInt64) value == 0 && return needed_bigits = div(kUInt64Size,kBigitSize) + 1 @inbounds for i = 1:needed_bigits - x.bigits[i] = value & kBigitMask + x.bigits[i] = bitand(value, kBigitMask) value >>= kBigitSize end x.used_digits = needed_bigits @@ -202,13 +202,13 @@ function addbignum!(x::Bignum,other::Bignum) bigit_pos = other.exponent - x.exponent @inbounds for i = 1:other.used_digits sum::Chunk = x.bigits[bigit_pos+1] + other.bigits[i] + carry - x.bigits[bigit_pos+1] = sum & kBigitMask + x.bigits[bigit_pos+1] = bitand(sum, kBigitMask) carry = sum >> kBigitSize bigit_pos += 1 end @inbounds while carry != 0 sum = x.bigits[bigit_pos+1] + carry - x.bigits[bigit_pos+1] = sum & kBigitMask + x.bigits[bigit_pos+1] = bitand(sum, kBigitMask) carry = sum >> kBigitSize bigit_pos += 1 end @@ -223,13 +223,13 @@ function subtractbignum!(x::Bignum,other::Bignum) @inbounds begin for i = 1:other.used_digits difference = x.bigits[i+offset] - other.bigits[i] - borrow - x.bigits[i+offset] = difference & kBigitMask + x.bigits[i+offset] = bitand(difference, kBigitMask) borrow = difference >> (kChunkSize - 1) end i = other.used_digits+1 while borrow != 0 difference = x.bigits[i+offset] - borrow - x.bigits[i+offset] = difference & kBigitMask + x.bigits[i+offset] = bitand(difference, kBigitMask) borrow = difference >> (kChunkSize - 1) i += 1 end @@ -255,11 +255,11 @@ function multiplybyuint32!(x::Bignum,factor::UInt32) @inbounds begin for i = 1:x.used_digits product::DoubleChunk = (factor % DoubleChunk) * x.bigits[i] + carry - x.bigits[i] = (product & kBigitMask) % Chunk + x.bigits[i] = bitand(product, kBigitMask) % Chunk carry = product >> kBigitSize end while carry != 0 - x.bigits[x.used_digits+1] = carry & kBigitMask + x.bigits[x.used_digits+1] = bitand(carry, kBigitMask) x.used_digits += 1 carry >>= kBigitSize end @@ -274,19 +274,19 @@ function multiplybyuint64!(x::Bignum,factor::UInt64) return end carry::UInt64 = 0 - low::UInt64 = factor & 0xFFFFFFFF + low::UInt64 = bitand(factor, 0xFFFFFFFF) high::UInt64 = factor >> 32 @inbounds begin for i = 1:x.used_digits product_low::UInt64 = low * x.bigits[i] product_high::UInt64 = high * x.bigits[i] - tmp::UInt64 = (carry & kBigitMask) + product_low - x.bigits[i] = tmp & kBigitMask + tmp::UInt64 = bitand(carry, kBigitMask) + product_low + x.bigits[i] = bitand(tmp, kBigitMask) carry = (carry >> kBigitSize) + (tmp >> kBigitSize) + (product_high << (32 - kBigitSize)) end while carry != 0 - x.bigits[x.used_digits+1] = carry & kBigitMask + x.bigits[x.used_digits+1] = bitand(carry, kBigitMask) x.used_digits += 1 carry >>= kBigitSize end @@ -346,7 +346,7 @@ function square!(x::Bignum) bigit_index1 -= 1 bigit_index2 += 1 end - x.bigits[i] = (accumulator % Chunk) & kBigitMask + x.bigits[i] = bitand(accumulator % Chunk, kBigitMask) accumulator >>= kBigitSize end for i = x.used_digits+1:product_length @@ -359,7 +359,7 @@ function square!(x::Bignum) bigit_index1 -= 1 bigit_index2 += 1 end - x.bigits[i] = (accumulator % Chunk) & kBigitMask + x.bigits[i] = bitand(accumulator % Chunk, kBigitMask) accumulator >>= kBigitSize end end @@ -375,7 +375,7 @@ function assignpoweruint16!(x::Bignum,base::UInt16,power_exponent::Int) end zero!(x) shifts::Int = 0 - while base & UInt16(1) == UInt16(0) + while bitand(base, UInt16(1)) == UInt16(0) base >>= UInt16(1) shifts += 1 end @@ -396,9 +396,9 @@ function assignpoweruint16!(x::Bignum,base::UInt16,power_exponent::Int) max_32bits::UInt64 = 0xFFFFFFFF while mask != 0 && this_value <= max_32bits this_value *= this_value - if (power_exponent & mask) != 0 + if bitand(power_exponent, mask) != 0 base_bits_mask::UInt64 = bitnot(UInt64(1) << (64 - bit_size) - 1) - high_bits_zero = (this_value & base_bits_mask) == 0 + high_bits_zero = bitand(this_value, base_bits_mask) == 0 if high_bits_zero this_value *= base else @@ -411,7 +411,7 @@ function assignpoweruint16!(x::Bignum,base::UInt16,power_exponent::Int) delayed_multiplication && multiplybyuint32!(x,UInt32(base)) while mask != 0 square!(x) - (power_exponent & mask) != 0 && multiplybyuint32!(x,UInt32(base)) + bitand(power_exponent, mask) != 0 && multiplybyuint32!(x,UInt32(base)) mask >>= 1 end shiftleft!(x,shifts * power_exponent) diff --git a/base/grisu/fastfixed.jl b/base/grisu/fastfixed.jl index 014806b6531ea..de379c68e4ca4 100644 --- a/base/grisu/fastfixed.jl +++ b/base/grisu/fastfixed.jl @@ -118,7 +118,7 @@ function fillfractionals(fractionals, exponent, len += 1 fractionals -= UInt64(digit) << point end - if ((fractionals >> (point - 1)) & 1) == 1 + if bitand(fractionals >> (point - 1), 1) == 1 len, decimal_point = roundup(buffer, len, decimal_point) end else @@ -140,9 +140,9 @@ function fillfractionals(fractionals, exponent, return len, decimal_point end -low(x) = UInt64(x&0xffffffffffffffff) +low(x) = UInt64(bitand(x, 0xffffffffffffffff)) high(x) = UInt64(x >>> 64) -bitat(x::UInt128,y) = y >= 64 ? (Int32(high(x) >> (y-64)) & 1) : (Int32(low(x) >> y) & 1) +bitat(x::UInt128,y) = y >= 64 ? bitand(Int32(high(x) >> (y-64)), 1) : bitand(Int32(low(x) >> y), 1) function divrem2(x,power) h = high(x) l = low(x) diff --git a/base/grisu/fastprecision.jl b/base/grisu/fastprecision.jl index 3d737b1d13eb6..02e27f2c75cd3 100644 --- a/base/grisu/fastprecision.jl +++ b/base/grisu/fastprecision.jl @@ -52,7 +52,7 @@ function digitgen(w,buffer,requested_digits=1000) unit::UInt64 = 1 one = Float(unit << -w.e, w.e) integrals = w.s >> -one.e - fractionals = w.s & (one.s-1) + fractionals = bitand(w.s, one.s - 1) divisor, kappa = bigpowten(integrals, 64 + one.e) len = 1 rest = 0 @@ -78,7 +78,7 @@ function digitgen(w,buffer,requested_digits=1000) buffer[len] = 0x30 + digit len += 1 requested_digits -= 1 - fractionals &= one.s - 1 + fractionals = bitand(fractionals, one.s - 1) kappa -= 1 end requested_digits != 0 && return false, kappa, len diff --git a/base/grisu/fastshortest.jl b/base/grisu/fastshortest.jl index c7b70dea84acc..79ac828ac0401 100644 --- a/base/grisu/fastshortest.jl +++ b/base/grisu/fastshortest.jl @@ -67,7 +67,7 @@ function digitgen(low,w,high,buffer) too_high = Float(high.s+unit,high.e) unsafe_interval = too_high - Float(low.s-unit,low.e) integrals = too_high.s >> -one.e - fractionals = too_high.s & (one.s-1) + fractionals = bitand(too_high.s, one.s - 1) divisor, kappa = bigpowten(integrals, 64 + one.e) len = 1 rest = UInt64(0) @@ -92,7 +92,7 @@ function digitgen(low,w,high,buffer) digit = fractionals >> -one.e buffer[len] = 0x30 + digit len += 1 - fractionals &= one.s - 1 + fractionals = bitand(fractionals, one.s - 1) kappa -= 1 if fractionals < unsafe_interval.s r, kappa = roundweed(buffer,len,fractionals,one.s, diff --git a/base/grisu/float.jl b/base/grisu/float.jl index a92b94ccd4b51..fefed382c3d49 100644 --- a/base/grisu/float.jl +++ b/base/grisu/float.jl @@ -48,11 +48,11 @@ const FloatSignificandSize = Int32(64) function normalize(v::Float) f = v.s e::Int32 = v.e - while (f & Float10MSBits) == 0 + while bitand(f, Float10MSBits) == 0 f <<= 10 e -= 10 end - while (f & FloatSignMask) == 0 + while bitand(f, FloatSignMask) == 0 f <<= 1 e -= 1 end @@ -60,7 +60,7 @@ function normalize(v::Float) end function normalize(v::Float64) s = _significand(v); e = _exponent(v) - while (s & HiddenBit(Float64)) == 0 + while bitand(s, HiddenBit(Float64)) == 0 s <<= UInt64(1) e -= Int32(1) end @@ -108,14 +108,14 @@ uint_t(d::Float16) = reinterpret(UInt16,d) function _exponent(d::T) where T<:AbstractFloat isdenormal(d) && return DenormalExponent(T) - biased_e::Int32 = Int32((uint_t(d) & ExponentMask(T)) >> PhysicalSignificandSize(T)) + biased_e::Int32 = Int32(bitand(uint_t(d), ExponentMask(T)) >> PhysicalSignificandSize(T)) return Int32(biased_e - ExponentBias(T)) end function _significand(d::T) where T<:AbstractFloat - s = uint_t(d) & SignificandMask(T) + s = bitand(uint_t(d), SignificandMask(T)) return !isdenormal(d) ? s + HiddenBit(T) : s end -isdenormal(d::T) where {T<:AbstractFloat} = (uint_t(d) & ExponentMask(T)) == 0 +isdenormal(d::T) where {T<:AbstractFloat} = bitand(uint_t(d), ExponentMask(T)) == 0 function normalizedbound(f::AbstractFloat) v = Float(_significand(f),_exponent(f)) @@ -128,7 +128,7 @@ function normalizedbound(f::AbstractFloat) return Float(m_minus.s << (m_minus.e - m_plus.e), m_plus.e), m_plus end function lowerboundaryiscloser(f::T) where T<:AbstractFloat - physical_significand_is_zero = (uint_t(f) & SignificandMask(T)) == 0 + physical_significand_is_zero = bitand(uint_t(f), SignificandMask(T)) == 0 return physical_significand_is_zero && (_exponent(f) != DenormalExponent(T)) end @@ -138,14 +138,14 @@ const FloatM32 = 0xFFFFFFFF function (*)(this::Float,other::Float) a::UInt64 = this.s >> 32 - b::UInt64 = this.s & FloatM32 + b::UInt64 = bitand(this.s, FloatM32) c::UInt64 = other.s >> 32 - d::UInt64 = other.s & FloatM32 + d::UInt64 = bitand(other.s, FloatM32) ac::UInt64 = a * c bc::UInt64 = b * c ad::UInt64 = a * d bd::UInt64 = b * d - tmp::UInt64 = (bd >> 32) + (ad & FloatM32) + (bc & FloatM32) + tmp::UInt64 = (bd >> 32) + bitand(ad, FloatM32) + bitand(bc, FloatM32) # By adding 1U << 31 to tmp we round the final result. # Halfway cases will be round up. tmp += UInt64(1) << 31 diff --git a/base/hashing2.jl b/base/hashing2.jl index c333962999673..89a1b0775e58b 100644 --- a/base/hashing2.jl +++ b/base/hashing2.jl @@ -100,8 +100,8 @@ function decompose(x::Float16)::NTuple{3,Int} isnan(x) && return 0, 0, 0 isinf(x) && return ifelse(x < 0, -1, 1), 0, 0 n = reinterpret(UInt16, x) - s = (n & 0x03ff) % Int16 - e = (n & 0x7c00 >> 10) % Int + s = bitand(n, 0x03ff) % Int16 + e = bitand(n, 0x7c00 >> 10) % Int s = bitor(s, Int16(e != 0) << 10) d = ifelse(signbit(x), -1, 1) s, e - 25 + (e == 0), d @@ -111,8 +111,8 @@ function decompose(x::Float32)::NTuple{3,Int} isnan(x) && return 0, 0, 0 isinf(x) && return ifelse(x < 0, -1, 1), 0, 0 n = reinterpret(UInt32, x) - s = (n & 0x007fffff) % Int32 - e = (n & 0x7f800000 >> 23) % Int + s = bitand(n, 0x007fffff) % Int32 + e = bitand(n, 0x7f800000 >> 23) % Int s = bitor(s, Int32(e != 0) << 23) d = ifelse(signbit(x), -1, 1) s, e - 150 + (e == 0), d @@ -122,8 +122,8 @@ function decompose(x::Float64)::Tuple{Int64, Int, Int} isnan(x) && return 0, 0, 0 isinf(x) && return ifelse(x < 0, -1, 1), 0, 0 n = reinterpret(UInt64, x) - s = (n & 0x000fffffffffffff) % Int64 - e = (n & 0x7ff0000000000000 >> 52) % Int + s = bitand(n, 0x000fffffffffffff) % Int64 + e = bitand(n, 0x7ff0000000000000 >> 52) % Int s = bitor(s, Int64(e != 0) << 52) d = ifelse(signbit(x), -1, 1) s, e - 1075 + (e == 0), d diff --git a/base/inference.jl b/base/inference.jl index dfd647bff4caa..31586b5c0d0da 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -3610,7 +3610,7 @@ function optimize(me::InferenceState) end if proven_pure for fl in me.src.slotflags - if (fl & Slot_UsedUndef) != 0 + if bitand(fl, Slot_UsedUndef) != 0 proven_pure = false break end @@ -4111,7 +4111,7 @@ function effect_free(@nospecialize(e), src::CodeInfo, mod::Module, allow_volatil elseif isa(e, Symbol) return allow_volatile elseif isa(e, Slot) - return src.slotflags[slot_id(e)] & Slot_UsedUndef == 0 + return bitand(src.slotflags[slot_id(e)], Slot_UsedUndef) == 0 elseif isa(e, Expr) e = e::Expr head = e.head @@ -5573,7 +5573,7 @@ function find_sa_vars(src::CodeInfo, nargs::Int) # this transformation is not valid for vars used before def. # we need to preserve the point of assignment to know where to # throw errors (issue #4645). - if id > nargs && (src.slotflags[id] & Slot_UsedUndef == 0) + if id > nargs && bitand(src.slotflags[id], Slot_UsedUndef) == 0 if !haskey(av, lhs) av[lhs] = e.args[2] else @@ -5636,7 +5636,7 @@ function occurs_outside_getfield(@nospecialize(e), @nospecialize(sym), end else if (head === :block && isa(sym, Slot) && - sv.src.slotflags[slot_id(sym)] & Slot_UsedUndef == 0) + bitand(sv.src.slotflags[slot_id(sym)], Slot_UsedUndef) == 0) ignore_void = true else ignore_void = false @@ -5662,7 +5662,7 @@ function void_use_elim_pass!(sv::OptimizationState) # Explicitly listed here for clarity return false elseif isa(ex, Slot) - return sv.src.slotflags[slot_id(ex)] & Slot_UsedUndef != 0 + return bitand(sv.src.slotflags[slot_id(ex)], Slot_UsedUndef) != 0 elseif isa(ex, GlobalRef) ex = ex::GlobalRef return !isdefined(ex.mod, ex.name) @@ -5989,7 +5989,7 @@ function alloc_elim_pass!(sv::OptimizationState) rhs = e.args[2] # Need to make sure LLVM can recognize this as LLVM ssa value too is_ssa = (isa(var, SSAValue) || - sv.src.slotflags[slot_id(var)] & Slot_UsedUndef == 0) + bitand(sv.src.slotflags[slot_id(var)], Slot_UsedUndef) == 0) else var = nothing rhs = e diff --git a/base/int.jl b/base/int.jl index efea6b77b2fae..c460bb9df2ae4 100644 --- a/base/int.jl +++ b/base/int.jl @@ -465,7 +465,7 @@ for to in BitInteger_types, from in (BitInteger_types..., Bool) @eval rem(x::($from), ::Type{$to}) = trunc_int($to, x) elseif from === Bool # Bools use i8 storage and may have garbage in their 7 high bits - @eval convert(::Type{$to}, x::($from)) = zext_int($to, x) & $to(1) + @eval convert(::Type{$to}, x::($from)) = bitand(zext_int($to, x), $to(1)) @eval rem(x::($from), ::Type{$to}) = convert($to, x) elseif from.size < to.size if from <: Signed @@ -518,7 +518,7 @@ end rem(x::T, ::Type{T}) where {T<:Integer} = x rem(x::Integer, T::Type{<:Integer}) = convert(T, x) # `x % T` falls back to `convert` -rem(x::Integer, ::Type{Bool}) = ((x & 1) != 0) +rem(x::Integer, ::Type{Bool}) = !iszero(bitand(x, 1)) mod(x::Integer, ::Type{T}) where {T<:Integer} = rem(x, T) unsafe_trunc(::Type{T}, x::Integer) where {T<:Integer} = rem(x, T) @@ -693,14 +693,14 @@ if Core.sizeof(Int) == 4 local u0::UInt64, v0::UInt64, w0::UInt64 local u1::Int64, v1::Int64, w1::UInt64, w2::Int64, t::UInt64 - u0 = u & 0xffffffff; u1 = u >> 32 - v0 = v & 0xffffffff; v1 = v >> 32 + u0 = bitand(u, 0xffffffff); u1 = u >> 32 + v0 = bitand(v, 0xffffffff); v1 = v >> 32 w0 = u0 * v0 t = reinterpret(UInt64, u1) * v0 + (w0 >>> 32) w2 = reinterpret(Int64, t) >> 32 - w1 = u0 * reinterpret(UInt64, v1) + (t & 0xffffffff) + w1 = u0 * reinterpret(UInt64, v1) + bitand(t, 0xffffffff) hi = u1 * v1 + w2 + (reinterpret(Int64, w1) >> 32) - lo = w0 & 0xffffffff + (w1 << 32) + lo = bitand(w0, 0xffffffff) + (w1 << 32) return Int128(hi) << 64 + Int128(lo) end @@ -708,14 +708,14 @@ if Core.sizeof(Int) == 4 local u0::UInt64, v0::UInt64, w0::UInt64 local u1::UInt64, v1::UInt64, w1::UInt64, w2::UInt64, t::UInt64 - u0 = u & 0xffffffff; u1 = u >>> 32 - v0 = v & 0xffffffff; v1 = v >>> 32 + u0 = bitand(u, 0xffffffff); u1 = u >>> 32 + v0 = bitand(v, 0xffffffff); v1 = v >>> 32 w0 = u0 * v0 t = u1 * v0 + (w0 >>> 32) w2 = t >>> 32 - w1 = u0 * v1 + (t & 0xffffffff) + w1 = u0 * v1 + bitand(t, 0xffffffff) hi = u1 * v1 + w2 + (w1 >>> 32) - lo = w0 & 0xffffffff + (w1 << 32) + lo = bitand(w0, 0xffffffff) + (w1 << 32) return UInt128(hi) << 64 + UInt128(lo) end @@ -726,8 +726,8 @@ if Core.sizeof(Int) == 4 lohi = widemul(reinterpret(Int64, u0), v1) hilo = widemul(u1, reinterpret(Int64, v0)) t = reinterpret(UInt128, hilo) + (lolo >>> 64) - w1 = reinterpret(UInt128, lohi) + (t & 0xffffffffffffffff) - return Int128(lolo & 0xffffffffffffffff) + reinterpret(Int128, w1) << 64 + w1 = reinterpret(UInt128, lohi) + bitand(t, 0xffffffffffffffff) + return Int128(bitand(lolo, 0xffffffffffffffff)) + reinterpret(Int128, w1) << 64 end function *(u::UInt128, v::UInt128) @@ -737,8 +737,8 @@ if Core.sizeof(Int) == 4 lohi = widemul(u0, v1) hilo = widemul(u1, v0) t = hilo + (lolo >>> 64) - w1 = lohi + (t & 0xffffffffffffffff) - return (lolo & 0xffffffffffffffff) + UInt128(w1) << 64 + w1 = lohi + bitand(t, 0xffffffffffffffff) + return bitand(lolo, 0xffffffffffffffff) + UInt128(w1) << 64 end function div(x::Int128, y::Int128) diff --git a/base/intfuncs.jl b/base/intfuncs.jl index cffb2323a13dc..0632390f9f96c 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -558,7 +558,7 @@ function bin(x::Unsigned, pad::Int, neg::Bool) i = neg + max(pad,sizeof(x)<<3-leading_zeros(x)) a = StringVector(i) while i > neg - a[i] = '0'+(x&0x1) + a[i] = '0' + bitand(x, 0x1) x >>= 1 i -= 1 end @@ -570,7 +570,7 @@ function oct(x::Unsigned, pad::Int, neg::Bool) i = neg + max(pad,div((sizeof(x)<<3)-leading_zeros(x)+2,3)) a = StringVector(i) while i > neg - a[i] = '0'+(x&0x7) + a[i] = '0' + bitand(x, 0x7) x >>= 3 i -= 1 end @@ -594,7 +594,7 @@ function hex(x::Unsigned, pad::Int, neg::Bool) i = neg + max(pad,(sizeof(x)<<1)-(leading_zeros(x)>>2)) a = StringVector(i) while i > neg - d = x & 0xf + d = bitand(x, 0xf) a[i] = '0'+d+39*(d>9) x >>= 4 i -= 1 diff --git a/base/io.jl b/base/io.jl index 401ff76956456..7236919475d05 100644 --- a/base/io.jl +++ b/base/io.jl @@ -406,17 +406,17 @@ function write(s::IO, ch::Char) if c < 0x80 return write(s, c%UInt8) elseif c < 0x800 - return (write(s, bitor(c >> 6 , 0xC0) % UInt8)) + - (write(s, bitor(c & 0x3F, 0x80) % UInt8)) + return (write(s, bitor(c >> 6 , 0xC0) % UInt8)) + + (write(s, bitor(bitand(c, 0x3F), 0x80) % UInt8)) elseif c < 0x10000 - return (write(s, bitor(c >> 12 , 0xE0) % UInt8)) + - (write(s, bitor((c >> 6) & 0x3F, 0x80) % UInt8)) + - (write(s, bitor(c & 0x3F, 0x80) % UInt8)) + return (write(s, bitor(c >> 12 , 0xE0) % UInt8)) + + (write(s, bitor(bitand(c >> 6, 0x3F), 0x80) % UInt8)) + + (write(s, bitor(bitand(c, 0x3F) , 0x80) % UInt8)) elseif c < 0x110000 - return (write(s, bitor(c >> 18 , 0xF0) % UInt8)) + - (write(s, bitor((c >> 12) & 0x3F, 0x80) % UInt8)) + - (write(s, bitor((c >> 6) & 0x3F, 0x80) % UInt8)) + - (write(s, bitor(c & 0x3F, 0x80) % UInt8)) + return (write(s, bitor(c >> 18 , 0xF0) % UInt8)) + + (write(s, bitor(bitand(c >> 12, 0x3F), 0x80) % UInt8)) + + (write(s, bitor(bitand(c >> 6, 0x3F) , 0x80) % UInt8)) + + (write(s, bitor(bitand(c, 0x3F) , 0x80) % UInt8)) else return write(s, '\ufffd') end diff --git a/base/libgit2/callbacks.jl b/base/libgit2/callbacks.jl index e3c7e432096c7..258344b1ad2a7 100644 --- a/base/libgit2/callbacks.jl +++ b/base/libgit2/callbacks.jl @@ -287,11 +287,12 @@ function credentials_callback(libgit2credptr::Ptr{Ptr{Void}}, url_ptr::Cstring, p.credential = Nullable(deepcopy(cred)) if isa(cred, SSHCredentials) - allowed_types &= Cuint(Consts.CREDTYPE_SSH_KEY) + allowed_types = bitand(allowed_types, Cuint(Consts.CREDTYPE_SSH_KEY)) elseif isa(cred, UserPasswordCredentials) - allowed_types &= Cuint(Consts.CREDTYPE_USERPASS_PLAINTEXT) + allowed_types = bitand(allowed_types, Cuint(Consts.CREDTYPE_USERPASS_PLAINTEXT)) else - allowed_types &= Cuint(0) # Unhandled credential type + # just allowed_types = zero(allowed_types) ? + allowed_types = bitand(allowed_types, Cuint(0)) # Unhandled credential type end elseif !isnull(p.cache) cache = unsafe_get(p.cache) diff --git a/base/libgit2/utils.jl b/base/libgit2/utils.jl index 9dfec6316d89a..432de3e6a069e 100644 --- a/base/libgit2/utils.jl +++ b/base/libgit2/utils.jl @@ -44,14 +44,14 @@ const VERSION = version() Test whether the bits of `val` indexed by `flag` are set (`1`) or unset (`0`). """ -isset(val::Integer, flag::Integer) = (val & flag == flag) +isset(val::Integer, flag::Integer) = bitand(val, flag) == flag """ reset(val::Integer, flag::Integer) Unset the bits of `val` indexed by `flag`, returning them to `0`. """ -reset(val::Integer, flag::Integer) = (val &= bitnot(flag)) +reset(val::Integer, flag::Integer) = bitand(val, bitnot(flag)) """ toggle(val::Integer, flag::Integer) diff --git a/base/linalg/bitarray.jl b/base/linalg/bitarray.jl index dfa41f48f3677..e8f1fb35708a3 100644 --- a/base/linalg/bitarray.jl +++ b/base/linalg/bitarray.jl @@ -7,7 +7,7 @@ function dot(x::BitVector, y::BitVector) xc = x.chunks yc = y.chunks @inbounds for i = 1:length(xc) - s += count_ones(xc[i] & yc[i]) + s += count_ones(bitand(xc[i], yc[i])) end s end @@ -33,7 +33,7 @@ end #for j = 1:nB #for k = 1:col_ch ## TODO: improve - #C[i, j] += count_ones(aux_chunksA[k] & aux_chunksB[j][k]) + #C[i, j] += count_ones(bitand(aux_chunksA[k], aux_chunksB[j][k])) #end #end #end @@ -135,19 +135,19 @@ function nonzero_chunks(chunks::Vector{UInt64}, pos0::Int, pos1::Int) z = UInt64(0) u = bitnot(z) if delta_k == 0 - msk_0 = (u << l0) & bitnot(u << l1 << 1) + msk_0 = bitand(u << l0, bitnot(u << l1 << 1)) else msk_0 = (u << l0) msk_1 = bitnot(u << l1 << 1) end @inbounds begin - (chunks[k0] & msk_0) == z || return true + bitand(chunks[k0], msk_0) == z || return true delta_k == 0 && return false for i = k0 + 1 : k1 - 1 chunks[i] == z || return true end - (chunks[k1] & msk_1)==z || return true + bitand(chunks[k1], msk_1) == z || return true end return false end @@ -195,7 +195,7 @@ function findmin(a::BitArray) k == 64 || return (false, ti) end l = Base._mod64(length(a)-1) + 1 - @inbounds k = trailing_ones(ac[end] & Base._msk_end(l)) + @inbounds k = trailing_ones(bitand(ac[end], Base._msk_end(l))) ti += k k == l || return (false, ti) return m, mi @@ -205,11 +205,11 @@ end # http://www.hackersdelight.org/hdcodetxt/transpose8.c.txt function transpose8x8(x::UInt64) y = x - t = xor(y, y >>> 7) & 0x00aa00aa00aa00aa + t = bitand(xor(y, y >>> 7), 0x00aa00aa00aa00aa) y = xor(y, t, t << 7) - t = xor(y, y >>> 14) & 0x0000cccc0000cccc + t = bitand(xor(y, y >>> 14), 0x0000cccc0000cccc) y = xor(y, t, t << 14) - t = xor(y, y >>> 28) & 0x00000000f0f0f0f0 + t = bitand(xor(y, y >>> 28), 0x00000000f0f0f0f0) return xor(y, t, t << 28) end @@ -220,10 +220,10 @@ function form_8x8_chunk(Bc::Vector{UInt64}, i1::Int, i2::Int, m::Int, cgap::Int, r = 0 for j = 1:8 k > nc && break - x = bitor(x, ((Bc[k] >>> l) & msk8) << r) + x = bitor(x, bitand(Bc[k] >>> l, msk8) << r) if l + 8 >= 64 && nc > k r0 = 8 - Base._mod64(l + 8) - x = bitor(x, (Bc[k + 1] & (msk8 >>> r0)) << (r + r0)) + x = bitor(x, bitand(Bc[k + 1], msk8 >>> r0) << (r + r0)) end k += cgap + (l + cinc >= 64 ? 1 : 0) l = Base._mod64(l + cinc) @@ -238,10 +238,10 @@ function put_8x8_chunk(Bc::Vector{UInt64}, i1::Int, i2::Int, x::UInt64, m::Int, r = 0 for j = 1:8 k > nc && break - Bc[k] = bitor(Bc[k], ((x >>> r) & msk8) << l) + Bc[k] = bitor(Bc[k], bitand(x >>> r, msk8) << l) if l + 8 >= 64 && nc > k r0 = 8 - Base._mod64(l + 8) - Bc[k + 1] = bitor(Bc[k + 1], (x >>> (r + r0)) & (msk8 >>> r0)) + Bc[k + 1] = bitor(Bc[k + 1], bitand(x >>> (r + r0), msk8 >>> r0)) end k += cgap + (l + cinc >= 64 ? 1 : 0) l = Base._mod64(l + cinc) diff --git a/base/math.jl b/base/math.jl index 6ebc9276e7afd..1e0280ef2d6c4 100644 --- a/base/math.jl +++ b/base/math.jl @@ -542,14 +542,14 @@ julia> ldexp(5., 2) """ function ldexp(x::T, e::Integer) where T<:IEEEFloat xu = reinterpret(Unsigned, x) - xs = xu & bitnot(sign_mask(T)) + xs = bitand(xu, bitnot(sign_mask(T))) xs >= exponent_mask(T) && return x # NaN or Inf k = Int(xs >> significand_bits(T)) if k == 0 # x is subnormal xs == 0 && return x # +-0 m = leading_zeros(xs) - exponent_bits(T) ys = xs << unsigned(m) - xu = bitor(ys, xu & sign_mask(T)) + xu = bitor(ys, bitand(xu, sign_mask(T))) k = 1 - m # underflow, otherwise may have integer underflow in the following n + k e < -50000 && return flipsign(T(0.0), x) @@ -568,7 +568,7 @@ function ldexp(x::T, e::Integer) where T<:IEEEFloat return flipsign(T(Inf), x) end if k > 0 # normal case - xu = bitor(xu & bitnot(exponent_mask(T)), rem(k, uinttype(T)) << significand_bits(T)) + xu = bitor(bitand(xu, bitnot(exponent_mask(T))), rem(k, uinttype(T)) << significand_bits(T)) return reinterpret(T, xu) else # subnormal case if k <= -significand_bits(T) # underflow @@ -578,7 +578,7 @@ function ldexp(x::T, e::Integer) where T<:IEEEFloat end k += significand_bits(T) z = T(2.0)^-significand_bits(T) - xu = bitor(xu & bitnot(exponent_mask(T)), rem(k, uinttype(T)) << significand_bits(T)) + xu = bitor(bitand(xu, bitnot(exponent_mask(T))), rem(k, uinttype(T)) << significand_bits(T)) return z*reinterpret(T, xu) end end @@ -592,7 +592,7 @@ Get the exponent of a normalized floating-point number. function exponent(x::T) where T<:IEEEFloat @noinline throw1(x) = throw(DomainError(x, "Cannot be NaN or Inf.")) @noinline throw2(x) = throw(DomainError(x, "Cannot be subnormal converted to 0.")) - xs = reinterpret(Unsigned, x) & bitnot(sign_mask(T)) + xs = bitand(reinterpret(Unsigned, x), bitnot(sign_mask(T))) xs >= exponent_mask(T) && throw1(x) k = Int(xs >> significand_bits(T)) if k == 0 # x is subnormal @@ -621,15 +621,15 @@ julia> significand(15.2)*8 """ function significand(x::T) where T<:IEEEFloat xu = reinterpret(Unsigned, x) - xs = xu & bitnot(sign_mask(T)) + xs = bitand(xu, bitnot(sign_mask(T))) xs >= exponent_mask(T) && return x # NaN or Inf - if xs <= (bitnot(exponent_mask(T)) & bitnot(sign_mask(T))) # x is subnormal + if xs <= bitand(bitnot(exponent_mask(T)), bitnot(sign_mask(T))) # x is subnormal xs == 0 && return x # +-0 m = unsigned(leading_zeros(xs) - exponent_bits(T)) xs <<= m - xu = bitor(xs, xu & sign_mask(T)) + xu = bitor(xs, bitand(xu, sign_mask(T))) end - xu = bitor(xu & bitnot(exponent_mask(T)), exponent_one(T)) + xu = bitor(bitand(xu, bitnot(exponent_mask(T))), exponent_one(T)) return reinterpret(T, xu) end @@ -641,18 +641,18 @@ and `val` is equal to ``x \\times 2^{exp}``. """ function frexp(x::T) where T<:IEEEFloat xu = reinterpret(Unsigned, x) - xs = xu & bitnot(sign_mask(T)) + xs = bitand(xu, bitnot(sign_mask(T))) xs >= exponent_mask(T) && return x, 0 # NaN or Inf k = Int(xs >> significand_bits(T)) if k == 0 # x is subnormal xs == 0 && return x, 0 # +-0 m = leading_zeros(xs) - exponent_bits(T) xs <<= unsigned(m) - xu = bitor(xs, xu & sign_mask(T)) + xu = bitor(xs, bitand(xu, sign_mask(T))) k = 1 - m end k -= (exponent_bias(T) - 1) - xu = bitor(xu & bitnot(exponent_mask(T)), exponent_half(T)) + xu = bitor(bitand(xu, bitnot(exponent_mask(T))), exponent_half(T)) return reinterpret(T, xu), k end @@ -813,7 +813,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Nearest}) n,y = rem_pio2_kernel(x) if iseven(n) - if n & 2 == 2 # n % 4 == 2: add/subtract pi + if bitand(n, 2) == 2 # n % 4 == 2: add/subtract pi if y.hi <= 0 return add22condh(y.hi,y.lo,pi2o2_h,pi2o2_l) else @@ -823,7 +823,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Nearest}) return y.hi+y.lo end else - if n & 2 == 2 # n % 4 == 3: subtract pi/2 + if bitand(n, 2) == 2 # n % 4 == 3: subtract pi/2 return add22condh(y.hi,y.lo,-pi1o2_h,-pi1o2_l) else # n % 4 == 1: add pi/2 return add22condh(y.hi,y.lo,pi1o2_h,pi1o2_l) @@ -837,7 +837,7 @@ function rem2pi(x::Float64, ::RoundingMode{:ToZero}) n,y = rem_pio2_kernel(x) if iseven(n) - if n & 2 == 2 # n % 4 == 2: add pi + if bitand(n, 2) == 2 # n % 4 == 2: add pi z = add22condh(y.hi,y.lo,pi2o2_h,pi2o2_l) else # n % 4 == 0: add 0 or 2pi if y.hi > 0 @@ -847,7 +847,7 @@ function rem2pi(x::Float64, ::RoundingMode{:ToZero}) end end else - if n & 2 == 2 # n % 4 == 3: add 3pi/2 + if bitand(n, 2) == 2 # n % 4 == 3: add 3pi/2 z = add22condh(y.hi,y.lo,pi3o2_h,pi3o2_l) else # n % 4 == 1: add pi/2 z = add22condh(y.hi,y.lo,pi1o2_h,pi1o2_l) @@ -867,7 +867,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Down}) n,y = rem_pio2_kernel(x) if iseven(n) - if n & 2 == 2 # n % 4 == 2: add pi + if bitand(n, 2) == 2 # n % 4 == 2: add pi return add22condh(y.hi,y.lo,pi2o2_h,pi2o2_l) else # n % 4 == 0: add 0 or 2pi if y.hi > 0 @@ -877,7 +877,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Down}) end end else - if n & 2 == 2 # n % 4 == 3: add 3pi/2 + if bitand(n, 2) == 2 # n % 4 == 3: add 3pi/2 return add22condh(y.hi,y.lo,pi3o2_h,pi3o2_l) else # n % 4 == 1: add pi/2 return add22condh(y.hi,y.lo,pi1o2_h,pi1o2_l) @@ -896,7 +896,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Up}) n,y = rem_pio2_kernel(x) if iseven(n) - if n & 2 == 2 # n % 4 == 2: sub pi + if bitand(n, 2) == 2 # n % 4 == 2: sub pi return add22condh(y.hi,y.lo,-pi2o2_h,-pi2o2_l) else # n % 4 == 0: sub 0 or 2pi if y.hi < 0 @@ -906,7 +906,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Up}) end end else - if n & 2 == 2 # n % 4 == 3: sub pi/2 + if bitand(n, 2) == 2 # n % 4 == 3: sub pi/2 return add22condh(y.hi,y.lo,-pi1o2_h,-pi1o2_l) else # n % 4 == 1: sub 3pi/2 return add22condh(y.hi,y.lo,-pi3o2_h,-pi3o2_l) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index 7866ab87d1da0..f2c6f2578b45b 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -487,7 +487,7 @@ done(L::LogicalIndex, s) = s[3] > length(L) i, n = s Bc = L.mask.chunks while true - if Bc[_div64(i)+1] & (UInt64(1)<<_mod64(i)) != 0 + if bitand(Bc[_div64(i)+1], UInt64(1) << _mod64(i)) != 0 i += 1 return (i, (i, n+1)) end @@ -1215,7 +1215,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra c = bitor(c, UInt64(unchecked_bool_convert(C[ind])) << j) ind += 1 end - Bc[kd0] = bitor(Bc[kd0] & msk_d0, c & bitnot(msk_d0)) + Bc[kd0] = bitor(bitand(Bc[kd0], msk_d0), bitand(c, bitnot(msk_d0))) bind += 1 end @@ -1237,7 +1237,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra c = bitor(c, UInt64(unchecked_bool_convert(C[ind])) << j) ind += 1 end - Bc[kd1] = bitor(Bc[kd1] & msk_d1, c & bitnot(msk_d1)) + Bc[kd1] = bitor(bitand(Bc[kd1], msk_d1), bitand(c, bitnot(msk_d1))) end end diff --git a/base/nullable.jl b/base/nullable.jl index 38f29fa144b33..6819027d8a83a 100644 --- a/base/nullable.jl +++ b/base/nullable.jl @@ -402,7 +402,7 @@ null_safe_op(::typeof(!), ::Type{Bool}) = true # Note this list does not include ^, ÷ and % # Operations between signed and unsigned types are not safe: promotion to unsigned # gives an InexactError for negative numbers -for op in (+, -, *, /, &, bitor, <<, >>, >>>, +for op in (+, -, *, /, bitand, bitor, <<, >>, >>>, scalarmin, scalarmax) # to fix ambiguities global null_safe_op diff --git a/base/printf.jl b/base/printf.jl index c6e121405f02f..5eea89225e6f4 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -828,7 +828,7 @@ function decode_oct(d::Integer) @handle_zero x pt = i = div((sizeof(x)<<3)-leading_zeros(x)+2,3) while i > 0 - DIGITS[i] = '0'+(x&0x7) + DIGITS[i] = '0' + bitand(x, 0x7) x >>= 3 i -= 1 end @@ -840,7 +840,7 @@ function decode_0ct(d::Integer) # doesn't need special handling for zero pt = i = div((sizeof(x)<<3)-leading_zeros(x)+5,3) while i > 0 - DIGITS[i] = '0'+(x&0x7) + DIGITS[i] = '0' + bitand(x, 0x7) x >>= 3 i -= 1 end @@ -864,7 +864,7 @@ function decode_hex(d::Integer, symbols::Array{UInt8,1}) @handle_zero x pt = i = (sizeof(x)<<1)-(leading_zeros(x)>>2) while i > 0 - DIGITS[i] = symbols[(x&0xf)+1] + DIGITS[i] = symbols[bitand(x, 0xf) + 1] x >>= 4 i -= 1 end @@ -1046,13 +1046,13 @@ function ini_hex(x::SmallFloatingPoint, n::Int, symbols::Array{UInt8,1}) sigbits = 4*min(n-1,13) s = 0.25*round(ldexp(s,1+sigbits)) # ensure last 2 exponent bits either 01 or 10 - u = (reinterpret(UInt64,s) & 0x003f_ffff_ffff_ffff) >> (52-sigbits) + u = bitand(reinterpret(UInt64,s), 0x003f_ffff_ffff_ffff) >> (52-sigbits) if n > 14 ccall(:memset, Ptr{Void}, (Ptr{Void}, Cint, Csize_t), DIGITS, '0', n) end i = (sizeof(u)<<1)-(leading_zeros(u)>>2) while i > 0 - DIGITS[i] = symbols[(u&0xf)+1] + DIGITS[i] = symbols[bitand(u, 0xf) + 1] u >>= 4 i -= 1 end @@ -1069,12 +1069,12 @@ function ini_hex(x::SmallFloatingPoint, symbols::Array{UInt8,1}) else s, p = frexp(x) s *= 2.0 - u = (reinterpret(UInt64,s) & 0x001f_ffff_ffff_ffff) + u = bitand(reinterpret(UInt64,s), 0x001f_ffff_ffff_ffff) t = (trailing_zeros(u) >> 2) u >>= (t<<2) n = 14-t for i = n:-1:1 - DIGITS[i] = symbols[(u&0xf)+1] + DIGITS[i] = symbols[bitand(u, 0xf) + 1] u >>= 4 end # pt is the binary exponent diff --git a/base/process.jl b/base/process.jl index c2bc8726e4c89..58d9a176507ab 100644 --- a/base/process.jl +++ b/base/process.jl @@ -19,9 +19,9 @@ struct Cmd <: AbstractCmd new(cmd.exec, ignorestatus, flags, env, dir === cmd.dir ? dir : cstr(dir)) function Cmd(cmd::Cmd; ignorestatus::Bool=cmd.ignorestatus, env=cmd.env, dir::AbstractString=cmd.dir, - detach::Bool = 0 != cmd.flags & UV_PROCESS_DETACHED, - windows_verbatim::Bool = 0 != cmd.flags & UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS, - windows_hide::Bool = 0 != cmd.flags & UV_PROCESS_WINDOWS_HIDE) + detach::Bool = !iszero(bitand(cmd.flags, UV_PROCESS_DETACHED)), + windows_verbatim::Bool = !iszero(bitand(cmd.flags, UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS)), + windows_hide::Bool = !iszero(bitand(cmd.flags, UV_PROCESS_WINDOWS_HIDE))) flags = bitor(detach * UV_PROCESS_DETACHED, windows_hide * UV_PROCESS_WINDOWS_HIDE, windows_verbatim * UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS) diff --git a/base/random/RNGs.jl b/base/random/RNGs.jl index cd1064cbf9433..1f830f0f5e696 100644 --- a/base/random/RNGs.jl +++ b/base/random/RNGs.jl @@ -173,7 +173,7 @@ function make_seed(n::Integer) n < 0 && throw(DomainError(n, "`n` must be non-negative.")) seed = UInt32[] while true - push!(seed, n & 0xffffffff) + push!(seed, bitand(n, 0xffffffff)) n >>= 32 if n == 0 return seed @@ -318,10 +318,10 @@ function rand!(r::MersenneTwister, A::Array{Float64}, n::Int=length(A), end mask128(u::UInt128, ::Type{Float16}) = - bitor(u & 0x03ff03ff03ff03ff03ff03ff03ff03ff, 0x3c003c003c003c003c003c003c003c00) + bitor(bitand(u, 0x03ff03ff03ff03ff03ff03ff03ff03ff), 0x3c003c003c003c003c003c003c003c00) mask128(u::UInt128, ::Type{Float32}) = - bitor(u & 0x007fffff007fffff007fffff007fffff, 0x3f8000003f8000003f8000003f800000) + bitor(bitand(u, 0x007fffff007fffff007fffff007fffff), 0x3f8000003f8000003f8000003f800000) function rand!(r::MersenneTwister, A::Union{Array{Float16},Array{Float32}}, ::Close1Open2_64) @@ -413,7 +413,7 @@ end function rand_lteq(r::AbstractRNG, randfun, u::U, mask::U) where U<:Integer while true - x = randfun(r) & mask + x = bitand(randfun(r), mask) x <= u && return x end end diff --git a/base/random/dSFMT.jl b/base/random/dSFMT.jl index d4ae974dbe9fc..977db0d42b7b5 100644 --- a/base/random/dSFMT.jl +++ b/base/random/dSFMT.jl @@ -114,7 +114,7 @@ function dsfmt_jump(s::DSFMT_state, jp::AbstractString) for c in jp bits = parse(UInt8,c,16) for j in 1:4 - (bits & 0x01) != 0x00 && dsfmt_jump_add!(rwork, dsfmt) + bitand(bits, 0x01) != 0x00 && dsfmt_jump_add!(rwork, dsfmt) bits = bits >> 0x01 dsfmt_jump_next_state!(dsfmt) end @@ -167,8 +167,8 @@ function dsfmt_jump_next_state!(mts::Vector{UInt64}) L1 = mts[u+1] mts[u] = xor(t0 << SL1, L1 >> 32, L1 << 32, mts[b]) mts[u+1] = xor(t1 << SL1, L0 >> 32, L0 << 32, mts[b+1]) - mts[a] = xor(mts[u] >> SR, mts[u] & MSK1, t0) - mts[a+1] = xor(mts[u+1] >> SR, mts[u+1] & MSK2, t1) + mts[a] = xor(mts[u] >> SR, bitand(mts[u], MSK1), t0) + mts[a+1] = xor(mts[u+1] >> SR, bitand(mts[u+1], MSK2), t1) mts[end] = (mts[end] + 2) % (N*2) return mts diff --git a/base/random/generation.jl b/base/random/generation.jl index f13682e9d20bc..9695bb549a59b 100644 --- a/base/random/generation.jl +++ b/base/random/generation.jl @@ -19,13 +19,13 @@ rand(r::AbstractRNG=GLOBAL_RNG, ::Type{T}=Float64) where {T<:AbstractFloat} = rand_generic(r::AbstractRNG, ::CloseOpen{Float16}) = Float16(reinterpret(Float32, - bitor((rand_ui10_raw(r) % UInt32 << 13) & 0x007fe000, 0x3f800000) - 1) + bitor(bitand(rand_ui10_raw(r) % UInt32 << 13, 0x007fe000), 0x3f800000) - 1) rand_generic(r::AbstractRNG, ::CloseOpen{Float32}) = - reinterpret(Float32, bitor(rand_ui23_raw(r) % UInt32 & 0x007fffff, 0x3f800000) - 1 + reinterpret(Float32, bitor(bitand(rand_ui23_raw(r) % UInt32, 0x007fffff), 0x3f800000) - 1 rand_generic(r::AbstractRNG, ::Close1Open2_64) = - reinterpret(Float64, bitor(0x3ff0000000000000, rand(r, UInt64) & 0x000fffffffffffff)) + reinterpret(Float64, bitor(0x3ff0000000000000, bitand(rand(r, UInt64), 0x000fffffffffffff))) rand_generic(r::AbstractRNG, ::CloseOpen_64) = rand(r, Close1Open2()) - 1.0 @@ -54,7 +54,7 @@ function _rand(rng::AbstractRNG, gen::BigFloatRandGenerator) rand!(rng, limbs) @inbounds begin limbs[1] <<= gen.shift - randbool = iszero(limbs[end] & Limb_high_bit) + randbool = iszero(bitand(limbs[end], Limb_high_bit)) limbs[end] = bitor(limbs[end], Limb_high_bit) end z.sign = 1 @@ -96,7 +96,7 @@ rand_ui10_raw(r::AbstractRNG) = rand(r, UInt16) rand_ui23_raw(r::AbstractRNG) = rand(r, UInt32) rand_ui52_raw(r::AbstractRNG) = reinterpret(UInt64, rand(r, Close1Open2())) -rand_ui52(r::AbstractRNG) = rand_ui52_raw(r) & 0x000fffffffffffff +rand_ui52(r::AbstractRNG) = bitand(rand_ui52_raw(r), 0x000fffffffffffff) ### random complex numbers @@ -271,7 +271,7 @@ function rand(rng::AbstractRNG, g::RangeGeneratorBigInt) limbs = unsafe_wrap(Array, x.d, g.nlimbs) while true rand!(rng, limbs) - @inbounds limbs[end] &= g.mask + @inbounds limbs[end] = bitand(limbs[end], g.mask) MPZ.mpn_cmp(x, g.m, g.nlimbs) <= 0 && break end # adjust x.size (normally done by mpz_limbs_finish, in GMP version >= 6) diff --git a/base/random/misc.jl b/base/random/misc.jl index a42bf308173ff..e203352db4ff1 100644 --- a/base/random/misc.jl +++ b/base/random/misc.jl @@ -6,7 +6,7 @@ function rand!(rng::AbstractRNG, B::BitArray) isempty(B) && return B Bc = B.chunks rand!(rng, Bc) - Bc[end] &= Base._msk_end(B) + Bc[end] = bitand(Bc[end], Base._msk_end(B)) return B end @@ -148,7 +148,7 @@ randsubseq(A::AbstractArray, p::Real) = randsubseq(GLOBAL_RNG, A, p) # this duplicates the functionality of RangeGenerator objects, # to optimize this special case while true - x = (rand_ui52_raw(r) % Int) & mask + x = bitand(rand_ui52_raw(r) % Int, mask) x < n && return x end end @@ -378,7 +378,7 @@ function uuid1(rng::AbstractRNG=GLOBAL_RNG) u = rand(rng, UInt128) # mask off clock sequence and node - u &= 0x00000000000000003fffffffffffffff + u = bitand(u, 0x00000000000000003fffffffffffffff) # set the unicast/multicast bit and version u = bitor(u, 0x00000000000010000000010000000000) @@ -386,9 +386,9 @@ function uuid1(rng::AbstractRNG=GLOBAL_RNG) # 0x01b21dd213814000 is the number of 100 nanosecond intervals # between the UUID epoch and Unix epoch timestamp = round(UInt64, time() * 1e7) + 0x01b21dd213814000 - ts_low = timestamp & typemax(UInt32) - ts_mid = (timestamp >> 32) & typemax(UInt16) - ts_hi = (timestamp >> 48) & 0x0fff + ts_low = bitand(timestamp, typemax(UInt32)) + ts_mid = bitand(timestamp >> 32, typemax(UInt16)) + ts_hi = bitand(timestamp >> 48, 0x0fff) u = bitor(u, UInt128(ts_low) << 96) u = bitor(u, UInt128(ts_mid) << 80) @@ -413,7 +413,7 @@ julia> Base.Random.uuid4(rng) """ function uuid4(rng::AbstractRNG=GLOBAL_RNG) u = rand(rng, UInt128) - u &= 0xffffffffffff0fff3fffffffffffffff + u = bitand(u, 0xffffffffffff0fff3fffffffffffffff) u = bitor(u, 0x00000000000040008000000000000000) UUID(u) end @@ -431,7 +431,7 @@ julia> Base.Random.uuid_version(Base.Random.uuid4(rng)) 4 ``` """ -uuid_version(u::UUID) = Int((u.value >> 76) & 0xf) +uuid_version(u::UUID) = Int(bitand(u.value >> 76, 0xf)) Base.convert(::Type{UInt128}, u::UUID) = u.value @@ -447,7 +447,7 @@ let groupings = [1:8; 10:13; 15:18; 20:23; 25:36] for i in groupings u <<= 4 d = s[i] - '0' - u = bitor(u, 0xf & (d - 39*(d > 9))) + u = bitor(u, bitand(0xf, d - 39*(d > 9))) end return UUID(u) end @@ -458,7 +458,7 @@ let groupings = [36:-1:25; 23:-1:20; 18:-1:15; 13:-1:10; 8:-1:1] u = u.value a = Base.StringVector(36) for i in groupings - d = u & 0xf + d = bitand(u, 0xf) a[i] = '0' + d + 39*(d > 9) u >>= 4 end diff --git a/base/random/normal.jl b/base/random/normal.jl index 8f816867afbd7..6a38ec00aed6f 100644 --- a/base/random/normal.jl +++ b/base/random/normal.jl @@ -37,7 +37,7 @@ julia> randn(rng, Complex64, (2, 3)) @inbounds begin r = rand_ui52(rng) rabs = Int64(r>>1) # One bit for the sign - idx = rabs & 0xFF + idx = bitand(rabs, 0xFF) x = ifelse(r % Bool, -rabs, rabs)*wi[idx+1] rabs < ki[idx+1] && return x # 99.3% of the time we return here 1st try return randn_unlikely(rng, idx, rabs, x) @@ -96,7 +96,7 @@ julia> randexp(rng, 3, 3) function randexp(rng::AbstractRNG=GLOBAL_RNG) @inbounds begin ri = rand_ui52(rng) - idx = ri & 0xFF + idx = bitand(ri, 0xFF) x = ri*we[idx+1] ri < ke[idx+1] && return x # 98.9% of the time we return here 1st try return randexp_unlikely(rng, idx, x) diff --git a/base/reflection.jl b/base/reflection.jl index 63165a62226db..4d33992e138bb 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -248,16 +248,16 @@ end # type predicates datatype_alignment(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefError()) : - Int(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment & 0x1FF) + Int(bitand(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment, 0x1FF)) datatype_haspadding(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefError()) : - (unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 9) & 1 == 1 + bitand(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 9, 1) == 1 datatype_pointerfree(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefError()) : - (unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 10) & 0xFFFFF == 0 + bitand(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 10, 0xFFFFF) == 0 datatype_fielddesc_type(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefError()) : - (unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 30) & 3 + bitand(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 30, 3) """ isimmutable(v) diff --git a/base/regex.jl b/base/regex.jl index 898855ccf110e..7d00e8e02c80f 100644 --- a/base/regex.jl +++ b/base/regex.jl @@ -21,10 +21,10 @@ mutable struct Regex pattern = String(pattern) compile_options = UInt32(compile_options) match_options = UInt32(match_options) - if (compile_options & bitnot(PCRE.COMPILE_MASK)) != 0 + if bitand(compile_options, bitnot(PCRE.COMPILE_MASK)) != 0 throw(ArgumentError("invalid regex compile options: $compile_options")) end - if (match_options & bitnot(PCRE.EXECUTE_MASK)) !=0 + if bitand(match_options, bitnot(PCRE.EXECUTE_MASK)) !=0 throw(ArgumentError("invalid regex match options: $match_options")) end re = compile(new(pattern, compile_options, match_options, C_NULL, @@ -86,13 +86,13 @@ macro r_str(pattern, flags...) Regex(pattern, flags...) end function show(io::IO, re::Regex) imsx = bitor(PCRE.CASELESS, PCRE.MULTILINE, PCRE.DOTALL, PCRE.EXTENDED) opts = re.compile_options - if (opts & bitnot(imsx)) == DEFAULT_COMPILER_OPTS + if bitand(opts, bitnot(imsx)) == DEFAULT_COMPILER_OPTS print(io, 'r') print_quoted_literal(io, re.pattern) - if (opts & PCRE.CASELESS ) != 0; print(io, 'i'); end - if (opts & PCRE.MULTILINE) != 0; print(io, 'm'); end - if (opts & PCRE.DOTALL ) != 0; print(io, 's'); end - if (opts & PCRE.EXTENDED ) != 0; print(io, 'x'); end + if bitand(opts, PCRE.CASELESS ) != 0; print(io, 'i'); end + if bitand(opts, PCRE.MULTILINE) != 0; print(io, 'm'); end + if bitand(opts, PCRE.DOTALL ) != 0; print(io, 's'); end + if bitand(opts, PCRE.EXTENDED ) != 0; print(io, 'x'); end else print(io, "Regex(") show(io, re.pattern) diff --git a/base/repl/LineEdit.jl b/base/repl/LineEdit.jl index 43e5b494ce77e..463b867ee3002 100644 --- a/base/repl/LineEdit.jl +++ b/base/repl/LineEdit.jl @@ -395,7 +395,7 @@ function char_move_left(buf::IOBuffer) while position(buf) > 0 seek(buf, position(buf)-1) c = peek(buf) - (((c & 0x80) == 0) || ((c & 0xc0) == 0xc0)) && break + bitand(c, 0x80) == 0 || bitand(c, 0xc0) == 0xc0 && break end pos = position(buf) c = read(buf, Char) diff --git a/base/serialize.jl b/base/serialize.jl index 39f85df757a0d..b72ba13662bbe 100644 --- a/base/serialize.jl +++ b/base/serialize.jl @@ -942,7 +942,7 @@ function deserialize_array(s::AbstractSerializer) while i <= n b = read(s.io, UInt8)::UInt8 v = (b >> 7) != 0 - count = b & 0x7f + count = bitand(b, 0x7f) nxt = i + count while i < nxt A[i] = v diff --git a/base/show.jl b/base/show.jl index 1f6fd407b3a9f..b5ba1a2192269 100644 --- a/base/show.jl +++ b/base/show.jl @@ -2147,9 +2147,9 @@ end function print_bit_chunk(io::IO, c::UInt64, l::Integer = 64) for s = 0:l-1 - d = (c >>> s) & 1 + d = bitand(c >>> s, 1) print(io, "01"[d + 1]) - if (s + 1) & 7 == 0 + if bitand(s + 1, 7) == 0 print(io, " ") end end diff --git a/base/socket.jl b/base/socket.jl index bd8a8bd4a2372..7657837d79d06 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -43,10 +43,10 @@ end IPv4(str::AbstractString) = parse(IPv4, str) show(io::IO,ip::IPv4) = print(io,"ip\"",ip,"\"") -print(io::IO,ip::IPv4) = print(io,dec((ip.host&(0xFF000000))>>24),".", - dec((ip.host&(0xFF0000))>>16),".", - dec((ip.host&(0xFF00))>>8),".", - dec(ip.host&0xFF)) +print(io::IO,ip::IPv4) = print(io, dec(bitand(ip.host, 0xFF000000) >> 24), ".", + dec(bitand(ip.host, 0xFF0000) >> 16), ".", + dec(bitand(ip.host, 0xFF00) >> 8), ".", + dec(bitand(ip.host, 0xFF))) struct IPv6 <: IPAddr host::UInt128 @@ -102,7 +102,7 @@ function ipv6_field(ip::IPv6,i) if i < 0 || i > 7 throw(BoundsError()) end - UInt16(ip.host&(UInt128(0xFFFF)<<(i*16))>>(i*16)) + UInt16(bitand(ip.host, UInt128(0xFFFF) << (i*16)) >> (i*16)) end show(io::IO, ip::IPv6) = print(io,"ip\"",ip,"\"") @@ -523,7 +523,7 @@ function uv_recvcb(handle::Ptr{Void}, nread::Cssize_t, buf::Ptr{Void}, addr::Ptr if nread < 0 Libc.free(buf_addr) notify_error(sock.recvnotify, UVError("recv", nread)) - elseif flags & UV_UDP_PARTIAL > 0 + elseif bitand(flags, UV_UDP_PARTIAL) > 0 Libc.free(buf_addr) notify_error(sock.recvnotify, "Partial message received") else diff --git a/base/special/exp.jl b/base/special/exp.jl index e5b7e7a5521fb..f22bccf8ceb62 100644 --- a/base/special/exp.jl +++ b/base/special/exp.jl @@ -70,13 +70,13 @@ julia> exp(1.0) ``` """ function exp(x::T) where T<:Union{Float32,Float64} - xa = reinterpret(Unsigned, x) & bitnot(sign_mask(T)) + xa = bitand(reinterpret(Unsigned, x), bitnot(sign_mask(T))) xsb = signbit(x) # filter out non-finite arguments if xa > reinterpret(Unsigned, MAX_EXP(T)) if xa >= exponent_mask(T) - xa & significand_mask(T) != 0 && return T(NaN) + bitand(xa, significand_mask(T)) != 0 && return T(NaN) return xsb ? T(0.0) : T(Inf) # exp(+-Inf) end x > MAX_EXP(T) && return T(Inf) diff --git a/base/special/exp10.jl b/base/special/exp10.jl index 3f53817e5495d..ca4f79644db0d 100644 --- a/base/special/exp10.jl +++ b/base/special/exp10.jl @@ -82,13 +82,13 @@ julia> exp10(0.2) ``` """ function exp10(x::T) where T<:Union{Float32,Float64} - xa = reinterpret(Unsigned, x) & bitnot(sign_mask(T)) + xa = bitand(reinterpret(Unsigned, x), bitnot(sign_mask(T))) xsb = signbit(x) # filter out non-finite arguments if xa > reinterpret(Unsigned, MAX_EXP10(T)) if xa >= exponent_mask(T) - xa & significand_mask(T) != 0 && return T(NaN) + bitand(xa, significand_mask(T)) != 0 && return T(NaN) return xsb ? T(0.0) : T(Inf) # exp10(+-Inf) end x > MAX_EXP10(T) && return T(Inf) diff --git a/base/special/gamma.jl b/base/special/gamma.jl index b6b4539fb46fc..c9e8c64845ec5 100644 --- a/base/special/gamma.jl +++ b/base/special/gamma.jl @@ -119,7 +119,7 @@ function lgamma(z::Complex{Float64}) while x <= 7 shiftprod *= Complex(x,yabs) sb′ = signbit(imag(shiftprod)) - signflips += sb′ & (sb′ != sb) + signflips += bitand(sb′, sb′ != sb) sb = sb′ x += 1 end diff --git a/base/special/log.jl b/base/special/log.jl index 3627269a9da36..ab17f944f9465 100644 --- a/base/special/log.jl +++ b/base/special/log.jl @@ -146,7 +146,7 @@ const FMA_NATIVE = muladd(nextfloat(1.0),nextfloat(1.0),-nextfloat(1.0,2)) == -4 # truncate lower order bits (up to 26) # ideally, this should be able to use ANDPD instructions, see #9868. @inline function truncbits(x::Float64) - reinterpret(Float64, reinterpret(UInt64,x) & 0xffff_ffff_f800_0000) + reinterpret(Float64, bitand(reinterpret(UInt64,x), 0xffff_ffff_f800_0000)) end @@ -262,14 +262,14 @@ function log(x::Float64) # Step 3 xu = reinterpret(UInt64,x) - m = Int(xu >> 52) & 0x07ff + m = bitand(Int(xu >> 52), 0x07ff) if m == 0 # x is subnormal x *= 1.8014398509481984e16 # 0x1p54, normalise significand xu = reinterpret(UInt64,x) - m = Int(xu >> 52) & 0x07ff - 54 + m = bitand(Int(xu >> 52), 0x07ff) - 54 end m -= 1023 - y = reinterpret(Float64, bitor(xu & 0x000f_ffff_ffff_ffff, 0x3ff0_0000_0000_0000)) + y = reinterpret(Float64, bitor(bitand(xu, 0x000f_ffff_ffff_ffff), 0x3ff0_0000_0000_0000)) mf = Float64(m) F = (y + 3.5184372088832e13) - 3.5184372088832e13 # 0x1p-7*round(0x1p7*y) @@ -298,14 +298,14 @@ function log(x::Float32) # Step 3 xu = reinterpret(UInt32,x) - m = Int(xu >> 23) & 0x00ff + m = bitand(Int(xu >> 23), 0x00ff) if m == 0 # x is subnormal x *= 3.3554432f7 # 0x1p25, normalise significand xu = reinterpret(UInt32,x) - m = Int(xu >> 23) & 0x00ff - 25 + m = bitand(Int(xu >> 23), 0x00ff) - 25 end m -= 127 - y = reinterpret(Float32, bitor(xu & 0x007f_ffff, 0x3f80_0000)) + y = reinterpret(Float32, bitor(bitand(xu, 0x007f_ffff), 0x3f80_0000)) mf = Float32(m) F = (y + 65536.0f0) - 65536.0f0 # 0x1p-7*round(0x1p7*y) @@ -337,10 +337,10 @@ function log1p(x::Float64) # Step 3 z = 1.0 + x zu = reinterpret(UInt64,z) - s = reinterpret(Float64,0x7fe0_0000_0000_0000 - (zu & 0xfff0_0000_0000_0000)) # 2^-m - m = Int(zu >> 52) & 0x07ff - 1023 # z cannot be subnormal + s = reinterpret(Float64,0x7fe0_0000_0000_0000 - bitand(zu, 0xfff0_0000_0000_0000)) # 2^-m + m = bitand(Int(zu >> 52), 0x07ff) - 1023 # z cannot be subnormal c = m > 0 ? 1.0-(z-x) : x-(z-1.0) # 1+x = z+c exactly - y = reinterpret(Float64, bitor(zu & 0x000f_ffff_ffff_ffff, 0x3ff0_0000_0000_0000)) + y = reinterpret(Float64, bitor(bitand(zu, 0x000f_ffff_ffff_ffff), 0x3ff0_0000_0000_0000)) mf = Float64(m) F = (y + 3.5184372088832e13) - 3.5184372088832e13 # 0x1p-7*round(0x1p7*y) @@ -370,10 +370,10 @@ function log1p(x::Float32) # Step 3 z = 1f0 + x zu = reinterpret(UInt32,z) - s = reinterpret(Float32,0x7f000000 - (zu & 0xff80_0000)) # 2^-m - m = Int(zu >> 23) & 0x00ff - 127 # z cannot be subnormal + s = reinterpret(Float32,0x7f000000 - bitand(zu, 0xff80_0000)) # 2^-m + m = bitand(Int(zu >> 23), 0x00ff) - 127 # z cannot be subnormal c = m > 0 ? 1f0-(z-x) : x-(z-1f0) # 1+x = z+c - y = reinterpret(Float32, bitor(zu & 0x007f_ffff, 0x3f80_0000)) + y = reinterpret(Float32, bitor(bitand(zu, 0x007f_ffff), 0x3f80_0000)) mf = Float32(m) F = (y + 65536.0f0) - 65536.0f0 # 0x1p-7*round(0x1p7*y) diff --git a/base/special/rem_pio2.jl b/base/special/rem_pio2.jl index 1d7b300c0f94b..bd25cef65140b 100644 --- a/base/special/rem_pio2.jl +++ b/base/special/rem_pio2.jl @@ -57,8 +57,8 @@ Return the high word of `x` as a `UInt32`. Return positive part of the high word of `x` as a `UInt32`. """ -@inline poshighword(x::UInt64) = unsafe_trunc(UInt32,x >> 32)&0x7fffffff -@inline poshighword(x::Float32) = reinterpret(UInt32, x)&0x7fffffff +@inline poshighword(x::UInt64) = bitand(unsafe_trunc(UInt32,x >> 32), 0x7fffffff) +@inline poshighword(x::Float32) = bitand(reinterpret(UInt32, x), 0x7fffffff) @inline poshighword(x::Float64) = poshighword(reinterpret(UInt64, x)) @inline function cody_waite_2c_pio2(x::Float64, fn, n) @@ -89,7 +89,7 @@ end j = xhp>>20 y1 = r-w high = highword(y1) - i = j-((high>>20)&0x7ff) + i = j - bitand(high >> 20, 0x7ff) if i>16 # 2nd iteration needed, good to 118 t = r w = fn*pio2_2 @@ -97,7 +97,7 @@ end w = muladd(fn, pio2_2t,-((t-r)-w)) y1 = r-w high = highword(y1) - i = j-((high>>20)&0x7ff) + i = j - bitand(high >> 20, 0x7ff) if i>49 # 3rd iteration need, 151 bits acc t = r # will cover all possible cases w = fn*pio2_3 @@ -152,10 +152,10 @@ function paynehanek(x::Float64) # Computations are integer based, so reinterpret x as UInt64 u = reinterpret(UInt64, x) # Strip x of exponent bits and replace with ^1 - X = bitor(u & significand_mask(Float64), one(UInt64) << significand_bits(Float64)) + X = bitor(bitand(u, significand_mask(Float64)), one(UInt64) << significand_bits(Float64)) # Get k from formula above # k = exponent(x)-52 - k = Int((u & exponent_mask(Float64)) >> significand_bits(Float64)) - exponent_bias(Float64) - significand_bits(Float64) + k = Int(bitand(u, exponent_mask(Float64)) >> significand_bits(Float64)) - exponent_bias(Float64) - significand_bits(Float64) # 2. Let α = 1/2π, then: # @@ -238,7 +238,7 @@ added for ``π/4<|x|<=π/2`` instead of simply returning `x`. if xhp <= 0x400f6a7a # last five bits of xhp == last five bits of highword(pi/2) or # highword(2pi/2) implies |x| ~= pi/2 or 2pi/2, - if (xhp & 0xfffff) == 0x921fb # use precise Cody Waite scheme + if bitand(xhp, 0xfffff) == 0x921fb # use precise Cody Waite scheme return cody_waite_ext_pio2(x, xhp) end # use Cody Waite with two constants diff --git a/base/special/trig.jl b/base/special/trig.jl index a9c572e2d488b..833e02de6e4c7 100644 --- a/base/special/trig.jl +++ b/base/special/trig.jl @@ -38,7 +38,7 @@ function sin(x::T) where T<:Union{Float32, Float64} sin_domain_error(x) end n, y = rem_pio2_kernel(x) - n = n&3 + n = bitand(n, 3) if n == 0 return sin_kernel(y) elseif n == 1 @@ -108,7 +108,7 @@ function cos(x::T) where T<:Union{Float32, Float64} cos_domain_error(x) else n, y = rem_pio2_kernel(x) - n = n&3 + n = bitand(n, 3) if n == 0 return cos_kernel(y) elseif n == 1 @@ -181,7 +181,7 @@ function sincos(x::T) where T<:Union{Float32, Float64} sincos_domain_error(x) end n, y = rem_pio2_kernel(x) - n = n&3 + n = bitand(n, 3) # calculate both kernels at the reduced y... si, co = sincos_kernel(y) # ... and use the same selection scheme as above: (sin, cos, -sin, -cos) for @@ -528,7 +528,7 @@ function atan2(y::T, x::T) where T<:Union{Float32, Float64} if k > ATAN2_RATIO_THRESHOLD(T) # |y/x| > threshold z=T(pi)/2+T(0.5)*ATAN2_PI_LO(T) - m&=1; + m = bitand(m, 1) elseif x<0 && k < -ATAN2_RATIO_THRESHOLD(T) # 0 > |y|/x > threshold z = zero(T) else #safe to do y/x @@ -554,7 +554,7 @@ PIO2_HI(::Type{Float64}) = 1.57079632679489655800e+00 PIO2_LO(::Type{Float64}) = 6.12323399573676603587e-17 ACOS_PI(::Type{Float32}) = 3.1415925026f+00 ACOS_PI(::Type{Float64}) = 3.14159265358979311600e+00 -@inline ACOS_CORRECT_LOWWORD(::Type{Float32}, x) = reinterpret(Float32, (reinterpret(UInt32, x) & 0xfffff000)) +@inline ACOS_CORRECT_LOWWORD(::Type{Float32}, x) = reinterpret(Float32, bitand(reinterpret(UInt32, x), 0xfffff000)) @inline ACOS_CORRECT_LOWWORD(::Type{Float64}, x) = reinterpret(Float64, (reinterpret(UInt64, x) >> 32) << 32) @noinline acos_domain_error(x) = throw(DomainError(x, "acos(x) not defined for |x| > 1")) @@ -620,7 +620,7 @@ function mulpi_ext(x::Float64) m_hi = 3.1415926218032837 m_lo = 3.178650954705639e-8 - x_hi = reinterpret(Float64, reinterpret(UInt64,x) & 0xffff_ffff_f800_0000) + x_hi = reinterpret(Float64, bitand(reinterpret(UInt64,x), 0xffff_ffff_f800_0000)) x_lo = x-x_hi y_hi = m*x diff --git a/base/stat.jl b/base/stat.jl index 0de651cd9f6de..01785f94f2ce1 100644 --- a/base/stat.jl +++ b/base/stat.jl @@ -151,56 +151,56 @@ Equivalent to `stat(file).ctime` Returns `true` if `path` is a valid filesystem path, `false` otherwise. """ - ispath(st::StatStruct) = filemode(st) & 0xf000 != 0x0000 + ispath(st::StatStruct) = bitand(filemode(st), 0xf000) != 0x0000 """ isfifo(path) -> Bool Returns `true` if `path` is a FIFO, `false` otherwise. """ - isfifo(st::StatStruct) = filemode(st) & 0xf000 == 0x1000 + isfifo(st::StatStruct) = bitand(filemode(st), 0xf000) == 0x1000 """ ischardev(path) -> Bool Returns `true` if `path` is a character device, `false` otherwise. """ - ischardev(st::StatStruct) = filemode(st) & 0xf000 == 0x2000 + ischardev(st::StatStruct) = bitand(filemode(st), 0xf000) == 0x2000 """ isdir(path) -> Bool Returns `true` if `path` is a directory, `false` otherwise. """ - isdir(st::StatStruct) = filemode(st) & 0xf000 == 0x4000 + isdir(st::StatStruct) = bitand(filemode(st), 0xf000) == 0x4000 """ isblockdev(path) -> Bool Returns `true` if `path` is a block device, `false` otherwise. """ -isblockdev(st::StatStruct) = filemode(st) & 0xf000 == 0x6000 +isblockdev(st::StatStruct) = bitand(filemode(st), 0xf000) == 0x6000 """ isfile(path) -> Bool Returns `true` if `path` is a regular file, `false` otherwise. """ - isfile(st::StatStruct) = filemode(st) & 0xf000 == 0x8000 + isfile(st::StatStruct) = bitand(filemode(st), 0xf000) == 0x8000 """ islink(path) -> Bool Returns `true` if `path` is a symbolic link, `false` otherwise. """ - islink(st::StatStruct) = filemode(st) & 0xf000 == 0xa000 + islink(st::StatStruct) = bitand(filemode(st), 0xf000) == 0xa000 """ issocket(path) -> Bool Returns `true` if `path` is a socket, `false` otherwise. """ - issocket(st::StatStruct) = filemode(st) & 0xf000 == 0xc000 + issocket(st::StatStruct) = bitand(filemode(st), 0xf000) == 0xc000 # mode permission predicates @@ -209,21 +209,21 @@ Returns `true` if `path` is a socket, `false` otherwise. Returns `true` if `path` has the setuid flag set, `false` otherwise. """ -issetuid(st::StatStruct) = (filemode(st) & 0o4000) > 0 +issetuid(st::StatStruct) = bitand(filemode(st), 0o4000) > 0 """ issetgid(path) -> Bool Returns `true` if `path` has the setgid flag set, `false` otherwise. """ -issetgid(st::StatStruct) = (filemode(st) & 0o2000) > 0 +issetgid(st::StatStruct) = bitand(filemode(st), 0o2000) > 0 """ issticky(path) -> Bool Returns `true` if `path` has the sticky bit set, `false` otherwise. """ -issticky(st::StatStruct) = (filemode(st) & 0o1000) > 0 +issticky(st::StatStruct) = bitand(filemode(st), 0o1000) > 0 """ uperm(file) @@ -238,14 +238,14 @@ Gets the permissions of the owner of the file as a bitfield of For allowed arguments, see [`stat`](@ref). """ -uperm(st::StatStruct) = UInt8((filemode(st) >> 6) & 0x7) +uperm(st::StatStruct) = UInt8(bitand(filemode(st) >> 6, 0x7)) """ gperm(file) Like [`uperm`](@ref) but gets the permissions of the group owning the file. """ -gperm(st::StatStruct) = UInt8((filemode(st) >> 3) & 0x7) +gperm(st::StatStruct) = UInt8(bitand(filemode(st) >> 3, 0x7)) """ operm(file) @@ -253,7 +253,7 @@ gperm(st::StatStruct) = UInt8((filemode(st) >> 3) & 0x7) Like [`uperm`](@ref) but gets the permissions for people who neither own the file nor are a member of the group owning the file """ -operm(st::StatStruct) = UInt8((filemode(st) ) & 0x7) +operm(st::StatStruct) = UInt8(bitand(filemode(st), 0x7)) # mode predicate methods for file names diff --git a/base/strings/io.jl b/base/strings/io.jl index 247fb4fc0d08e..c03a9a3c1d413 100644 --- a/base/strings/io.jl +++ b/base/strings/io.jl @@ -496,7 +496,7 @@ function convert(::Type{String}, chars::AbstractVector{Char}) if '\ud7ff' < c && c + 1024 < '\ue000' d, state = next(chars, state) if '\ud7ff' < d - 1024 && d < '\ue000' - c = Char(bitor(0x10000 + ((UInt32(c) & 0x03ff) << 10), (UInt32(d) & 0x03ff))) + c = Char(bitor(0x10000 + (bitand(UInt32(c), 0x03ff) << 10), bitand(UInt32(d), 0x03ff))) else write(io, c) c = d diff --git a/base/strings/search.jl b/base/strings/search.jl index 5f3dd62579060..1948ea303e530 100644 --- a/base/strings/search.jl +++ b/base/strings/search.jl @@ -80,7 +80,7 @@ end _searchindex(s, t::Char, i) = search(s, t, i) function _search_bloom_mask(c) - UInt64(1) << (c & 63) + UInt64(1) << bitand(c, 63) end _nthbyte(s::String, i) = codeunit(s, i) @@ -131,13 +131,13 @@ function _searchindex(s::Union{String,ByteArray}, t::Union{String,ByteArray}, i) end # no match, try to rule out the next character - if i < w && bloom_mask & _search_bloom_mask(_nthbyte(s,i+n+1)) == 0 + if i < w && bitand(bloom_mask, _search_bloom_mask(_nthbyte(s,i+n+1))) == 0 i += n else i += skip end elseif i < w - if bloom_mask & _search_bloom_mask(_nthbyte(s,i+n+1)) == 0 + if bitand(bloom_mask, _search_bloom_mask(_nthbyte(s,i+n+1))) == 0 i += n end end @@ -298,13 +298,13 @@ function _rsearchindex(s::Union{String,ByteArray}, t::Union{String,ByteArray}, k end # no match, try to rule out the next character - if i > 1 && bloom_mask & _search_bloom_mask(_nthbyte(s,i-1)) == 0 + if i > 1 && bitand(bloom_mask, _search_bloom_mask(_nthbyte(s,i-1))) == 0 i -= n else i -= skip end elseif i > 1 - if bloom_mask & _search_bloom_mask(_nthbyte(s,i-1)) == 0 + if bitand(bloom_mask, _search_bloom_mask(_nthbyte(s,i-1))) == 0 i -= n end end diff --git a/base/strings/string.jl b/base/strings/string.jl index 9fcee8391e4cc..76c5b0d847567 100644 --- a/base/strings/string.jl +++ b/base/strings/string.jl @@ -185,10 +185,10 @@ isvalid(s::String) = isvalid(String, s) ## basic UTF-8 decoding & iteration ## -is_surrogate_lead(c::Unsigned) = ((c & bitnot(0x003ff)) == 0xd800) -is_surrogate_trail(c::Unsigned) = ((c & bitnot(0x003ff)) == 0xdc00) -is_surrogate_codeunit(c::Unsigned) = ((c & bitnot(0x007ff)) == 0xd800) -is_valid_continuation(c) = ((c & 0xc0) == 0x80) +is_surrogate_lead(c::Unsigned) = bitand(c, bitnot(0x003ff)) == 0xd800 +is_surrogate_trail(c::Unsigned) = bitand(c, bitnot(0x003ff)) == 0xdc00 +is_surrogate_codeunit(c::Unsigned) = bitand(c, bitnot(0x007ff)) == 0xd800 +is_valid_continuation(c) = bitand(c, 0xc0) == 0x80 const utf8_offset = [ 0x00000000, 0x00003080, @@ -426,17 +426,17 @@ function string(a::Union{String,Char}...) if c < 0x80 unsafe_store!(p, c%UInt8, offs); offs += 1 elseif c < 0x800 - unsafe_store!(p, bitor(c >> 6 , 0xC0) % UInt8, offs); offs += 1 - unsafe_store!(p, bitor(c & 0x3F, 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor(c >> 6 , 0xC0) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor(bitand(c, 0x3F), 0x80) % UInt8, offs); offs += 1 elseif c < 0x10000 - unsafe_store!(p, bitor(c >> 12 , 0xE0) % UInt8, offs); offs += 1 - unsafe_store!(p, bitor((c >> 6) & 0x3F, 0x80) % UInt8, offs); offs += 1 - unsafe_store!(p, bitor(c & 0x3F , 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor(c >> 12 , 0xE0) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor(bitand(0x3F, c >> 6), 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor(bitand(0x3F, c ), 0x80) % UInt8, offs); offs += 1 elseif c < 0x110000 - unsafe_store!(p, bitor(c >> 18 , 0xF0) % UInt8, offs); offs += 1 - unsafe_store!(p, bitor((c >> 12) & 0x3F, 0x80) % UInt8, offs); offs += 1 - unsafe_store!(p, bitor((c >> 6) & 0x3F, 0x80) % UInt8, offs); offs += 1 - unsafe_store!(p, bitor(c & 0x3F , 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor(c >> 18 , 0xF0) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor(bitand(c >> 12, 0x3F), 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor(bitand(c >> 6, 0x3F), 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, bitor(bitand(c, 0x3F) , 0x80) % UInt8, offs); offs += 1 else # '\ufffd' unsafe_store!(p, 0xef, offs); offs += 1 @@ -519,7 +519,7 @@ function repeat(c::Char, r::Integer) elseif ch < 0x800 out = _string_n(2r) p16 = reinterpret(Ptr{UInt16}, pointer(out)) - u16 = bitor(bitor(ch >> 0x6, (ch & 0x3f) << 0x8) % UInt16, 0x80c0) + u16 = bitor(bitor(ch >> 0x6, bitand(ch, 0x3f) << 0x8) % UInt16, 0x80c0) @inbounds for i = 1:r unsafe_store!(p16, u16, i) end @@ -528,8 +528,8 @@ function repeat(c::Char, r::Integer) out = _string_n(3r) p = pointer(out) b1 = bitor((ch >> 0xc) % UInt8, 0xe0) - b2 = bitor(((ch >> 0x6) & 0x3f) % UInt8, 0x80) - b3 = bitor((ch & 0x3f) % UInt8, 0x80) + b2 = bitor(bitand(ch >> 0x6, 0x3f) % UInt8, 0x80) + b3 = bitor(bitand(ch, 0x3f) % UInt8, 0x80) @inbounds for i = 1:r unsafe_store!(p, b1) unsafe_store!(p, b2, 2) @@ -540,9 +540,9 @@ function repeat(c::Char, r::Integer) out = _string_n(4r) p32 = reinterpret(Ptr{UInt32}, pointer(out)) u32 = bitor(ch >> 0x12, - (ch >> 0x4) & 0x03f00, - (ch << 0xa) & 0x3f0000, - (ch & 0x3f) << 0x18 ) + bitand(ch >> 0x4, 0x03f00), + bitand(ch << 0xa, 0x3f0000), + bitand(ch, 0x3f) << 0x18 ) u32 = bitor(u32 % UInt32, 0x808080f0) @inbounds for i = 1:r unsafe_store!(p32, u32) diff --git a/base/strings/util.jl b/base/strings/util.jl index 0e556aa822ffe..175b0a5d2b806 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -543,7 +543,7 @@ function bytes2hex(a::AbstractArray{UInt8}) i = 0 for x in a b[i += 1] = hex_chars[1 + x >> 4] - b[i += 1] = hex_chars[1 + x & 0xf] + b[i += 1] = hex_chars[1 + bitand(x, 0xf)] end return String(b) end diff --git a/base/sysinfo.jl b/base/sysinfo.jl index def66c52e5225..811b1f230e002 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -261,7 +261,7 @@ end if iswindows() function windows_version() verinfo = ccall(:GetVersion, UInt32, ()) - VersionNumber(verinfo & 0xFF, (verinfo >> 8) & 0xFF, verinfo >> 16) + VersionNumber(bitand(verinfo, 0xFF), bitand(verinfo >> 8, 0xFF), verinfo >> 16) end else windows_version() = v"0.0" diff --git a/base/twiceprecision.jl b/base/twiceprecision.jl index 0e9a32f12a9ff..5d138f58cf736 100644 --- a/base/twiceprecision.jl +++ b/base/twiceprecision.jl @@ -26,7 +26,7 @@ function splitprec(::Type{F}, i::Integer) where {F<:AbstractFloat} end function truncmask(x::F, mask) where {F<:IEEEFloat} - reinterpret(F, mask & reinterpret(uinttype(F), x)) + reinterpret(F, bitand(mask, reinterpret(uinttype(F), x))) end truncmask(x, mask) = x From 4c1b6e732f7fdc210ee485fc7b01816a64113dc6 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Wed, 22 Nov 2017 11:30:32 -0800 Subject: [PATCH 12/17] Replace bitwise calls to & with bitand in stdlib/. --- stdlib/Base64/src/encode.jl | 2 +- stdlib/FileWatching/src/FileWatching.jl | 18 +++++++++--------- stdlib/Mmap/src/Mmap.jl | 14 +++++++------- stdlib/SharedArrays/src/SharedArrays.jl | 6 +++--- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/stdlib/Base64/src/encode.jl b/stdlib/Base64/src/encode.jl index 2d2f78820c664..222c5c15838c3 100644 --- a/stdlib/Base64/src/encode.jl +++ b/stdlib/Base64/src/encode.jl @@ -2,7 +2,7 @@ # Generate encode table. const BASE64_ENCODE = [UInt8(x) for x in ['A':'Z'; 'a':'z'; '0':'9'; '+'; '/']] -encode(x::UInt8) = @inbounds return BASE64_ENCODE[(x & 0x3f) + 1] +encode(x::UInt8) = @inbounds return BASE64_ENCODE[bitand(x, 0x3f) + 1] encodepadding() = UInt8('=') """ diff --git a/stdlib/FileWatching/src/FileWatching.jl b/stdlib/FileWatching/src/FileWatching.jl index 9720dd67b5494..adb33f68c1969 100644 --- a/stdlib/FileWatching/src/FileWatching.jl +++ b/stdlib/FileWatching/src/FileWatching.jl @@ -30,9 +30,9 @@ struct FileEvent timedout::Bool end FileEvent() = FileEvent(false, false, false) -FileEvent(flags::Integer) = FileEvent((flags & UV_RENAME) != 0, - (flags & UV_CHANGE) != 0, - (flags & FD_TIMEDOUT) != 0) +FileEvent(flags::Integer) = FileEvent(bitand(flags, UV_RENAME) != 0, + bitand(flags, UV_CHANGE) != 0, + bitand(flags, FD_TIMEDOUT) != 0) fetimeout() = FileEvent(false, false, true) struct FDEvent @@ -50,10 +50,10 @@ const FD_TIMEDOUT = 8 isreadable(f::FDEvent) = f.readable iswritable(f::FDEvent) = f.writable FDEvent() = FDEvent(false, false, false, false) -FDEvent(flags::Integer) = FDEvent((flags & UV_READABLE) != 0, - (flags & UV_WRITABLE) != 0, - (flags & UV_DISCONNECT) != 0, - (flags & FD_TIMEDOUT) != 0) +FDEvent(flags::Integer) = FDEvent(bitand(flags, UV_READABLE) != 0, + bitand(flags, UV_WRITABLE) != 0, + bitand(flags, UV_DISCONNECT) != 0, + bitand(flags, FD_TIMEDOUT) != 0) fdtimeout() = FDEvent(false, false, false, true) |(a::FDEvent, b::FDEvent) = FDEvent(a.readable | b.readable, @@ -378,11 +378,11 @@ function wait(fdw::_FDWatcher; readable=true, writable=true) events = bitor(events, FDEvent(fdw.events)) haveevent = false if readable && isreadable(events) - fdw.events &= bitnot(UV_READABLE) + fdw.events = bitand(fdw.events, bitnot(UV_READABLE)) haveevent = true end if writable && iswritable(events) - fdw.events &= bitnot(UV_WRITABLE) + fdw.events = bitand(fdw.events, bitnot(UV_WRITABLE)) haveevent = true end if haveevent diff --git a/stdlib/Mmap/src/Mmap.jl b/stdlib/Mmap/src/Mmap.jl index 5367684ad9c83..722ca877a3d03 100644 --- a/stdlib/Mmap/src/Mmap.jl +++ b/stdlib/Mmap/src/Mmap.jl @@ -51,13 +51,13 @@ function settings(s::Int, shared::Bool) else mode = ccall(:fcntl,Cint,(Cint,Cint),s,F_GETFL) systemerror("fcntl F_GETFL", mode == -1) - mode = mode & 3 + mode = bitand(mode, 3) prot = mode == 0 ? PROT_READ : mode == 1 ? PROT_WRITE : bitor(PROT_READ, PROT_WRITE) - if prot & PROT_READ == 0 + if iszero(bitand(prot, PROT_READ)) throw(ArgumentError("mmap requires read permissions on the file (open with \"r+\" mode to override)")) end end - return prot, flags, (prot & PROT_WRITE) > 0 + return prot, flags, bitand(prot, PROT_WRITE) > 0 end # Before mapping, grow the file to sufficient size @@ -196,12 +196,12 @@ function mmap(io::IO, szfile = convert(Csize_t, len + offset) readonly && szfile > filesize(io) && throw(ArgumentError("unable to increase file size to $szfile due to read-only permissions")) handle = create ? ccall(:CreateFileMappingW, stdcall, Ptr{Void}, (Cptrdiff_t, Ptr{Void}, DWORD, DWORD, DWORD, Cwstring), - file_desc, C_NULL, readonly ? PAGE_READONLY : PAGE_READWRITE, szfile >> 32, szfile & typemax(UInt32), name) : + file_desc, C_NULL, readonly ? PAGE_READONLY : PAGE_READWRITE, szfile >> 32, bitand(szfile, typemax(UInt32)), name) : ccall(:OpenFileMappingW, stdcall, Ptr{Void}, (DWORD, Cint, Cwstring), readonly ? FILE_MAP_READ : FILE_MAP_WRITE, true, name) handle == C_NULL && error("could not create file mapping: $(Libc.FormatMessage())") ptr = ccall(:MapViewOfFile, stdcall, Ptr{Void}, (Ptr{Void}, DWORD, DWORD, DWORD, Csize_t), - handle, readonly ? FILE_MAP_READ : FILE_MAP_WRITE, offset_page >> 32, offset_page & typemax(UInt32), (offset - offset_page) + len) + handle, readonly ? FILE_MAP_READ : FILE_MAP_WRITE, offset_page >> 32, bitand(offset_page, typemax(UInt32)), (offset - offset_page) + len) ptr == C_NULL && error("could not create mapping view: $(Libc.FormatMessage())") end # os-test # convert mmapped region to Julia Array at `ptr + (offset - offset_page)` since file was mapped at offset_page @@ -251,9 +251,9 @@ function mmap(io::IOStream, ::Type{<:BitArray}, dims::NTuple{N,Integer}, nc = Base.num_bit_chunks(n) chunks = mmap(io, Vector{UInt64}, (nc,), offset; grow=grow, shared=shared) if !isreadonly(io) - chunks[end] &= Base._msk_end(n) + chunks[end] = bitand(chunks[end], Base._msk_end(n)) else - if chunks[end] != chunks[end] & Base._msk_end(n) + if chunks[end] != bitand(chunks[end], Base._msk_end(n)) throw(ArgumentError("the given file does not contain a valid BitArray of size $(join(dims, 'x')) (open with \"r+\" mode to override)")) end end diff --git a/stdlib/SharedArrays/src/SharedArrays.jl b/stdlib/SharedArrays/src/SharedArrays.jl index 38e51b84cc371..25abc66fd7901 100644 --- a/stdlib/SharedArrays/src/SharedArrays.jl +++ b/stdlib/SharedArrays/src/SharedArrays.jl @@ -648,8 +648,8 @@ end if Sys.iswindows() function _shm_mmap_array(T, dims, shm_seg_name, mode) - readonly = !((mode & JL_O_RDWR) == JL_O_RDWR) - create = (mode & JL_O_CREAT) == JL_O_CREAT + readonly = bitand(mode, JL_O_RDWR) != JL_O_RDWR + create = bitand(mode, JL_O_CREAT) == JL_O_CREAT s = Mmap.Anonymous(shm_seg_name, readonly, create) Mmap.mmap(s, Array{T,length(dims)}, dims, zero(Int64)) end @@ -666,7 +666,7 @@ function _shm_mmap_array(T, dims, shm_seg_name, mode) # On OSX, ftruncate must to used to set size of segment, just lseek does not work. # and only at creation time - if (mode & JL_O_CREAT) == JL_O_CREAT + if bitand(mode, JL_O_CREAT) == JL_O_CREAT rc = ccall(:jl_ftruncate, Cint, (Cint, Int64), fd_mem, prod(dims)*sizeof(T)) systemerror("ftruncate() failed for shm segment " * shm_seg_name, rc != 0) end From 955cf6d186770c70e60f0249c7f4173e0a4736c8 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Wed, 22 Nov 2017 12:26:35 -0800 Subject: [PATCH 13/17] Deprecate bitwise calls to xor to bitxor. --- base/bool.jl | 24 ++++++++++++++---------- base/deprecated.jl | 12 ++++++++++-- base/gmp.jl | 6 +++--- base/int.jl | 30 ++++++++++++++++++++++++++++-- base/operators.jl | 6 +++--- base/promotion.jl | 2 +- 6 files changed, 59 insertions(+), 21 deletions(-) diff --git a/base/bool.jl b/base/bool.jl index d5273c367ae6b..c04125bc5514e 100644 --- a/base/bool.jl +++ b/base/bool.jl @@ -41,29 +41,33 @@ end bitnot(x::Bool) = !x bitand(x::Bool, y::Bool) = and_int(x, y) bitor(x::Bool, y::Bool) = or_int(x, y) +bitxor(x::Bool, y::Bool) = (x != y) (&)(x::Bool, y::Bool) = and_int(x, y) (|)(x::Bool, y::Bool) = or_int(x, y) """ xor(x, y) - ⊻(x, y) -Bitwise exclusive or of `x` and `y`. The infix operation -`a ⊻ b` is a synonym for `xor(a,b)`, and -`⊻` can be typed by tab-completing `\\xor` -or `\\veebar` in the Julia REPL. +Logical exclusive or of `x` and `y`. # Examples ```jldoctest -julia> [true; true; false] .⊻ [true; false; false] -3-element BitArray{1}: - false - true - false +julia> xor(true, false) +true + +julia> xor(false, true) +true + +julia> xor(true, true) +false + +julia> xor(false, false) +false ``` """ xor(x::Bool, y::Bool) = (x != y) + >>(x::Bool, c::Unsigned) = Int(x) >> c <<(x::Bool, c::Unsigned) = Int(x) << c >>>(x::Bool, c::Unsigned) = Int(x) >>> c diff --git a/base/deprecated.jl b/base/deprecated.jl index e4629903ca27c..4741155b10ced 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -2111,8 +2111,16 @@ end @deprecate (&)(x::T, y::T) where {T<:BitInteger} bitand(x, y) @deprecate (&)(a, b, c, xs...) bitand(a, b, c, xs...) - - +@deprecate xor(x::BigInt, y::BigInt) bitxor(x, y) +@deprecate xor(a::BigInt, b::BigInt, c::BigInt) bitxor(a, b, c) +@deprecate xor(a::BigInt, b::BigInt, c::BigInt, d::BigInt) bitxor(a, b, c, d) +@deprecate xor(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) bitxor(a, b, c, d, e) + +@deprecate xor(x::Integer) bitxor(x) +@deprecate xor(a::Integer, b::Integer) bitxor(a, b) +@deprecate xor(x::T, y::T) where {T<:Integer} bitxor(x, y) +@deprecate xor(x::T, y::T) where {T<:BitInteger} bitxor(x, y) +@deprecate xor(a, b, c, xs...) bitxor(a, b, c, xs...) # #24258 # Physical units define an equivalence class: there is no such thing as a step of "1" (is diff --git a/base/gmp.jl b/base/gmp.jl index da142ddaefacf..40946545e9a4c 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -4,7 +4,7 @@ module GMP export BigInt -import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, bitnot, bitand, bitor, xor, +import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, bitnot, bitand, bitor, bitxor, binomial, cmp, convert, div, divrem, factorial, fld, gcd, gcdx, lcm, mod, ndigits, promote_rule, rem, show, isqrt, string, powermod, sum, trailing_zeros, trailing_ones, count_ones, base, tryparse_internal, @@ -405,7 +405,7 @@ big(::Type{<:Rational}) = Rational{BigInt} for (fJ, fC) in ((:+, :add), (:-,:sub), (:*, :mul), (:fld, :fdiv_q), (:div, :tdiv_q), (:mod, :fdiv_r), (:rem, :tdiv_r), (:gcd, :gcd), (:lcm, :lcm), - (:bitand, :and), (:bitor, :ior), (:xor, :xor)) + (:bitand, :and), (:bitor, :ior), (:bitxor, :xor)) @eval begin ($fJ)(x::BigInt, y::BigInt) = MPZ.$fC(x, y) end @@ -433,7 +433,7 @@ function invmod(x::BigInt, y::BigInt) end # More efficient commutative operations -for (fJ, fC) in ((:+, :add), (:*, :mul), (:bitand, :and), (:bitor, :ior), (:xor, :xor)) +for (fJ, fC) in ((:+, :add), (:*, :mul), (:bitand, :and), (:bitor, :ior), (:bitxor, :xor)) fC! = Symbol(fC, :!) @eval begin ($fJ)(a::BigInt, b::BigInt, c::BigInt) = MPZ.$fC!(MPZ.$fC(a, b), c) diff --git a/base/int.jl b/base/int.jl index c460bb9df2ae4..3d86daf9fd37a 100644 --- a/base/int.jl +++ b/base/int.jl @@ -291,7 +291,33 @@ julia> bitor(4, 1) ``` """ bitor(x::T, y::T) where {T<:BitInteger} = or_int(x, y) -xor(x::T, y::T) where {T<:BitInteger} = xor_int(x, y) + +""" + bitxor(x, y) + ⊻(x, y) + +Bitwise exclusive or of `x` and `y`. The infix operation +`a ⊻ b` is a synonym for `bitxor(a,b)`, and +`⊻` can be typed by tab-completing `\\xor` +or `\\veebar` in the Julia REPL. + +# Examples +```jldoctest +julia> bitstring(Int8(3)) +"00000011" + +julia> bitstring(Int8(5)) +"00000101" + +julia> bitstring(bitxor(Int8(3), Int8(5))) +"00000110" + +julia> bitstring(Int8(3) ⊻ Int8(5)) +"00000110" +``` +""" +bitxor(x::T, y::T) where {T<:BitInteger} = xor_int(x, y) + """ bswap(n) @@ -770,7 +796,7 @@ else end # issue #15489: since integer ops are unchecked, they shouldn't check promotion -for op in (:+, :-, :*, bitand, :bitor, :xor) +for op in (:+, :-, :*, bitand, :bitor, :bitxor) @eval function $op(a::Integer, b::Integer) T = promote_typeof(a, b) return $op(a % T, b % T) diff --git a/base/operators.jl b/base/operators.jl index 1044487bf7b0b..24bade7343a07 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -445,9 +445,9 @@ identity(x) = x *(x::Number) = x bitand(x::Integer) = x bitor(x::Integer) = x -xor(x::Integer) = x +bitxor(x::Integer) = x -const ⊻ = xor +const ⊻ = bitxor # foldl for argument lists. expand recursively up to a point, then # switch to a loop. this allows small cases like `a+b+c+d` to be inlined @@ -461,7 +461,7 @@ function afoldl(op,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,qs...) y end -for op in (:+, :*, :bitand, :bitor, :xor, :min, :max, :kron) +for op in (:+, :*, :bitand, :bitor, :bitxor, :min, :max, :kron) @eval begin # note: these definitions must not cause a dispatch loop when +(a,b) is # not defined, and must only try to call 2-argument definitions, so diff --git a/base/promotion.jl b/base/promotion.jl index 4a7f39f88dbc4..51faef7008c93 100644 --- a/base/promotion.jl +++ b/base/promotion.jl @@ -381,7 +381,7 @@ muladd(x::T, y::T, z::T) where {T<:Number} = x*y+z bitand(x::T, y::T) where {T<:Integer} = no_op_err("bitand", T) bitor(x::T, y::T) where {T<:Integer} = no_op_err("bitor", T) -xor(x::T, y::T) where {T<:Integer} = no_op_err("xor", T) +bitxor(x::T, y::T) where {T<:Integer} = no_op_err("bitxor", T) (==)(x::T, y::T) where {T<:Number} = x === y (< )(x::T, y::T) where {T<:Real} = no_op_err("<" , T) From 59f2d321e7ee9392d68df2bb2b91e4d29d760ebe Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Wed, 22 Nov 2017 11:35:55 -0800 Subject: [PATCH 14/17] Replace bitwise calls to xor with bitxor in test/. --- test/bigint.jl | 10 +++++----- test/operators.jl | 2 +- test/sparse/sparse.jl | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/bigint.jl b/test/bigint.jl index f28ab75876de6..c1a694687afee 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -223,11 +223,11 @@ end @test *(a, b, c, d, f) == parse(BigInt,"-45258849200337190631492857400003938881995610529251881450243326128168934937055005474972396281351684800") @test *(a, b, c, d, f, g) == parse(BigInt,"45258849200337190631492857400003938881995610529251881450243326128168934937055005474972396281351684800") - @test xor(a, b) == parse(BigInt,"327299") - @test xor(a, b, c) == parse(BigInt,"3426495623485904783798472") - @test xor(a, b, c, d) == parse(BigInt,"-3426495623485906178489610") - @test xor(a, b, c, d, f) == parse(BigInt,"-2413804710837418037418307081437316711364709261074607933698") - @test xor(a, b, c, d, f, g) == parse(BigInt,"2413804710837418037418307081437316711364709261074607933697") + @test bitxor(a, b) == parse(BigInt,"327299") + @test bitxor(a, b, c) == parse(BigInt,"3426495623485904783798472") + @test bitxor(a, b, c, d) == parse(BigInt,"-3426495623485906178489610") + @test bitxor(a, b, c, d, f) == parse(BigInt,"-2413804710837418037418307081437316711364709261074607933698") + @test bitxor(a, b, c, d, f, g) == parse(BigInt,"2413804710837418037418307081437316711364709261074607933697") @test bitand(a, b) == parse(BigInt,"124") @test bitand(a, b, c) == parse(BigInt,"72") diff --git a/test/operators.jl b/test/operators.jl index 482b0061ef2e2..80d2d7aade47d 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -49,7 +49,7 @@ p = 1=>:foo @test p[endof(p)] == p[end] == p[2] == :foo @test bitor(2) == 2 -@test xor(2) == 2 +@test bitxor(2) == 2 @test (⊻)(2) == 2 @test_throws ArgumentError Base.scalarmin(['a','b'],['c','d']) diff --git a/test/sparse/sparse.jl b/test/sparse/sparse.jl index c1763de9199b7..e9b48016f0cc0 100644 --- a/test/sparse/sparse.jl +++ b/test/sparse/sparse.jl @@ -67,7 +67,7 @@ do33 = ones(3) sqrboolmat, colboolmat = sprand(Bool, 4, 4, 0.5), sprand(Bool, 4, 1, 0.5) @test_throws DimensionMismatch map(bitand, sqrboolmat, colboolmat) @test_throws DimensionMismatch map(bitor, sqrboolmat, colboolmat) - @test_throws DimensionMismatch map(xor, sqrboolmat, colboolmat) + @test_throws DimensionMismatch map(bitxor, sqrboolmat, colboolmat) end end @@ -1723,7 +1723,7 @@ end for op in (+, -) @test op(A13024, B13024) == op(Array(A13024), Array(B13024)) end - for op in (max, min, bitand, bitor, xor) + for op in (max, min, bitand, bitor, bitxor) @test op.(A13024, B13024) == op.(Array(A13024), Array(B13024)) end end From dcb86f000723fa6845b62184053a326b56d71d60 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Wed, 22 Nov 2017 12:47:17 -0800 Subject: [PATCH 15/17] Replace bitwise calls to xor with bitxor in base/. --- base/atomics.jl | 2 +- base/bitarray.jl | 4 ++-- base/c.jl | 10 +++++----- base/linalg/bitarray.jl | 12 ++++++------ base/namedtuple.jl | 2 +- base/random/RNGs.jl | 6 +++--- base/random/dSFMT.jl | 8 ++++---- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/base/atomics.jl b/base/atomics.jl index fa37273758429..33cdf7821441f 100644 --- a/base/atomics.jl +++ b/base/atomics.jl @@ -249,7 +249,7 @@ function atomic_or! end Atomically bitwise-xor (exclusive-or) `x` with `val` -Performs `x[] \$= val` atomically. Returns the **old** value. +Performs `x[] = bitxor(x[], val)` atomically. Returns the **old** value. For further details, see LLVM's `atomicrmw xor` instruction. diff --git a/base/bitarray.jl b/base/bitarray.jl index 44d6755542492..1155ac7c82d7e 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1750,10 +1750,10 @@ map!(::typeof(identity), dest::BitArray, A::BitArray) = copy!(dest, A) for (T, f) in ((:(Union{typeof(&), typeof(*), typeof(min)}), :(&)), (:(Union{typeof(|), typeof(max)}), :(|)), - (:(Union{typeof(xor), typeof(!=)}), :xor), + (:(Union{typeof(xor), typeof(!=)}), :bitxor), (:(Union{typeof(>=), typeof(^)}), :((p, q) -> bitor(p, bitnot(q)))), (:(typeof(<=)), :((p, q) -> bitor(bitnot(p), q))), - (:(typeof(==)), :((p, q) -> bitnot(xor(p, q)))), + (:(typeof(==)), :((p, q) -> bitnot(bitxor(p, q)))), (:(typeof(<)), :((p, q) -> bitand(bitnot(p), q))), (:(typeof(>)), :((p, q) -> bitand(p, bitnot(q))))) @eval map(::$T, A::BitArray, B::BitArray) = bit_map!($f, similar(A), A, B) diff --git a/base/c.jl b/base/c.jl index 50de51162586e..80eb2edd90a0e 100644 --- a/base/c.jl +++ b/base/c.jl @@ -225,24 +225,24 @@ function transcode(::Type{UInt16}, src::Vector{UInt8}) push!(dst, a) a = b; continue elseif a < 0xe0 # 2-byte UTF-8 - push!(dst, xor(0x3080, UInt16(a) << 6, b)) + push!(dst, bitxor(0x3080, UInt16(a) << 6, b)) elseif i < n # 3/4-byte character c = src[i += 1] if -64 <= (c % Int8) # invalid UTF-8 (non-continuation) push!(dst, a, b) a = c; continue elseif a < 0xf0 # 3-byte UTF-8 - push!(dst, xor(0x2080, UInt16(a) << 12, UInt16(b) << 6, c)) + push!(dst, bitxor(0x2080, UInt16(a) << 12, UInt16(b) << 6, c)) elseif i < n d = src[i += 1] if -64 <= (d % Int8) # invalid UTF-8 (non-continuation) push!(dst, a, b, c) a = d; continue elseif a == 0xf0 && b < 0x90 # overlong encoding - push!(dst, xor(0x2080, UInt16(b) << 12, UInt16(c) << 6, d)) + push!(dst, bitxor(0x2080, UInt16(b) << 12, UInt16(c) << 6, d)) else # 4-byte UTF-8 push!(dst, 0xe5b8 + (UInt16(a) << 8) + (UInt16(b) << 2) + (c >> 4), - xor(0xdc80, UInt16(bitand(c, 0xf)) << 6, d)) + bitxor(0xdc80, UInt16(bitand(c, 0xf)) << 6, d)) end else # too short push!(dst, a, b, c) @@ -311,7 +311,7 @@ function transcode(::Type{UInt8}, src::Vector{UInt16}) a += 0x2840 dst[j += 1] = bitor(0xf0, (a >> 8) % UInt8) dst[j += 1] = bitor(0x80, (a % UInt8) >> 2) - dst[j += 1] = xor(0xf0, bitand((a % UInt8) << 4, 0x3f), (b >> 6) % UInt8) + dst[j += 1] = bitxor(0xf0, bitand((a % UInt8) << 4, 0x3f), (b >> 6) % UInt8) dst[j += 1] = bitor(0x80, bitand(b % UInt8, 0x3f)) else dst[j += 1] = bitor(0xe0, (a >> 12) % UInt8) diff --git a/base/linalg/bitarray.jl b/base/linalg/bitarray.jl index e8f1fb35708a3..c1786bbb48ea8 100644 --- a/base/linalg/bitarray.jl +++ b/base/linalg/bitarray.jl @@ -205,12 +205,12 @@ end # http://www.hackersdelight.org/hdcodetxt/transpose8.c.txt function transpose8x8(x::UInt64) y = x - t = bitand(xor(y, y >>> 7), 0x00aa00aa00aa00aa) - y = xor(y, t, t << 7) - t = bitand(xor(y, y >>> 14), 0x0000cccc0000cccc) - y = xor(y, t, t << 14) - t = bitand(xor(y, y >>> 28), 0x00000000f0f0f0f0) - return xor(y, t, t << 28) + t = bitand(bitxor(y, y >>> 7), 0x00aa00aa00aa00aa) + y = bitxor(y, t, t << 7) + t = bitand(bitxor(y, y >>> 14), 0x0000cccc0000cccc) + y = bitxor(y, t, t << 14) + t = bitand(bitxor(y, y >>> 28), 0x00000000f0f0f0f0) + return bitxor(y, t, t << 28) end function form_8x8_chunk(Bc::Vector{UInt64}, i1::Int, i2::Int, m::Int, cgap::Int, cinc::Int, nc::Int, msk8::UInt64) diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 4f224bf47afcf..828faeab77ced 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -107,7 +107,7 @@ isequal(a::NamedTuple, b::NamedTuple) = false _nt_names(::NamedTuple{names}) where {names} = names _nt_names(::Type{T}) where {names,T<:NamedTuple{names}} = names -hash(x::NamedTuple, h::UInt) = xor(object_id(_nt_names(x)), hash(Tuple(x), h)) +hash(x::NamedTuple, h::UInt) = bitxor(object_id(_nt_names(x)), hash(Tuple(x), h)) isless(a::NamedTuple{n}, b::NamedTuple{n}) where {n} = isless(Tuple(a), Tuple(b)) # TODO: case where one argument's names are a prefix of the other's diff --git a/base/random/RNGs.jl b/base/random/RNGs.jl index 1f830f0f5e696..8335fa861a96e 100644 --- a/base/random/RNGs.jl +++ b/base/random/RNGs.jl @@ -246,9 +246,9 @@ end function rand(r::MersenneTwister, ::Type{UInt128}) reserve(r, 3) - xor(rand_ui52_raw_inbounds(r) % UInt128 << 96, - rand_ui52_raw_inbounds(r) % UInt128 << 48, - rand_ui52_raw_inbounds(r)) + bitxor(rand_ui52_raw_inbounds(r) % UInt128 << 96, + rand_ui52_raw_inbounds(r) % UInt128 << 48, + rand_ui52_raw_inbounds(r)) end rand(r::MersenneTwister, ::Type{Int64}) = reinterpret(Int64, rand(r, UInt64)) diff --git a/base/random/dSFMT.jl b/base/random/dSFMT.jl index 977db0d42b7b5..91ecc1876f303 100644 --- a/base/random/dSFMT.jl +++ b/base/random/dSFMT.jl @@ -165,10 +165,10 @@ function dsfmt_jump_next_state!(mts::Vector{UInt64}) t1 = mts[a+1] L0 = mts[u] L1 = mts[u+1] - mts[u] = xor(t0 << SL1, L1 >> 32, L1 << 32, mts[b]) - mts[u+1] = xor(t1 << SL1, L0 >> 32, L0 << 32, mts[b+1]) - mts[a] = xor(mts[u] >> SR, bitand(mts[u], MSK1), t0) - mts[a+1] = xor(mts[u+1] >> SR, bitand(mts[u+1], MSK2), t1) + mts[u] = bitxor(t0 << SL1, L1 >> 32, L1 << 32, mts[b]) + mts[u+1] = bitxor(t1 << SL1, L0 >> 32, L0 << 32, mts[b+1]) + mts[a] = bitxor(mts[u] >> SR, bitand(mts[u], MSK1), t0) + mts[a+1] = bitxor(mts[u+1] >> SR, bitand(mts[u+1], MSK2), t1) mts[end] = (mts[end] + 2) % (N*2) return mts From c9b645bcf3a49fd9e44b1a191c170400c171841f Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Sun, 17 Dec 2017 21:52:25 -0800 Subject: [PATCH 16/17] touchup --- base/atomics.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/atomics.jl b/base/atomics.jl index 33cdf7821441f..3f6beeac9458e 100644 --- a/base/atomics.jl +++ b/base/atomics.jl @@ -180,7 +180,7 @@ function atomic_sub! end Atomically bitwise-and `x` with `val` -Performs `x[] = bitand(x[]mval` atomically. Returns the **old** value. +Performs `x[] = bitand(x[], mval)` atomically. Returns the **old** value. For further details, see LLVM's `atomicrmw and` instruction. From 062ad1491beb99f746abc2757210a112db44c52c Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Mon, 18 Dec 2017 17:24:59 -0800 Subject: [PATCH 17/17] bitX -> X sed --- base/atomics.jl | 8 +- base/bitarray.jl | 222 ++++++++++++------------ base/bitset.jl | 6 +- base/bool.jl | 8 +- base/c.jl | 40 ++--- base/char.jl | 2 +- base/checked.jl | 4 +- base/codevalidation.jl | 2 +- base/deprecated.jl | 74 ++++---- base/dict.jl | 12 +- base/exports.jl | 6 +- base/file.jl | 12 +- base/float.jl | 126 +++++++------- base/gmp.jl | 12 +- base/grisu/bignum.jl | 4 +- base/grisu/bignums.jl | 44 ++--- base/grisu/fastfixed.jl | 6 +- base/grisu/fastprecision.jl | 4 +- base/grisu/fastshortest.jl | 4 +- base/grisu/float.jl | 20 +-- base/hashing.jl | 4 +- base/hashing2.jl | 18 +- base/inference.jl | 20 +-- base/int.jl | 72 ++++---- base/intfuncs.jl | 6 +- base/io.jl | 18 +- base/libc.jl | 2 +- base/libdl.jl | 8 +- base/libgit2/callbacks.jl | 6 +- base/libgit2/consts.jl | 2 +- base/libgit2/libgit2.jl | 2 +- base/libgit2/utils.jl | 6 +- base/libgit2/walker.jl | 2 +- base/linalg/bitarray.jl | 36 ++-- base/math.jl | 40 ++--- base/multidimensional.jl | 16 +- base/namedtuple.jl | 2 +- base/nullable.jl | 4 +- base/operators.jl | 10 +- base/pcre.jl | 10 +- base/printf.jl | 14 +- base/process.jl | 12 +- base/promotion.jl | 6 +- base/random/RNGs.jl | 12 +- base/random/dSFMT.jl | 10 +- base/random/generation.jl | 16 +- base/random/misc.jl | 30 ++-- base/random/normal.jl | 4 +- base/reflection.jl | 8 +- base/regex.jl | 26 +-- base/repl/LineEdit.jl | 2 +- base/serialize.jl | 8 +- base/show.jl | 4 +- base/socket.jl | 28 +-- base/special/exp.jl | 4 +- base/special/exp10.jl | 4 +- base/special/gamma.jl | 2 +- base/special/log.jl | 26 +-- base/special/rem_pio2.jl | 24 +-- base/special/trig.jl | 12 +- base/stat.jl | 28 +-- base/strings/io.jl | 2 +- base/strings/search.jl | 14 +- base/strings/string.jl | 50 +++--- base/strings/utf8proc.jl | 38 ++-- base/strings/util.jl | 2 +- base/subarray.jl | 2 +- base/sysinfo.jl | 2 +- base/twiceprecision.jl | 2 +- base/util.jl | 4 +- base/version.jl | 4 +- stdlib/Base64/src/decode.jl | 12 +- stdlib/Base64/src/encode.jl | 12 +- stdlib/FileWatching/src/FileWatching.jl | 24 +-- stdlib/Mmap/src/Mmap.jl | 20 +-- stdlib/SharedArrays/src/SharedArrays.jl | 12 +- test/TestHelpers.jl | 4 +- test/arrayops.jl | 6 +- test/bigint.jl | 38 ++-- test/bitarray.jl | 26 +-- test/core.jl | 4 +- test/fastmath.jl | 2 +- test/file.jl | 46 ++--- test/int.jl | 6 +- test/linalg/generic.jl | 2 +- test/nullable.jl | 2 +- test/numbers.jl | 24 +-- test/operators.jl | 4 +- test/perf/kernel/ziggurat.jl | 4 +- test/perf/shootout/mandelbrot.jl | 2 +- test/perf/shootout/meteor_contest.jl | 20 +-- test/random.jl | 2 +- test/ranges.jl | 6 +- test/read.jl | 2 +- test/reduce.jl | 10 +- test/reducedim.jl | 2 +- test/serialize.jl | 6 +- test/show.jl | 16 +- test/sorting.jl | 2 +- test/sparse/sparse.jl | 16 +- 100 files changed, 816 insertions(+), 816 deletions(-) diff --git a/base/atomics.jl b/base/atomics.jl index 3f6beeac9458e..7778db8cb2947 100644 --- a/base/atomics.jl +++ b/base/atomics.jl @@ -180,7 +180,7 @@ function atomic_sub! end Atomically bitwise-and `x` with `val` -Performs `x[] = bitand(x[], mval)` atomically. Returns the **old** value. +Performs `x[] and= mval` atomically. Returns the **old** value. For further details, see LLVM's `atomicrmw and` instruction. @@ -203,7 +203,7 @@ function atomic_and! end Atomically bitwise-nand (not-and) `x` with `val` -Performs `x[] = bitnot(bitand(x[], val))` atomically. Returns the **old** value. +Performs `x[] = not(and(x[], val))` atomically. Returns the **old** value. For further details, see LLVM's `atomicrmw nand` instruction. @@ -226,7 +226,7 @@ function atomic_nand! end Atomically bitwise-or `x` with `val` -Performs `x[] = bitor(x[], val)` atomically. Returns the **old** value. +Performs `x[] or= val` atomically. Returns the **old** value. For further details, see LLVM's `atomicrmw or` instruction. @@ -249,7 +249,7 @@ function atomic_or! end Atomically bitwise-xor (exclusive-or) `x` with `val` -Performs `x[] = bitxor(x[], val)` atomically. Returns the **old** value. +Performs `x[] xor= val` atomically. Returns the **old** value. For further details, see LLVM's `atomicrmw xor` instruction. diff --git a/base/bitarray.jl b/base/bitarray.jl index 1155ac7c82d7e..0d71cf3c06474 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -79,9 +79,9 @@ IndexStyle(::Type{<:BitArray}) = IndexLinear() ## aux functions ## -const _msk64 = bitnot(UInt64(0)) +const _msk64 = not(UInt64(0)) @inline _div64(l) = l >>> 6 -@inline _mod64(l) = bitand(l, 63) +@inline _mod64(l) = and(l, 63) @inline _msk_end(l::Integer) = _msk64 >>> _mod64(-l) @inline _msk_end(B::BitArray) = _msk_end(length(B)) num_bit_chunks(n::Int) = _div64(n+63) @@ -96,7 +96,7 @@ function _check_bitarray_consistency(B::BitArray{N}) where N nc = length(Bc) nc == num_bit_chunks(n) || (warn("incorrect chunks length for length $n: expected=$(num_bit_chunks(n)) actual=$nc"); return false) n == 0 && return true - bitand(Bc[end], _msk_end(n)) == Bc[end] || (warn("nonzero bits in chunk after BitArray end"); return false) + and(Bc[end], _msk_end(n)) == Bc[end] || (warn("nonzero bits in chunk after BitArray end"); return false) return true end @@ -104,10 +104,10 @@ end function glue_src_bitchunks(src::Vector{UInt64}, k::Int, ks1::Int, msk_s0::UInt64, ls0::Int) @inbounds begin - chunk = bitand(src[k], msk_s0) >>> ls0 + chunk = and(src[k], msk_s0) >>> ls0 if ks1 > k && ls0 > 0 - chunk_n = bitand(src[k + 1], bitnot(msk_s0)) - chunk = bitor(chunk, chunk_n << (64 - ls0)) + chunk_n = and(src[k + 1], not(msk_s0)) + chunk or= chunk_n << (64 - ls0) end end return chunk @@ -129,27 +129,27 @@ function copy_chunks!(dest::Vector{UInt64}, pos_d::Integer, src::Vector{UInt64}, u = _msk64 if delta_kd == 0 - msk_d0 = bitor(bitnot(u << ld0), u << (ld1+1)) + msk_d0 = or(not(u << ld0), u << (ld1+1)) else - msk_d0 = bitnot(u << ld0) + msk_d0 = not(u << ld0) msk_d1 = (u << (ld1+1)) end if delta_ks == 0 - msk_s0 = bitand(u << ls0, bitnot(u << (ls1+1))) + msk_s0 = and(u << ls0, not(u << (ls1+1))) else msk_s0 = (u << ls0) end chunk_s0 = glue_src_bitchunks(src, ks0, ks1, msk_s0, ls0) - dest[kd0] = bitor(bitand(dest[kd0], msk_d0), bitand(chunk_s0 << ld0, bitnot(msk_d0))) + dest[kd0] = or(and(dest[kd0], msk_d0), and(chunk_s0 << ld0, not(msk_d0))) delta_kd == 0 && return for i = 1 : kd1 - kd0 - 1 chunk_s1 = glue_src_bitchunks(src, ks0 + i, ks1, msk_s0, ls0) - chunk_s = bitor(chunk_s0 >>> (64 - ld0), chunk_s1 << ld0) + chunk_s = or(chunk_s0 >>> (64 - ld0), chunk_s1 << ld0) dest[kd0 + i] = chunk_s @@ -162,9 +162,9 @@ function copy_chunks!(dest::Vector{UInt64}, pos_d::Integer, src::Vector{UInt64}, chunk_s1 = UInt64(0) end - chunk_s = bitor(chunk_s0 >>> (64 - ld0), chunk_s1 << ld0) + chunk_s = or(chunk_s0 >>> (64 - ld0), chunk_s1 << ld0) - dest[kd1] = bitor(bitand(dest[kd1], msk_d1), bitand(chunk_s, bitnot(msk_d1))) + dest[kd1] = or(and(dest[kd1], msk_d1), and(chunk_s, not(msk_d1))) return end @@ -189,24 +189,24 @@ function copy_chunks_rtol!(chunks::Vector{UInt64}, pos_d::Integer, pos_s::Intege delta_ks = ks1 - ks0 if delta_kd == 0 - msk_d0 = bitor(bitnot(u << ld0), u << (ld1+1)) + msk_d0 = or(not(u << ld0), u << (ld1+1)) else - msk_d0 = bitnot(u << ld0) + msk_d0 = not(u << ld0) msk_d1 = (u << (ld1+1)) end if delta_ks == 0 - msk_s0 = bitand(u << ls0, bitnot(u << (ls1+1))) + msk_s0 = and(u << ls0, not(u << (ls1+1))) else msk_s0 = (u << ls0) end - chunk_s0 = bitand(glue_src_bitchunks(chunks, ks0, ks1, msk_s0, ls0), bitnot(u << s)) - chunks[kd0] = bitor(bitand(chunks[kd0], msk_d0), bitand(chunk_s0 << ld0, bitnot(msk_d0))) + chunk_s0 = and(glue_src_bitchunks(chunks, ks0, ks1, msk_s0, ls0), not(u << s)) + chunks[kd0] = or(and(chunks[kd0], msk_d0), and(chunk_s0 << ld0, not(msk_d0))) if delta_kd != 0 chunk_s = (chunk_s0 >>> (64 - ld0)) - chunks[kd1] = bitor(bitand(chunks[kd1], msk_d1), bitand(chunk_s, bitnot(msk_d1))) + chunks[kd1] = or(and(chunks[kd1], msk_d1), and(chunk_s, not(msk_d1))) end left -= s @@ -224,23 +224,23 @@ function fill_chunks!(Bc::Array{UInt64}, x::Bool, pos::Integer, numbits::Integer u = _msk64 if k1 == k0 - msk0 = bitand(u << l0, bitnot(u << (l1+1))) + msk0 = and(u << l0, not(u << (l1+1))) else msk0 = (u << l0) - msk1 = bitnot(u << (l1+1)) + msk1 = not(u << (l1+1)) end @inbounds if x - Bc[k0] = bitor(Bc[k0], msk0) + Bc[k0] or= msk0 for k = k0+1:k1-1 Bc[k] = u end - k1 > k0 && (Bc[k1] = bitor(Bc[k1], msk1)) + k1 > k0 && (Bc[k1] or= msk1) else - Bc[k0] = bitand(Bc[k0], bitnot(msk0)) + Bc[k0] and= not(msk0) for k = k0+1:k1-1 Bc[k] = 0 end - k1 > k0 && (Bc[k1] = bitand(Bc[k1], bitnot(msk1))) + k1 > k0 && (Bc[k1] and= not(msk1)) end end @@ -250,10 +250,10 @@ copy_to_bitarray_chunks!(dest::Vector{UInt64}, pos_d::Int, src::BitArray, pos_s: # pack 8 Bools encoded as one contiguous UIn64 into a single byte, e.g.: # 0000001:0000001:00000000:00000000:00000001:00000000:00000000:00000001 → 11001001 → 0xc9 function pack8bools(z::UInt64) - z = bitor(z, z >>> 7) - z = bitor(z, z >>> 14) - z = bitor(z, z >>> 28) - z = bitand(z, 0xFF) + z or= z >>> 7 + z or= z >>> 14 + z or= z >>> 28 + z and= 0xFF return z end @@ -265,10 +265,10 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} u = _msk64 if delta_kd == 0 - msk_d0 = msk_d1 = bitor(bitnot(u << ld0), u << (ld1+1)) + msk_d0 = msk_d1 = or(not(u << ld0), u << (ld1+1)) lt0 = ld1 else - msk_d0 = bitnot(u << ld0) + msk_d0 = not(u << ld0) msk_d1 = (u << (ld1+1)) lt0 = 63 end @@ -278,10 +278,10 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} @inbounds if ld0 > 0 c = UInt64(0) for j = ld0:lt0 - c = bitor(c, UInt64(C[ind]) << j) + c or= UInt64(C[ind]) << j ind += 1 end - Bc[kd0] = bitor(bitand(Bc[kd0], msk_d0), bitand(c, bitnot(msk_d0))) + Bc[kd0] = or(and(Bc[kd0], msk_d0), and(c, not(msk_d0))) bind += 1 end @@ -294,7 +294,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} c = UInt64(0) for j = 0:7 # unaligned load - c = bitor(c, pack8bools(unsafe_load(P8, ind8)) << (j<<3)) + c or= pack8bools(unsafe_load(P8, ind8)) << (j<<3) ind8 += 1 end Bc[bind] = c @@ -305,7 +305,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} @inbounds for i = (nc8+1):nc c = UInt64(0) for j = 0:63 - c = bitor(c, UInt64(C[ind]) << j) + c or= UInt64(C[ind]) << j ind += 1 end Bc[bind] = c @@ -315,10 +315,10 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::Array{Bool} @assert bind == kd1 c = UInt64(0) for j = 0:ld1 - c = bitor(c, UInt64(C[ind]) << j) + c or= UInt64(C[ind]) << j ind += 1 end - Bc[kd1] = bitor(bitand(Bc[kd1], msk_d1), bitand(c, bitnot(msk_d1))) + Bc[kd1] = or(and(Bc[kd1], msk_d1), and(c, not(msk_d1))) end end @@ -336,7 +336,7 @@ dumpbitcache(Bc::Vector{UInt64}, bind::Int, C::Vector{Bool}) = ## custom iterator ## start(B::BitArray) = 0 -next(B::BitArray, i::Int) = !iszero(bitand(B.chunks[_div64(i)+1], UInt64(1) << _mod64(i))), i+1 +next(B::BitArray, i::Int) = !iszero(and(B.chunks[_div64(i)+1], UInt64(1) << _mod64(i))), i+1 done(B::BitArray, i::Int) = i >= length(B) ## similar, fill!, copy! etc ## @@ -358,7 +358,7 @@ function fill!(B::BitArray, x) fill!(Bc, 0) else fill!(Bc, _msk64) - Bc[end] = bitand(Bc[end], _msk_end(B)) + Bc[end] and= _msk_end(B) end return B end @@ -456,8 +456,8 @@ function copy!(dest::BitArray, src::BitArray) destc[nc] = srcc[nc] else msk_s = _msk_end(src) - msk_d = bitnot(msk_s) - destc[nc] = bitor(bitand(msk_d, destc[nc]), bitand(msk_s, srcc[nc])) + msk_d = not(msk_s) + destc[nc] = or(and(msk_d, destc[nc]), and(msk_s, srcc[nc])) end end return dest @@ -521,14 +521,14 @@ function convert(::Type{BitArray{N}}, A::AbstractArray{T,N}) where N where T for i = 1:length(Bc)-1 c = UInt64(0) for j = 0:63 - c = bitor(c, UInt64(convert(Bool, A[ind])) << j) + c or= UInt64(convert(Bool, A[ind])) << j ind += 1 end Bc[i] = c end c = UInt64(0) for j = 0:_mod64(l-1) - c = bitor(c, UInt64(convert(Bool, A[ind])) << j) + c or= UInt64(convert(Bool, A[ind])) << j ind += 1 end Bc[end] = c @@ -672,7 +672,7 @@ end @inline function unsafe_bitgetindex(Bc::Vector{UInt64}, i::Int) i1, i2 = get_chunks_id(i) u = UInt64(1) << i2 - @inbounds r = bitand(Bc[i1], u) != 0 + @inbounds r = and(Bc[i1], u) != 0 return r end @@ -688,7 +688,7 @@ end u = UInt64(1) << i2 @inbounds begin c = Bc[i1] - Bc[i1] = ifelse(x, bitor(c, u), bitand(c, bitnot(u))) + Bc[i1] = ifelse(x, or(c, u), and(c, not(u))) end end @@ -726,11 +726,11 @@ function _unsafe_setindex!(B::BitArray, x, I::BitArray) length(Bc) == length(Ic) || throw_boundserror(B, I) @inbounds if y for i = 1:length(Bc) - Bc[i] = bitor(Bc[i], Ic[i]) + Bc[i] or= Ic[i] end else for i = 1:length(Bc) - Bc[i] = bitand(Bc[i], bitnot(Ic[i])) + Bc[i] and= not(Ic[i]) end end return B @@ -756,10 +756,10 @@ function _unsafe_setindex!(B::BitArray, X::AbstractArray, I::BitArray) @inbounds C = Bc[i] u = UInt64(1) for j = 1:(i < lc ? 64 : last_chunk_len) - if bitand(Imsk, u) != 0 + if and(Imsk, u) != 0 lx < c && throw_setindex_mismatch(X, c) @inbounds x = convert(Bool, X[c]) - C = ifelse(x, bitor(C, u), bitand(C, bitnot(u))) + C = ifelse(x, or(C, u), and(C, not(u))) c += 1 end u <<= 1 @@ -883,9 +883,9 @@ function unshift!(B::BitVector, item) return B end for i = length(Bc) : -1 : 2 - Bc[i] = bitor(Bc[i] << 1, Bc[i-1] >>> 63) + Bc[i] = or(Bc[i] << 1, Bc[i-1] >>> 63) end - Bc[1] = bitor(UInt64(item), Bc[1] << 1) + Bc[1] = or(UInt64(item), Bc[1] << 1) return B end @@ -897,7 +897,7 @@ function shift!(B::BitVector) Bc = B.chunks for i = 1 : length(Bc) - 1 - Bc[i] = bitor(Bc[i] >>> 1, Bc[i+1] << 63) + Bc[i] = or(Bc[i] >>> 1, Bc[i+1] << 63) end l = _mod64(length(B)) @@ -929,12 +929,12 @@ function insert!(B::BitVector, i::Integer, item) B.len += 1 for t = length(Bc) : -1 : k + 1 - Bc[t] = bitor(Bc[t] << 1, Bc[t - 1] >>> 63) + Bc[t] = or(Bc[t] << 1, Bc[t - 1] >>> 63) end msk_aft = (_msk64 << j) - msk_bef = bitnot(msk_aft) - Bc[k] = bitor(bitand(msk_bef, Bc[k]), bitand(msk_aft, Bc[k]) << 1) + msk_bef = not(msk_aft) + Bc[k] = or(and(msk_bef, Bc[k]), and(msk_aft, Bc[k]) << 1) B[i] = item B end @@ -943,19 +943,19 @@ function _deleteat!(B::BitVector, i::Integer) k, j = get_chunks_id(i) msk_bef = _msk64 >>> (63 - j) - msk_aft = bitnot(msk_bef) + msk_aft = not(msk_bef) msk_bef >>>= 1 Bc = B.chunks @inbounds begin - Bc[k] = bitor(bitand(msk_bef, Bc[k]), bitand(msk_aft, Bc[k]) >> 1) + Bc[k] = or(and(msk_bef, Bc[k]), and(msk_aft, Bc[k]) >> 1) if length(Bc) > k - Bc[k] = bitor(Bc[k], Bc[k + 1] << 63) + Bc[k] or= Bc[k + 1] << 63 end for t = k + 1 : length(Bc) - 1 - Bc[t] = bitor(Bc[t] >>> 1, Bc[t + 1] << 63) + Bc[t] = or(Bc[t] >>> 1, Bc[t + 1] << 63) end l = _mod64(length(B)) @@ -997,7 +997,7 @@ function deleteat!(B::BitVector, r::UnitRange{Int}) B.len = new_l if new_l > 0 - Bc[end] = bitand(Bc[end], _msk_end(new_l)) + Bc[end] and= _msk_end(new_l) end return B @@ -1035,7 +1035,7 @@ function deleteat!(B::BitVector, inds) B.len = new_l if new_l > 0 - Bc[end] = bitand(Bc[end], _msk_end(new_l)) + Bc[end] = and(Bc[end], _msk_end(new_l)) end return B @@ -1087,7 +1087,7 @@ function splice!(B::BitVector, r::Union{UnitRange{Int}, Integer}, ins::AbstractA B.len = new_l if new_l > 0 - Bc[end] = bitand(Bc[end], _msk_end(new_l)) + Bc[end] and= _msk_end(new_l) end return v @@ -1122,7 +1122,7 @@ function (-)(B::BitArray) u = UInt64(1) c = Bc[i] for j = 1:64 - if bitand(c, u) != 0 + if and(c, u) != 0 A[ind] = -1 end ind += 1 @@ -1132,7 +1132,7 @@ function (-)(B::BitArray) u = UInt64(1) c = Bc[end] for j = 0:_mod64(l-1) - if bitand(c, u) != 0 + if and(c, u) != 0 A[ind] = -1 end ind += 1 @@ -1142,15 +1142,15 @@ function (-)(B::BitArray) end broadcast(::typeof(sign), B::BitArray) = copy(B) -function broadcast(::typeof(bitnot), B::BitArray) +function broadcast(::typeof(not), B::BitArray) C = similar(B) Bc = B.chunks if !isempty(Bc) Cc = C.chunks for i = 1:length(Bc) - Cc[i] = bitnot(Bc[i]) + Cc[i] = not(Bc[i]) end - Cc[end] = bitand(Cc[end], _msk_end(B)) + Cc[end] and= _msk_end(B) end return C end @@ -1158,7 +1158,7 @@ end """ flipbits!(B::BitArray{N}) -> BitArray{N} -Performs a bitwise not operation on `B`. See [`bitnot`](@ref). +Performs a bitwise not operation on `B`. See [`not`](@ref). # Examples ```jldoctest @@ -1177,9 +1177,9 @@ function flipbits!(B::BitArray) Bc = B.chunks @inbounds if !isempty(Bc) for i = 1:length(Bc) - Bc[i] = bitnot(Bc[i]) + Bc[i] = not(Bc[i]) end - Bc[end] = bitand(Bc[end], _msk_end(B)) + Bc[end] and= _msk_end(B) end return B end @@ -1216,7 +1216,7 @@ broadcast(::typeof(&), B::BitArray, x::Bool) = x ? copy(B) : falses(size(B)) broadcast(::typeof(&), x::Bool, B::BitArray) = broadcast(&, B, x) broadcast(::typeof(|), B::BitArray, x::Bool) = x ? trues(size(B)) : copy(B) broadcast(::typeof(|), x::Bool, B::BitArray) = broadcast(|, B, x) -broadcast(::typeof(xor), B::BitArray, x::Bool) = x ? bitnot.(B) : copy(B) +broadcast(::typeof(xor), B::BitArray, x::Bool) = x ? not.(B) : copy(B) broadcast(::typeof(xor), x::Bool, B::BitArray) = broadcast(xor, B, x) for f in (:&, :|, :xor) @eval begin @@ -1229,7 +1229,7 @@ for f in (:&, :|, :xor) for i = 1:length(Fc) Fc[i] = ($f)(Ac[i], Bc[i]) end - Fc[end] = bitand(Fc[end], _msk_end(F)) + Fc[end] and= _msk_end(F) return F end broadcast(::typeof($f), A::DenseArray{Bool}, B::BitArray) = broadcast($f, BitArray(A), B) @@ -1302,12 +1302,12 @@ end function reverse_bits(src::UInt64) z = src - z = bitor(bitand(z >>> 1, 0x5555555555555555), bitand(z << 1, 0xaaaaaaaaaaaaaaaa)) - z = bitor(bitand(z >>> 2, 0x3333333333333333), bitand(z << 2, 0xcccccccccccccccc)) - z = bitor(bitand(z >>> 4, 0x0f0f0f0f0f0f0f0f), bitand(z << 4, 0xf0f0f0f0f0f0f0f0)) - z = bitor(bitand(z >>> 8, 0x00ff00ff00ff00ff), bitand(z << 8, 0xff00ff00ff00ff00)) - z = bitor(bitand(z >>> 16, 0x0000ffff0000ffff), bitand(z << 16, 0xffff0000ffff0000)) - return bitor(bitand(z >>> 32, 0x00000000ffffffff), bitand(z << 32, 0xffffffff00000000)) + z = or(and(z >>> 1, 0x5555555555555555), and(z << 1, 0xaaaaaaaaaaaaaaaa)) + z = or(and(z >>> 2, 0x3333333333333333), and(z << 2, 0xcccccccccccccccc)) + z = or(and(z >>> 4, 0x0f0f0f0f0f0f0f0f), and(z << 4, 0xf0f0f0f0f0f0f0f0)) + z = or(and(z >>> 8, 0x00ff00ff00ff00ff), and(z << 8, 0xff00ff00ff00ff00)) + z = or(and(z >>> 16, 0x0000ffff0000ffff), and(z << 16, 0xffff0000ffff0000)) + return or(and(z >>> 32, 0x00000000ffffffff), and(z << 32, 0xffffffff00000000)) end function reverse!(B::BitVector) @@ -1342,8 +1342,8 @@ function reverse!(B::BitVector) end u = reverse_bits(B.chunks[i]) B.chunks[i] = 0 - B.chunks[j] = bitor(B.chunks[j], u >>> h) - B.chunks[i] = bitor(B.chunks[i], v >>> h) + B.chunks[j] or= u >>> h + B.chunks[i] or= v >>> h j -= 1 if i == j @@ -1351,14 +1351,14 @@ function reverse!(B::BitVector) end v = reverse_bits(B.chunks[j]) B.chunks[j] = 0 - B.chunks[i] = bitor(B.chunks[i], v << k) - B.chunks[j] = bitor(B.chunks[j], u << k) + B.chunks[i] or= v << k + B.chunks[j] or= u << k end if isodd(length(B.chunks)) - B.chunks[i] = bitor(B.chunks[i], v >>> h) + B.chunks[i] or= v >>> h else - B.chunks[i] = bitor(B.chunks[i], u << k) + B.chunks[i] or= u << k end return B @@ -1508,8 +1508,8 @@ function findnext(B::BitArray, start::Integer) mask = _msk64 << within_chunk_start @inbounds begin - if bitand(Bc[chunk_start], mask) != 0 - return (chunk_start-1) << 6 + trailing_zeros(bitand(Bc[chunk_start], mask)) + 1 + if and(Bc[chunk_start], mask) != 0 + return (chunk_start-1) << 6 + trailing_zeros(and(Bc[chunk_start], mask)) + 1 end for i = chunk_start+1:length(Bc) @@ -1522,7 +1522,7 @@ function findnext(B::BitArray, start::Integer) end #findfirst(B::BitArray) = findnext(B, 1) ## defined in array.jl -# aux function: same as findnext(bitnot(B), start), but performed without temporaries +# aux function: same as findnext(not(B), start), but performed without temporaries function findnextnot(B::BitArray, start::Integer) start > 0 || throw(BoundsError(B, start)) start > length(B) && return 0 @@ -1533,11 +1533,11 @@ function findnextnot(B::BitArray, start::Integer) chunk_start = _div64(start-1)+1 within_chunk_start = _mod64(start-1) - mask = bitnot(_msk64 << within_chunk_start) + mask = not(_msk64 << within_chunk_start) @inbounds if chunk_start < l - if bitor(Bc[chunk_start], mask) != _msk64 - return (chunk_start-1) << 6 + trailing_ones(bitor(Bc[chunk_start], mask)) + 1 + if or(Bc[chunk_start], mask) != _msk64 + return (chunk_start-1) << 6 + trailing_ones(or(Bc[chunk_start], mask)) + 1 end for i = chunk_start+1:l-1 if Bc[i] != _msk64 @@ -1547,8 +1547,8 @@ function findnextnot(B::BitArray, start::Integer) if Bc[l] != _msk_end(B) return (l-1) << 6 + trailing_ones(Bc[l]) + 1 end - elseif bitor(Bc[l], mask) != _msk_end(B) - return (l-1) << 6 + trailing_ones(bitor(Bc[l], mask)) + 1 + elseif or(Bc[l], mask) != _msk_end(B) + return (l-1) << 6 + trailing_ones(or(Bc[l], mask)) + 1 end return 0 end @@ -1587,8 +1587,8 @@ function findprev(B::BitArray, start::Integer) mask = _msk_end(start) @inbounds begin - if bitand(Bc[chunk_start], mask) != 0 - return (chunk_start-1) << 6 + (64 - leading_zeros(bitand(Bc[chunk_start], mask))) + if and(Bc[chunk_start], mask) != 0 + return (chunk_start-1) << 6 + (64 - leading_zeros(and(Bc[chunk_start], mask))) end for i = (chunk_start-1):-1:1 @@ -1607,11 +1607,11 @@ function findprevnot(B::BitArray, start::Integer) Bc = B.chunks chunk_start = _div64(start-1)+1 - mask = bitnot(_msk_end(start)) + mask = not(_msk_end(start)) @inbounds begin - if bitor(Bc[chunk_start], mask) != _msk64 - return (chunk_start-1) << 6 + (64 - leading_ones(bitor(Bc[chunk_start], mask))) + if or(Bc[chunk_start], mask) != _msk64 + return (chunk_start-1) << 6 + (64 - leading_ones(or(Bc[chunk_start], mask))) end for i = chunk_start-1:-1:1 @@ -1658,7 +1658,7 @@ function find(B::BitArray) u = UInt64(1) c = Bc[i] for j = 1:64 - if bitand(c, u) != 0 + if and(c, u) != 0 I[Icount] = Bcount Icount += 1 end @@ -1669,7 +1669,7 @@ function find(B::BitArray) u = UInt64(1) c = Bc[end] for j = 0:_mod64(l-1) - if bitand(c, u) != 0 + if and(c, u) != 0 I[Icount] = Bcount Icount += 1 end @@ -1738,24 +1738,24 @@ maximum(B::BitArray) = isempty(B) ? throw(ArgumentError("argument must be non-em # arrays since there can be a 64x speedup by working at the level of Int64 # instead of looping bit-by-bit. -map(::Union{typeof(bitnot), typeof(!)}, A::BitArray) = bit_map!(bitnot, similar(A), A) +map(::Union{typeof(not), typeof(!)}, A::BitArray) = bit_map!(not, similar(A), A) map(::typeof(zero), A::BitArray) = fill!(similar(A), false) map(::typeof(one), A::BitArray) = fill!(similar(A), true) map(::typeof(identity), A::BitArray) = copy(A) -map!(::Union{typeof(bitnot), typeof(!)}, dest::BitArray, A::BitArray) = bit_map!(bitnot, dest, A) +map!(::Union{typeof(not), typeof(!)}, dest::BitArray, A::BitArray) = bit_map!(not, dest, A) map!(::typeof(zero), dest::BitArray, A::BitArray) = fill!(dest, false) map!(::typeof(one), dest::BitArray, A::BitArray) = fill!(dest, true) map!(::typeof(identity), dest::BitArray, A::BitArray) = copy!(dest, A) for (T, f) in ((:(Union{typeof(&), typeof(*), typeof(min)}), :(&)), (:(Union{typeof(|), typeof(max)}), :(|)), - (:(Union{typeof(xor), typeof(!=)}), :bitxor), - (:(Union{typeof(>=), typeof(^)}), :((p, q) -> bitor(p, bitnot(q)))), - (:(typeof(<=)), :((p, q) -> bitor(bitnot(p), q))), - (:(typeof(==)), :((p, q) -> bitnot(bitxor(p, q)))), - (:(typeof(<)), :((p, q) -> bitand(bitnot(p), q))), - (:(typeof(>)), :((p, q) -> bitand(p, bitnot(q))))) + (:(Union{typeof(xor), typeof(!=)}), :xor), + (:(Union{typeof(>=), typeof(^)}), :((p, q) -> or(p, not(q)))), + (:(typeof(<=)), :((p, q) -> or(not(p), q))), + (:(typeof(==)), :((p, q) -> not(xor(p, q)))), + (:(typeof(<)), :((p, q) -> and(not(p), q))), + (:(typeof(>)), :((p, q) -> and(p, not(q))))) @eval map(::$T, A::BitArray, B::BitArray) = bit_map!($f, similar(A), A, B) @eval map!(::$T, dest::BitArray, A::BitArray, B::BitArray) = bit_map!($f, dest, A, B) end @@ -1771,7 +1771,7 @@ function bit_map!(f::F, dest::BitArray, A::BitArray) where F for i = 1:(length(Ac)-1) destc[i] = f(Ac[i]) end - destc[end] = bitand(f(Ac[end]), _msk_end(A)) + destc[end] = and(f(Ac[end]), _msk_end(A)) dest end function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F @@ -1783,7 +1783,7 @@ function bit_map!(f::F, dest::BitArray, A::BitArray, B::BitArray) where F for i = 1:(length(Ac)-1) destc[i] = f(Ac[i], Bc[i]) end - destc[end] = bitand(f(Ac[end], Bc[end]), _msk_end(A)) + destc[end] = and(f(Ac[end], Bc[end]), _msk_end(A)) dest end @@ -1889,8 +1889,8 @@ function read!(s::IO, B::BitArray) n = length(B) Bc = B.chunks nc = length(read!(s, Bc)) - if length(Bc) > 0 && bitand(Bc[end], _msk_end(n)) ≠ Bc[end] - Bc[end] = bitand(Bc[end], _msk_end(n)) # ensure that the BitArray is not broken + if length(Bc) > 0 && and(Bc[end], _msk_end(n)) ≠ Bc[end] + Bc[end] and= _msk_end(n) # ensure that the BitArray is not broken throw(DimensionMismatch("read mismatch, found non-zero bits after BitArray length")) end return B diff --git a/base/bitset.jl b/base/bitset.jl index 016de396b4f91..25d5ec1f2b331 100644 --- a/base/bitset.jl +++ b/base/bitset.jl @@ -116,7 +116,7 @@ union(s1::BitSet, ss::BitSet...) = union(s1, union(ss...)) union(s::BitSet, ns) = union!(copy(s), ns) union!(s::BitSet, ns) = (for n in ns; push!(s, n); end; s) function union!(s1::BitSet, s2::BitSet) - _matched_map!(bitor, s1.bits, s2.bits) + _matched_map!(or, s1.bits, s2.bits) s1 end @@ -138,14 +138,14 @@ Intersects sets `s1` and `s2` and overwrites the set `s1` with the result. If ne will be expanded to the size of `s2`. """ function intersect!(s1::BitSet, s2::BitSet) - _matched_map!(bitand, s1.bits, s2.bits) + _matched_map!(and, s1.bits, s2.bits) s1 end setdiff(s::BitSet, ns) = setdiff!(copy(s), ns) setdiff!(s::BitSet, ns) = (for n in ns; delete!(s, n); end; s) function setdiff!(s1::BitSet, s2::BitSet) - _matched_map!((p, q) -> bitand(p, bitnot(q)), s1.bits, s2.bits) + _matched_map!((p, q) -> and(p, not(q)), s1.bits, s2.bits) s1 end diff --git a/base/bool.jl b/base/bool.jl index c04125bc5514e..b109229a03c56 100644 --- a/base/bool.jl +++ b/base/bool.jl @@ -38,10 +38,10 @@ function !(x::Bool) return not_int(x) end -bitnot(x::Bool) = !x -bitand(x::Bool, y::Bool) = and_int(x, y) -bitor(x::Bool, y::Bool) = or_int(x, y) -bitxor(x::Bool, y::Bool) = (x != y) +not(x::Bool) = !x +and(x::Bool, y::Bool) = and_int(x, y) +or(x::Bool, y::Bool) = or_int(x, y) +xor(x::Bool, y::Bool) = (x != y) (&)(x::Bool, y::Bool) = and_int(x, y) (|)(x::Bool, y::Bool) = or_int(x, y) diff --git a/base/c.jl b/base/c.jl index 80eb2edd90a0e..004109ea973eb 100644 --- a/base/c.jl +++ b/base/c.jl @@ -225,24 +225,24 @@ function transcode(::Type{UInt16}, src::Vector{UInt8}) push!(dst, a) a = b; continue elseif a < 0xe0 # 2-byte UTF-8 - push!(dst, bitxor(0x3080, UInt16(a) << 6, b)) + push!(dst, xor(0x3080, UInt16(a) << 6, b)) elseif i < n # 3/4-byte character c = src[i += 1] if -64 <= (c % Int8) # invalid UTF-8 (non-continuation) push!(dst, a, b) a = c; continue elseif a < 0xf0 # 3-byte UTF-8 - push!(dst, bitxor(0x2080, UInt16(a) << 12, UInt16(b) << 6, c)) + push!(dst, xor(0x2080, UInt16(a) << 12, UInt16(b) << 6, c)) elseif i < n d = src[i += 1] if -64 <= (d % Int8) # invalid UTF-8 (non-continuation) push!(dst, a, b, c) a = d; continue elseif a == 0xf0 && b < 0x90 # overlong encoding - push!(dst, bitxor(0x2080, UInt16(b) << 12, UInt16(c) << 6, d)) + push!(dst, xor(0x2080, UInt16(b) << 12, UInt16(c) << 6, d)) else # 4-byte UTF-8 push!(dst, 0xe5b8 + (UInt16(a) << 8) + (UInt16(b) << 2) + (c >> 4), - bitxor(0xdc80, UInt16(bitand(c, 0xf)) << 6, d)) + xor(0xdc80, UInt16(and(c, 0xf)) << 6, d)) end else # too short push!(dst, a, b, c) @@ -278,9 +278,9 @@ function transcode(::Type{UInt8}, src::Vector{UInt16}) m += 1 elseif a < 0x800 # 2-byte UTF-8 m += 2 - elseif bitand(a, 0xfc00) == 0xd800 && i < length(src) + elseif and(a, 0xfc00) == 0xd800 && i < length(src) b = src[i += 1] - if bitand(b, 0xfc00) == 0xdc00 # 2-unit UTF-16 sequence => 4-byte UTF-8 + if and(b, 0xfc00) == 0xdc00 # 2-unit UTF-16 sequence => 4-byte UTF-8 m += 4 else m += 3 @@ -302,29 +302,29 @@ function transcode(::Type{UInt8}, src::Vector{UInt16}) if a < 0x80 # ASCII dst[j += 1] = a % UInt8 elseif a < 0x800 # 2-byte UTF-8 - dst[j += 1] = bitor(0xc0, (a >> 6) % UInt8) - dst[j += 1] = bitor(0x80, bitand(a % UInt8, 0x3f)) - elseif bitand(a, 0xfc00) == 0xd800 && i < n + dst[j += 1] = or(0xc0, (a >> 6) % UInt8) + dst[j += 1] = or(0x80, and(a % UInt8, 0x3f)) + elseif and(a, 0xfc00) == 0xd800 && i < n b = src[i += 1] - if bitand(b, 0xfc00) == 0xdc00 + if and(b, 0xfc00) == 0xdc00 # 2-unit UTF-16 sequence => 4-byte UTF-8 a += 0x2840 - dst[j += 1] = bitor(0xf0, (a >> 8) % UInt8) - dst[j += 1] = bitor(0x80, (a % UInt8) >> 2) - dst[j += 1] = bitxor(0xf0, bitand((a % UInt8) << 4, 0x3f), (b >> 6) % UInt8) - dst[j += 1] = bitor(0x80, bitand(b % UInt8, 0x3f)) + dst[j += 1] = or(0xf0, (a >> 8) % UInt8) + dst[j += 1] = or(0x80, (a % UInt8) >> 2) + dst[j += 1] = xor(0xf0, and((a % UInt8) << 4, 0x3f), (b >> 6) % UInt8) + dst[j += 1] = or(0x80, and(b % UInt8, 0x3f)) else - dst[j += 1] = bitor(0xe0, (a >> 12) % UInt8) - dst[j += 1] = bitor(0x80, bitand((a >> 6) % UInt8, 0x3f)) - dst[j += 1] = bitor(0x80, bitand(a % UInt8, 0x3f)) + dst[j += 1] = or(0xe0, (a >> 12) % UInt8) + dst[j += 1] = or(0x80, and((a >> 6) % UInt8, 0x3f)) + dst[j += 1] = or(0x80, and(a % UInt8, 0x3f)) a = b; continue end else # 1-unit high UTF-16 or unpaired high surrogate # either way, encode as 3-byte UTF-8 code point - dst[j += 1] = bitor(0xe0, (a >> 12) % UInt8) - dst[j += 1] = bitor(0x80, bitand((a >> 6) % UInt8, 0x3f)) - dst[j += 1] = bitor(0x80, bitand(a % UInt8, 0x3f)) + dst[j += 1] = or(0xe0, (a >> 12) % UInt8) + dst[j += 1] = or(0x80, and((a >> 6) % UInt8, 0x3f)) + dst[j += 1] = or(0x80, and(a % UInt8, 0x3f)) end i < n || break a = src[i += 1] diff --git a/base/char.jl b/base/char.jl index 0c184e1e990ab..e884227e1ac5d 100644 --- a/base/char.jl +++ b/base/char.jl @@ -71,7 +71,7 @@ function show(io::IO, c::Char) write(io, 0x27, 0x5c, c <= '\x7f' ? 0x78 : c <= '\uffff' ? 0x75 : 0x55) d = max(2, 8 - (leading_zeros(u) >> 2)) while 0 < d - write(io, hex_chars[bitand(u >> ((d -= 1) << 2), 0xf) + 1]) + write(io, hex_chars[and(u >> ((d -= 1) << 2), 0xf) + 1]) end write(io, 0x27) end diff --git a/base/checked.jl b/base/checked.jl index 650fc58654a9d..f7f8a494558a2 100644 --- a/base/checked.jl +++ b/base/checked.jl @@ -148,8 +148,8 @@ end if BrokenUnsignedInt != Union{} function add_with_overflow(x::T, y::T) where T<:BrokenUnsignedInt # x + y > typemax(T) - # Note: bitnot(y) == -y-1 - x + y, x > bitnot(y) + # Note: not(y) == -y-1 + x + y, x > not(y) end end diff --git a/base/codevalidation.jl b/base/codevalidation.jl index b7ca04916c553..14e3cfd2ba9e3 100644 --- a/base/codevalidation.jl +++ b/base/codevalidation.jl @@ -146,4 +146,4 @@ function is_valid_rvalue(x) return !isa(x, GotoNode) && !isa(x, LabelNode) && !isa(x, LineNumberNode) end -is_flag_set(byte::UInt8, flag::UInt8) = bitand(byte, flag) == flag +is_flag_set(byte::UInt8, flag::UInt8) = and(byte, flag) == flag diff --git a/base/deprecated.jl b/base/deprecated.jl index 4741155b10ced..55a6331d29651 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -2084,43 +2084,43 @@ end @deprecate parse(str::AbstractString, pos::Int, ; kwargs...) Meta.parse(str, pos; kwargs...) @deprecate_binding ParseError Meta.ParseError -@deprecate (~)(x::BitInteger) bitnot(x) -@deprecate (~)(n::Integer) bitnot(x) -@deprecate (~)(x::BigInt) bitnot(x) -@deprecate (~)(x::Bool) bitnot(x) - -@deprecate (|)(a::BigInt, b::BigInt) bitor(a, b) -@deprecate (|)(a::BigInt, b::BigInt, c::BigInt) bitor(a, b, c) -@deprecate (|)(a::BigInt, b::BigInt, c::BigInt, d::BigInt) bitor(a, b, c, d) -@deprecate (|)(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) bitor(a, b, c, d, e) - -@deprecate (|)(x::Integer) bitor(x) -@deprecate (|)(a::Integer, b::Integer) bitor(a, b) -@deprecate (|)(x::T, y::T) where {T<:Integer} bitor(x, y) -@deprecate (|)(x::T, y::T) where {T<:BitInteger} bitor(x, y) -@deprecate (|)(a, b, c, xs...) bitor(a, b, c, xs...) - -@deprecate (&)(x::BigInt, y::BigInt) bitand(x, y) -@deprecate (&)(a::BigInt, b::BigInt, c::BigInt) bitand(a, b, c) -@deprecate (&)(a::BigInt, b::BigInt, c::BigInt, d::BigInt) bitand(a, b, c, d) -@deprecate (&)(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) bitand(a, b, c, d, e) - -@deprecate (&)(x::Integer) bitand(x) -@deprecate (&)(a::Integer, b::Integer) bitand(a, b) -@deprecate (&)(x::T, y::T) where {T<:Integer} bitand(x, y) -@deprecate (&)(x::T, y::T) where {T<:BitInteger} bitand(x, y) -@deprecate (&)(a, b, c, xs...) bitand(a, b, c, xs...) - -@deprecate xor(x::BigInt, y::BigInt) bitxor(x, y) -@deprecate xor(a::BigInt, b::BigInt, c::BigInt) bitxor(a, b, c) -@deprecate xor(a::BigInt, b::BigInt, c::BigInt, d::BigInt) bitxor(a, b, c, d) -@deprecate xor(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) bitxor(a, b, c, d, e) - -@deprecate xor(x::Integer) bitxor(x) -@deprecate xor(a::Integer, b::Integer) bitxor(a, b) -@deprecate xor(x::T, y::T) where {T<:Integer} bitxor(x, y) -@deprecate xor(x::T, y::T) where {T<:BitInteger} bitxor(x, y) -@deprecate xor(a, b, c, xs...) bitxor(a, b, c, xs...) +@deprecate (~)(x::BitInteger) not(x) +@deprecate (~)(n::Integer) not(x) +@deprecate (~)(x::BigInt) not(x) +@deprecate (~)(x::Bool) not(x) + +@deprecate (|)(a::BigInt, b::BigInt) or(a, b) +@deprecate (|)(a::BigInt, b::BigInt, c::BigInt) or(a, b, c) +@deprecate (|)(a::BigInt, b::BigInt, c::BigInt, d::BigInt) or(a, b, c, d) +@deprecate (|)(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) or(a, b, c, d, e) + +@deprecate (|)(x::Integer) or(x) +@deprecate (|)(a::Integer, b::Integer) or(a, b) +@deprecate (|)(x::T, y::T) where {T<:Integer} or(x, y) +@deprecate (|)(x::T, y::T) where {T<:BitInteger} or(x, y) +@deprecate (|)(a, b, c, xs...) or(a, b, c, xs...) + +@deprecate (&)(x::BigInt, y::BigInt) and(x, y) +@deprecate (&)(a::BigInt, b::BigInt, c::BigInt) and(a, b, c) +@deprecate (&)(a::BigInt, b::BigInt, c::BigInt, d::BigInt) and(a, b, c, d) +@deprecate (&)(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) and(a, b, c, d, e) + +@deprecate (&)(x::Integer) and(x) +@deprecate (&)(a::Integer, b::Integer) and(a, b) +@deprecate (&)(x::T, y::T) where {T<:Integer} and(x, y) +@deprecate (&)(x::T, y::T) where {T<:BitInteger} and(x, y) +@deprecate (&)(a, b, c, xs...) and(a, b, c, xs...) + +@deprecate xor(x::BigInt, y::BigInt) xor(x, y) +@deprecate xor(a::BigInt, b::BigInt, c::BigInt) xor(a, b, c) +@deprecate xor(a::BigInt, b::BigInt, c::BigInt, d::BigInt) xor(a, b, c, d) +@deprecate xor(a::BigInt, b::BigInt, c::BigInt, d::BigInt, e::BigInt) xor(a, b, c, d, e) + +@deprecate xor(x::Integer) xor(x) +@deprecate xor(a::Integer, b::Integer) xor(a, b) +@deprecate xor(x::T, y::T) where {T<:Integer} xor(x, y) +@deprecate xor(x::T, y::T) where {T<:BitInteger} xor(x, y) +@deprecate xor(a, b, c, xs...) xor(a, b, c, xs...) # #24258 # Physical units define an equivalence class: there is no such thing as a step of "1" (is diff --git a/base/dict.jl b/base/dict.jl index d72fa24f6d281..15d2dbf54a567 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -207,7 +207,7 @@ function convert(::Type{Dict{K,V}},d::Associative) where V where K end convert(::Type{Dict{K,V}},d::Dict{K,V}) where {K,V} = d -hashindex(key, sz) = (bitand(hash(key) % Int, sz - 1) + 1)::Int +hashindex(key, sz) = (and(hash(key) % Int, sz - 1) + 1)::Int @propagate_inbounds isslotempty(h::Dict, i::Int) = h.slots[i] == 0x0 @propagate_inbounds isslotfilled(h::Dict, i::Int) = h.slots[i] == 0x1 @@ -243,9 +243,9 @@ function rehash!(h::Dict{K,V}, newsz = length(h.keys)) where V where K v = oldv[i] index0 = index = hashindex(k, newsz) while slots[index] != 0 - index = bitand(index, newsz - 1) + 1 + index = and(index, newsz - 1) + 1 end - probe = bitand(index - index0, newsz - 1) + probe = and(index - index0, newsz - 1) probe > maxprobe && (maxprobe = probe) slots[index] = 0x1 keys[index] = k @@ -336,7 +336,7 @@ function ht_keyindex(h::Dict{K,V}, key) where V where K return index end - index = bitand(index, sz - 1) + 1 + index = and(index, sz - 1) + 1 iter += 1 iter > maxprobe && break end @@ -373,7 +373,7 @@ function ht_keyindex2(h::Dict{K,V}, key) where V where K return index end - index = bitand(index, sz - 1) + 1 + index = and(index, sz - 1) + 1 iter += 1 iter > maxprobe && break end @@ -387,7 +387,7 @@ function ht_keyindex2(h::Dict{K,V}, key) where V where K h.maxprobe = iter return -index end - index = bitand(index, sz - 1) + 1 + index = and(index, sz - 1) + 1 iter += 1 end diff --git a/base/exports.jl b/base/exports.jl index 1ed977cf15b8a..9e09d94e335eb 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -215,9 +215,9 @@ export ^, |, |>, - bitand, - bitor, - bitnot, + and, + or, + not, :, =>, ∘, diff --git a/base/file.jl b/base/file.jl index 63e778f3b52ee..d8fb09eb6bc57 100644 --- a/base/file.jl +++ b/base/file.jl @@ -138,7 +138,7 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false) try @static if Sys.iswindows() # is writable on windows actually means "is deletable" - if bitand(filemode(path), 0o222) == 0 + if and(filemode(path), 0o222) == 0 chmod(path, 0o777) end end @@ -245,7 +245,7 @@ end Update the last-modified timestamp on a file to the current time. """ function touch(path::AbstractString) - f = open(path, bitor(JL_O_WRONLY, JL_O_CREAT), 0o0666) + f = open(path, or(JL_O_WRONLY, JL_O_CREAT), 0o0666) try t = time() futime(f,t,t) @@ -287,7 +287,7 @@ end function mktempdir(parent=tempdir()) seed::UInt32 = rand(UInt32) while true - if bitand(seed, typemax(UInt16)) == 0 + if and(seed, typemax(UInt16)) == 0 seed += 1 end filename = tempname(parent, seed) @@ -520,8 +520,8 @@ function sendfile(src::AbstractString, dst::AbstractString) try src_file = open(src, JL_O_RDONLY) src_open = true - dst_file = open(dst, bitor(JL_O_CREAT, JL_O_TRUNC, JL_O_WRONLY), - bitor(S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, S_IWOTH)) + dst_file = open(dst, or(JL_O_CREAT, JL_O_TRUNC, JL_O_WRONLY), + or(S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, S_IWOTH)) dst_open = true bytes = filesize(stat(src_file)) @@ -558,7 +558,7 @@ function symlink(p::AbstractString, np::AbstractString) flags = 0 @static if Sys.iswindows() if isdir(p) - flags = bitor(flags, UV_FS_SYMLINK_JUNCTION) + flags or= UV_FS_SYMLINK_JUNCTION p = abspath(p) end end diff --git a/base/float.jl b/base/float.jl index e81d78802930c..27e0eb3f71a2d 100644 --- a/base/float.jl +++ b/base/float.jl @@ -78,11 +78,11 @@ function convert(::Type{Float64}, x::UInt128) x == 0 && return 0.0 n = 128-leading_zeros(x) # ndigits0z(x,2) if n <= 53 - y = bitand((x % UInt64) << (53-n), 0x000f_ffff_ffff_ffff) + y = and((x % UInt64) << (53-n), 0x000f_ffff_ffff_ffff) else - y = bitand((x >> (n-54)) % UInt64, 0x001f_ffff_ffff_ffff) # keep 1 extra bit + y = and((x >> (n-54)) % UInt64, 0x001f_ffff_ffff_ffff) # keep 1 extra bit y = (y+1)>>1 # round, ties up (extra leading bit in case of next exponent) - y = bitand(y, bitnot(UInt64(trailing_zeros(x) == (n-54)))) # fix last bit to round to even + y and= not(UInt64(trailing_zeros(x) == (n-54))) # fix last bit to round to even end d = ((n+1022) % UInt64) << 52 reinterpret(Float64, d + y) @@ -90,29 +90,29 @@ end function convert(::Type{Float64}, x::Int128) x == 0 && return 0.0 - s = bitand((x >>> 64) % UInt64, 0x8000_0000_0000_0000) # sign bit + s = and((x >>> 64) % UInt64, 0x8000_0000_0000_0000) # sign bit x = abs(x) % UInt128 n = 128-leading_zeros(x) # ndigits0z(x,2) if n <= 53 - y = bitand((x % UInt64) << (53-n), 0x000f_ffff_ffff_ffff) + y = and((x % UInt64) << (53-n), 0x000f_ffff_ffff_ffff) else - y = bitand((x >> (n-54)) % UInt64, 0x001f_ffff_ffff_ffff) # keep 1 extra bit + y = and((x >> (n-54)) % UInt64, 0x001f_ffff_ffff_ffff) # keep 1 extra bit y = (y+1)>>1 # round, ties up (extra leading bit in case of next exponent) - y = bitand(y, bitnot(UInt64(trailing_zeros(x) == (n-54)))) # fix last bit to round to even + y and= not(UInt64(trailing_zeros(x) == (n-54))) # fix last bit to round to even end d = ((n+1022) % UInt64) << 52 - reinterpret(Float64, bitor(s, d) + y) + reinterpret(Float64, or(s, d) + y) end function convert(::Type{Float32}, x::UInt128) x == 0 && return 0f0 n = 128-leading_zeros(x) # ndigits0z(x,2) if n <= 24 - y = bitand(((x % UInt32) << (24-n), 0x007f_ffff) + y = and(((x % UInt32) << (24-n), 0x007f_ffff) else - y = bitand(((x >> (n-25)) % UInt32, 0x00ff_ffff) # keep 1 extra bit + y = and(((x >> (n-25)) % UInt32, 0x00ff_ffff) # keep 1 extra bit y = (y+one(UInt32))>>1 # round, ties up (extra leading bit in case of next exponent) - y = bitand(y, bitnot(UInt32(trailing_zeros(x) == (n-25)))) # fix last bit to round to even + y and= not(UInt32(trailing_zeros(x) == (n-25))) # fix last bit to round to even end d = ((n+126) % UInt32) << 23 reinterpret(Float32, d + y) @@ -120,37 +120,37 @@ end function convert(::Type{Float32}, x::Int128) x == 0 && return 0f0 - s = bitand((x >>> 96) % UInt32, 0x8000_0000) # sign bit + s = and((x >>> 96) % UInt32, 0x8000_0000) # sign bit x = abs(x) % UInt128 n = 128-leading_zeros(x) # ndigits0z(x,2) if n <= 24 - y = bitand((x % UInt32) << (24-n), 0x007f_ffff) + y = and((x % UInt32) << (24-n), 0x007f_ffff) else - y = bitand((x >> (n-25)) % UInt32, 0x00ff_ffff) # keep 1 extra bit + y = and((x >> (n-25)) % UInt32, 0x00ff_ffff) # keep 1 extra bit y = (y+one(UInt32))>>1 # round, ties up (extra leading bit in case of next exponent) - y = bitand(y, bitnot(UInt32(trailing_zeros(x) == (n-25)))) # fix last bit to round to even + y and= not(UInt32(trailing_zeros(x) == (n-25))) # fix last bit to round to even end d = ((n+126) % UInt32) << 23 - reinterpret(Float32, bitor(s, d) + y) + reinterpret(Float32, or(s, d) + y) end function convert(::Type{Float16}, val::Float32) f = reinterpret(UInt32, val) if isnan(val) - t = 0x8000 ⊻ bitand(0x8000, (f >> 0x10) % UInt16) + t = 0x8000 ⊻ and(0x8000, (f >> 0x10) % UInt16) return reinterpret(Float16, t ⊻ ((f >> 0xd) % UInt16)) end - i = bitand(f >> 23, 0x1ff) + 1 + i = and(f >> 23, 0x1ff) + 1 sh = shifttable[i] - f = bitand(f, 0x007fffff) + f and= 0x007fffff h::UInt16 = basetable[i] + (f >> sh) # round # NOTE: we maybe should ignore NaNs here, but the payload is # getting truncated anyway so "rounding" it might not matter - nextbit = bitand(f >> (sh-1), 1) + nextbit = and(f >> (sh-1), 1) if nextbit != 0 # Round halfway to even or check lower bits - if bitand(h, 1) == 1 || bitand(f, (1 << (sh-1)) - 1) != 0 + if and(h, 1) == 1 || and(f, (1 << (sh-1)) - 1) != 0 h += 1 end end @@ -159,26 +159,26 @@ end function convert(::Type{Float32}, val::Float16) local ival::UInt32 = reinterpret(UInt16, val) - local sign::UInt32 = bitand(ival, 0x8000) >> 15 - local exp::UInt32 = bitand(ival, 0x7c00) >> 10 - local sig::UInt32 = bitand(ival, 0x3ff) >> 0 + local sign::UInt32 = and(ival, 0x8000) >> 15 + local exp::UInt32 = and(ival, 0x7c00) >> 10 + local sig::UInt32 = and(ival, 0x3ff) >> 0 local ret::UInt32 if exp == 0 if sig == 0 sign = sign << 31 - ret = bitor(sign, exp, sig) + ret = or(sign, exp, sig) else n_bit = 1 bit = 0x0200 - while bitand(bit, sig) == 0 + while and(bit, sig) == 0 n_bit = n_bit + 1 bit = bit >> 1 end sign = sign << 31 exp = (-14 - n_bit + 127) << 23 - sig = (bitand(sig, bitnot(bit)) << n_bit) << (23 - 10) - ret = bitor(sign, exp, sig) + sig = (and(sig, not(bit)) << n_bit) << (23 - 10) + ret = or(sign, exp, sig) end elseif exp == 0x1f if sig == 0 # Inf @@ -188,13 +188,13 @@ function convert(::Type{Float32}, val::Float16) ret = 0xff800000 end else # NaN - ret = bitor(0x7fc00000, sign << 31, sig << (23-10)) + ret = or(0x7fc00000, sign << 31, sig << (23-10)) end else sign = sign << 31 exp = (exp - 15 + 127) << 23 sig = sig << (23 - 10) - ret = bitor(sign, exp, sig) + ret = or(sign, exp, sig) end return reinterpret(Float32, ret) end @@ -209,30 +209,30 @@ const shifttable = Vector{UInt8}(512) for i = 0:255 e = i - 127 if e < -24 # Very small numbers map to zero - basetable[bitor(i, 0x000) + 1] = 0x0000 - basetable[bitor(i, 0x100) + 1] = 0x8000 - shifttable[bitor(i, 0x000) + 1] = 24 - shifttable[bitor(i, 0x100) + 1] = 24 + basetable[or(i, 0x000) + 1] = 0x0000 + basetable[or(i, 0x100) + 1] = 0x8000 + shifttable[or(i, 0x000) + 1] = 24 + shifttable[or(i, 0x100) + 1] = 24 elseif e < -14 # Small numbers map to denorms - basetable[bitor(i, 0x000) + 1] = (0x0400>>(-e-14)) - basetable[bitor(i, 0x100) + 1] = bitor(0x0400>>(-e-14), 0x8000) - shifttable[bitor(i, 0x000) + 1] = -e-1 - shifttable[bitor(i, 0x100) + 1] = -e-1 + basetable[or(i, 0x000) + 1] = (0x0400>>(-e-14)) + basetable[or(i, 0x100) + 1] = or(0x0400>>(-e-14), 0x8000) + shifttable[or(i, 0x000) + 1] = -e-1 + shifttable[or(i, 0x100) + 1] = -e-1 elseif e <= 15 # Normal numbers just lose precision - basetable[bitor(i, 0x000) + 1] = ((e+15)<<10) - basetable[bitor(i, 0x100) + 1] = bitor((e+15)<<10, 0x8000) - shifttable[bitor(i, 0x000) + 1] = 13 - shifttable[bitor(i, 0x100) + 1] = 13 + basetable[or(i, 0x000) + 1] = ((e+15)<<10) + basetable[or(i, 0x100) + 1] = or((e+15)<<10, 0x8000) + shifttable[or(i, 0x000) + 1] = 13 + shifttable[or(i, 0x100) + 1] = 13 elseif e < 128 # Large numbers map to Infinity - basetable[bitor(i, 0x000) + 1] = 0x7C00 - basetable[bitor(i, 0x100) + 1] = 0xFC00 - shifttable[bitor(i, 0x000) + 1] = 24 - shifttable[bitor(i, 0x100) + 1] = 24 + basetable[or(i, 0x000) + 1] = 0x7C00 + basetable[or(i, 0x100) + 1] = 0xFC00 + shifttable[or(i, 0x000) + 1] = 24 + shifttable[or(i, 0x100) + 1] = 24 else # Infinity and NaN's stay Infinity and NaN's - basetable[bitor(i, 0x000) + 1] = 0x7C00 - basetable[bitor(i, 0x100) + 1] = 0xFC00 - shifttable[bitor(i, 0x000) + 1] = 13 - shifttable[bitor(i, 0x100) + 1] = 13 + basetable[or(i, 0x000) + 1] = 0x7C00 + basetable[or(i, 0x100) + 1] = 0xFC00 + shifttable[or(i, 0x000) + 1] = 13 + shifttable[or(i, 0x100) + 1] = 13 end end #convert(::Type{Float16}, x::Float32) = fptrunc(Float16, x) @@ -306,8 +306,8 @@ end function unsafe_trunc(::Type{UInt128}, x::Float64) xu = reinterpret(UInt64,x) - k = bitand(Int(xu >> 52), 0x07ff) - 1075 - xu = bitor(bitand(xu, 0x000f_ffff_ffff_ffff), 0x0010_0000_0000_0000) + k = and(Int(xu >> 52), 0x07ff) - 1075 + xu = or(and(xu, 0x000f_ffff_ffff_ffff), 0x0010_0000_0000_0000) if k <= 0 UInt128(xu >> -k) else @@ -320,8 +320,8 @@ end function unsafe_trunc(::Type{UInt128}, x::Float32) xu = reinterpret(UInt32,x) - k = bitand(Int(xu >> 23), 0x00ff) - 150 - xu = bitor(bitand(xu, 0x007f_ffff), 0x0080_0000) + k = and(Int(xu >> 23), 0x00ff) - 150 + xu = or(and(xu, 0x007f_ffff), 0x0080_0000) if k <= 0 UInt128(xu >> -k) else @@ -432,10 +432,10 @@ end function ==(x::Float16, y::Float16) ix = reinterpret(UInt16,x) iy = reinterpret(UInt16,y) - if bitand(bitor(ix, iy), 0x7fff) > 0x7c00 #isnan(x) || isnan(y) + if and(or(ix, iy), 0x7fff) > 0x7c00 #isnan(x) || isnan(y) return false end - if bitand(bitor(ix, iy), 0x7fff) == 0x0000 + if and(or(ix, iy), 0x7fff) == 0x0000 return true end return ix == iy @@ -526,7 +526,7 @@ end <=(x::Union{Int32,UInt32}, y::Float32) = Float64(x)<=Float64(y) -abs(x::Float16) = reinterpret(Float16, bitand(reinterpret(UInt16, x), 0x7fff)) +abs(x::Float16) = reinterpret(Float16, and(reinterpret(UInt16, x), 0x7fff)) abs(x::Float32) = abs_float(x) abs(x::Float64) = abs_float(x) @@ -536,7 +536,7 @@ abs(x::Float64) = abs_float(x) Test whether a floating point number is not a number (NaN). """ isnan(x::AbstractFloat) = x != x -isnan(x::Float16) = bitand(reinterpret(UInt16,x), 0x7fff) > 0x7c00 +isnan(x::Float16) = and(reinterpret(UInt16,x), 0x7fff) > 0x7c00 isnan(x::Real) = false """ @@ -553,7 +553,7 @@ false ``` """ isfinite(x::AbstractFloat) = x - x == 0 -isfinite(x::Float16) = bitand(reinterpret(UInt16,x), 0x7c00) != 0x7c00 +isfinite(x::Float16) = and(reinterpret(UInt16,x), 0x7c00) != 0x7c00 isfinite(x::Real) = decompose(x)[3] != 0 isfinite(x::Integer) = true @@ -615,7 +615,7 @@ function nextfloat(f::IEEEFloat, d::Integer) isnan(f) && return f fi = reinterpret(Signed, f) fneg = fi < 0 - fu = unsigned(bitand(fi, typemax(fi))) + fu = unsigned(and(fi, typemax(fi))) dneg = d < 0 da = uabs(d) @@ -640,7 +640,7 @@ function nextfloat(f::IEEEFloat, d::Integer) end end if fneg - fu = bitor(fu, sign_mask(F)) + fu or= sign_mask(F) end reinterpret(F, fu) end @@ -715,7 +715,7 @@ Test whether a floating point number is subnormal. """ function issubnormal(x::T) where {T<:IEEEFloat} y = reinterpret(Unsigned, x) - iszero(bitand(y, exponent_mask(T))) & !iszero(bitand(y, significand_mask(T))) + iszero(and(y, exponent_mask(T))) & !iszero(and(y, significand_mask(T))) end @eval begin @@ -870,7 +870,7 @@ uinttype(::Type{Float64}) = UInt64 uinttype(::Type{Float32}) = UInt32 uinttype(::Type{Float16}) = UInt16 -Base.iszero(x::Float16) = bitand(reinterpret(UInt16, x), bitnot(sign_mask(Float16))) == 0x0000 +Base.iszero(x::Float16) = and(reinterpret(UInt16, x), not(sign_mask(Float16))) == 0x0000 ## Array operations on floating point numbers ## diff --git a/base/gmp.jl b/base/gmp.jl index 40946545e9a4c..a16f82bbed2c4 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -4,7 +4,7 @@ module GMP export BigInt -import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, bitnot, bitand, bitor, bitxor, +import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, not, and, or, xor, binomial, cmp, convert, div, divrem, factorial, fld, gcd, gcdx, lcm, mod, ndigits, promote_rule, rem, show, isqrt, string, powermod, sum, trailing_zeros, trailing_ones, count_ones, base, tryparse_internal, @@ -288,7 +288,7 @@ function convert(::Type{BigInt}, x::Integer) b = BigInt(0) shift = 0 while x < -1 - b += BigInt(bitnot(UInt32(bitand(x, 0xffffffff)))) << shift + b += BigInt(not(UInt32(and(x, 0xffffffff)))) << shift x >>= 32 shift += 32 end @@ -300,7 +300,7 @@ function convert(::Type{BigInt}, x::Integer) b = BigInt(0) shift = 0 while x > 0 - b += BigInt(UInt32(bitand(x, 0xffffffff))) << shift + b += BigInt(UInt32(and(x, 0xffffffff))) << shift x >>>= 32 shift += 32 end @@ -405,7 +405,7 @@ big(::Type{<:Rational}) = Rational{BigInt} for (fJ, fC) in ((:+, :add), (:-,:sub), (:*, :mul), (:fld, :fdiv_q), (:div, :tdiv_q), (:mod, :fdiv_r), (:rem, :tdiv_r), (:gcd, :gcd), (:lcm, :lcm), - (:bitand, :and), (:bitor, :ior), (:bitxor, :xor)) + (:and, :and), (:or, :ior), (:xor, :xor)) @eval begin ($fJ)(x::BigInt, y::BigInt) = MPZ.$fC(x, y) end @@ -433,7 +433,7 @@ function invmod(x::BigInt, y::BigInt) end # More efficient commutative operations -for (fJ, fC) in ((:+, :add), (:*, :mul), (:bitand, :and), (:bitor, :ior), (:bitxor, :xor)) +for (fJ, fC) in ((:+, :add), (:*, :mul), (:and, :and), (:or, :ior), (:xor, :xor)) fC! = Symbol(fC, :!) @eval begin ($fJ)(a::BigInt, b::BigInt, c::BigInt) = MPZ.$fC!(MPZ.$fC(a, b), c) @@ -465,7 +465,7 @@ end # unary ops (-)(x::BigInt) = MPZ.neg(x) -bitnot(x::BigInt) = MPZ.com(x) +not(x::BigInt) = MPZ.com(x) <<(x::BigInt, c::UInt) = c == 0 ? x : MPZ.mul_2exp(x, c) >>(x::BigInt, c::UInt) = c == 0 ? x : MPZ.fdiv_q_2exp(x, c) diff --git a/base/grisu/bignum.jl b/base/grisu/bignum.jl index 71cff5af13ff1..9dcbdae06e6ad 100644 --- a/base/grisu/bignum.jl +++ b/base/grisu/bignum.jl @@ -30,7 +30,7 @@ function normalizedexponent(significand, exponent::Int32) significand = UInt64(significand) - while bitand(significand, HiddenBit(Float64)) == 0 + while and(significand, HiddenBit(Float64)) == 0 significand <<= UInt64(1) exponent -= Int32(1) end @@ -43,7 +43,7 @@ function bignumdtoa(v,mode,requested_digits::Int,buffer,bignums) lower_boundary_is_closer = lowerboundaryiscloser(v) need_boundary_deltas = mode == SHORTEST - is_even = bitand(significand, 1) == 0 + is_even = and(significand, 1) == 0 normalized_exponent = normalizedexponent(significand, exponent) estimated_power = estimatepower(Int(normalized_exponent)) diff --git a/base/grisu/bignums.jl b/base/grisu/bignums.jl index 302a8d5e068a6..89badc9b49b1f 100644 --- a/base/grisu/bignums.jl +++ b/base/grisu/bignums.jl @@ -116,7 +116,7 @@ function bigitshiftleft!(x::Bignum,shift_amount) @inbounds begin for i = 1:x.used_digits new_carry::Chunk = x.bigits[i] >> (kBigitSize - shift_amount) - x.bigits[i] = bitand((x.bigits[i] << shift_amount) + carry, kBigitMask) + x.bigits[i] = and((x.bigits[i] << shift_amount) + carry, kBigitMask) carry = new_carry end if carry != 0 @@ -140,14 +140,14 @@ function subtracttimes!(x::Bignum,other::Bignum,factor) for i = 1:other.used_digits product::DoubleChunk = DoubleChunk(factor) * other.bigits[i] remove::DoubleChunk = borrow + product - difference::Chunk = (x.bigits[i+exponent_diff] - bitand(remove, kBigitMask)) % Chunk - x.bigits[i+exponent_diff] = bitand(difference, kBigitMask) + difference::Chunk = (x.bigits[i+exponent_diff] - and(remove, kBigitMask)) % Chunk + x.bigits[i+exponent_diff] = and(difference, kBigitMask) borrow = ((difference >> (kChunkSize - 1)) + (remove >> kBigitSize)) % Chunk end for i = (other.used_digits + exponent_diff + 1):x.used_digits borrow == 0 && return difference::Chunk = x.bigits[i] - borrow - x.bigits[i] = bitand(difference, kBigitMask) + x.bigits[i] = and(difference, kBigitMask) borrow = difference >> (kChunkSize - 1) end end @@ -168,7 +168,7 @@ function assignuint64!(x::Bignum,value::UInt64) value == 0 && return needed_bigits = div(kUInt64Size,kBigitSize) + 1 @inbounds for i = 1:needed_bigits - x.bigits[i] = bitand(value, kBigitMask) + x.bigits[i] = and(value, kBigitMask) value >>= kBigitSize end x.used_digits = needed_bigits @@ -202,13 +202,13 @@ function addbignum!(x::Bignum,other::Bignum) bigit_pos = other.exponent - x.exponent @inbounds for i = 1:other.used_digits sum::Chunk = x.bigits[bigit_pos+1] + other.bigits[i] + carry - x.bigits[bigit_pos+1] = bitand(sum, kBigitMask) + x.bigits[bigit_pos+1] = and(sum, kBigitMask) carry = sum >> kBigitSize bigit_pos += 1 end @inbounds while carry != 0 sum = x.bigits[bigit_pos+1] + carry - x.bigits[bigit_pos+1] = bitand(sum, kBigitMask) + x.bigits[bigit_pos+1] = and(sum, kBigitMask) carry = sum >> kBigitSize bigit_pos += 1 end @@ -223,13 +223,13 @@ function subtractbignum!(x::Bignum,other::Bignum) @inbounds begin for i = 1:other.used_digits difference = x.bigits[i+offset] - other.bigits[i] - borrow - x.bigits[i+offset] = bitand(difference, kBigitMask) + x.bigits[i+offset] = and(difference, kBigitMask) borrow = difference >> (kChunkSize - 1) end i = other.used_digits+1 while borrow != 0 difference = x.bigits[i+offset] - borrow - x.bigits[i+offset] = bitand(difference, kBigitMask) + x.bigits[i+offset] = and(difference, kBigitMask) borrow = difference >> (kChunkSize - 1) i += 1 end @@ -255,11 +255,11 @@ function multiplybyuint32!(x::Bignum,factor::UInt32) @inbounds begin for i = 1:x.used_digits product::DoubleChunk = (factor % DoubleChunk) * x.bigits[i] + carry - x.bigits[i] = bitand(product, kBigitMask) % Chunk + x.bigits[i] = and(product, kBigitMask) % Chunk carry = product >> kBigitSize end while carry != 0 - x.bigits[x.used_digits+1] = bitand(carry, kBigitMask) + x.bigits[x.used_digits+1] = and(carry, kBigitMask) x.used_digits += 1 carry >>= kBigitSize end @@ -274,19 +274,19 @@ function multiplybyuint64!(x::Bignum,factor::UInt64) return end carry::UInt64 = 0 - low::UInt64 = bitand(factor, 0xFFFFFFFF) + low::UInt64 = and(factor, 0xFFFFFFFF) high::UInt64 = factor >> 32 @inbounds begin for i = 1:x.used_digits product_low::UInt64 = low * x.bigits[i] product_high::UInt64 = high * x.bigits[i] - tmp::UInt64 = bitand(carry, kBigitMask) + product_low - x.bigits[i] = bitand(tmp, kBigitMask) + tmp::UInt64 = and(carry, kBigitMask) + product_low + x.bigits[i] = and(tmp, kBigitMask) carry = (carry >> kBigitSize) + (tmp >> kBigitSize) + (product_high << (32 - kBigitSize)) end while carry != 0 - x.bigits[x.used_digits+1] = bitand(carry, kBigitMask) + x.bigits[x.used_digits+1] = and(carry, kBigitMask) x.used_digits += 1 carry >>= kBigitSize end @@ -346,7 +346,7 @@ function square!(x::Bignum) bigit_index1 -= 1 bigit_index2 += 1 end - x.bigits[i] = bitand(accumulator % Chunk, kBigitMask) + x.bigits[i] = and(accumulator % Chunk, kBigitMask) accumulator >>= kBigitSize end for i = x.used_digits+1:product_length @@ -359,7 +359,7 @@ function square!(x::Bignum) bigit_index1 -= 1 bigit_index2 += 1 end - x.bigits[i] = bitand(accumulator % Chunk, kBigitMask) + x.bigits[i] = and(accumulator % Chunk, kBigitMask) accumulator >>= kBigitSize end end @@ -375,7 +375,7 @@ function assignpoweruint16!(x::Bignum,base::UInt16,power_exponent::Int) end zero!(x) shifts::Int = 0 - while bitand(base, UInt16(1)) == UInt16(0) + while and(base, UInt16(1)) == UInt16(0) base >>= UInt16(1) shifts += 1 end @@ -396,9 +396,9 @@ function assignpoweruint16!(x::Bignum,base::UInt16,power_exponent::Int) max_32bits::UInt64 = 0xFFFFFFFF while mask != 0 && this_value <= max_32bits this_value *= this_value - if bitand(power_exponent, mask) != 0 - base_bits_mask::UInt64 = bitnot(UInt64(1) << (64 - bit_size) - 1) - high_bits_zero = bitand(this_value, base_bits_mask) == 0 + if and(power_exponent, mask) != 0 + base_bits_mask::UInt64 = not(UInt64(1) << (64 - bit_size) - 1) + high_bits_zero = and(this_value, base_bits_mask) == 0 if high_bits_zero this_value *= base else @@ -411,7 +411,7 @@ function assignpoweruint16!(x::Bignum,base::UInt16,power_exponent::Int) delayed_multiplication && multiplybyuint32!(x,UInt32(base)) while mask != 0 square!(x) - bitand(power_exponent, mask) != 0 && multiplybyuint32!(x,UInt32(base)) + and(power_exponent, mask) != 0 && multiplybyuint32!(x,UInt32(base)) mask >>= 1 end shiftleft!(x,shifts * power_exponent) diff --git a/base/grisu/fastfixed.jl b/base/grisu/fastfixed.jl index de379c68e4ca4..347cd3cc79c45 100644 --- a/base/grisu/fastfixed.jl +++ b/base/grisu/fastfixed.jl @@ -118,7 +118,7 @@ function fillfractionals(fractionals, exponent, len += 1 fractionals -= UInt64(digit) << point end - if bitand(fractionals >> (point - 1), 1) == 1 + if and(fractionals >> (point - 1), 1) == 1 len, decimal_point = roundup(buffer, len, decimal_point) end else @@ -140,9 +140,9 @@ function fillfractionals(fractionals, exponent, return len, decimal_point end -low(x) = UInt64(bitand(x, 0xffffffffffffffff)) +low(x) = UInt64(and(x, 0xffffffffffffffff)) high(x) = UInt64(x >>> 64) -bitat(x::UInt128,y) = y >= 64 ? bitand(Int32(high(x) >> (y-64)), 1) : bitand(Int32(low(x) >> y), 1) +bitat(x::UInt128,y) = y >= 64 ? and(Int32(high(x) >> (y-64)), 1) : and(Int32(low(x) >> y), 1) function divrem2(x,power) h = high(x) l = low(x) diff --git a/base/grisu/fastprecision.jl b/base/grisu/fastprecision.jl index 02e27f2c75cd3..ade40f538add1 100644 --- a/base/grisu/fastprecision.jl +++ b/base/grisu/fastprecision.jl @@ -52,7 +52,7 @@ function digitgen(w,buffer,requested_digits=1000) unit::UInt64 = 1 one = Float(unit << -w.e, w.e) integrals = w.s >> -one.e - fractionals = bitand(w.s, one.s - 1) + fractionals = and(w.s, one.s - 1) divisor, kappa = bigpowten(integrals, 64 + one.e) len = 1 rest = 0 @@ -78,7 +78,7 @@ function digitgen(w,buffer,requested_digits=1000) buffer[len] = 0x30 + digit len += 1 requested_digits -= 1 - fractionals = bitand(fractionals, one.s - 1) + fractionals and= one.s - 1 kappa -= 1 end requested_digits != 0 && return false, kappa, len diff --git a/base/grisu/fastshortest.jl b/base/grisu/fastshortest.jl index 79ac828ac0401..146e1b431fce8 100644 --- a/base/grisu/fastshortest.jl +++ b/base/grisu/fastshortest.jl @@ -67,7 +67,7 @@ function digitgen(low,w,high,buffer) too_high = Float(high.s+unit,high.e) unsafe_interval = too_high - Float(low.s-unit,low.e) integrals = too_high.s >> -one.e - fractionals = bitand(too_high.s, one.s - 1) + fractionals = and(too_high.s, one.s - 1) divisor, kappa = bigpowten(integrals, 64 + one.e) len = 1 rest = UInt64(0) @@ -92,7 +92,7 @@ function digitgen(low,w,high,buffer) digit = fractionals >> -one.e buffer[len] = 0x30 + digit len += 1 - fractionals = bitand(fractionals, one.s - 1) + fractionals and= one.s - 1 kappa -= 1 if fractionals < unsafe_interval.s r, kappa = roundweed(buffer,len,fractionals,one.s, diff --git a/base/grisu/float.jl b/base/grisu/float.jl index fefed382c3d49..49b8f8ea3decf 100644 --- a/base/grisu/float.jl +++ b/base/grisu/float.jl @@ -48,11 +48,11 @@ const FloatSignificandSize = Int32(64) function normalize(v::Float) f = v.s e::Int32 = v.e - while bitand(f, Float10MSBits) == 0 + while and(f, Float10MSBits) == 0 f <<= 10 e -= 10 end - while bitand(f, FloatSignMask) == 0 + while and(f, FloatSignMask) == 0 f <<= 1 e -= 1 end @@ -60,7 +60,7 @@ function normalize(v::Float) end function normalize(v::Float64) s = _significand(v); e = _exponent(v) - while bitand(s, HiddenBit(Float64)) == 0 + while and(s, HiddenBit(Float64)) == 0 s <<= UInt64(1) e -= Int32(1) end @@ -108,14 +108,14 @@ uint_t(d::Float16) = reinterpret(UInt16,d) function _exponent(d::T) where T<:AbstractFloat isdenormal(d) && return DenormalExponent(T) - biased_e::Int32 = Int32(bitand(uint_t(d), ExponentMask(T)) >> PhysicalSignificandSize(T)) + biased_e::Int32 = Int32(and(uint_t(d), ExponentMask(T)) >> PhysicalSignificandSize(T)) return Int32(biased_e - ExponentBias(T)) end function _significand(d::T) where T<:AbstractFloat - s = bitand(uint_t(d), SignificandMask(T)) + s = and(uint_t(d), SignificandMask(T)) return !isdenormal(d) ? s + HiddenBit(T) : s end -isdenormal(d::T) where {T<:AbstractFloat} = bitand(uint_t(d), ExponentMask(T)) == 0 +isdenormal(d::T) where {T<:AbstractFloat} = and(uint_t(d), ExponentMask(T)) == 0 function normalizedbound(f::AbstractFloat) v = Float(_significand(f),_exponent(f)) @@ -128,7 +128,7 @@ function normalizedbound(f::AbstractFloat) return Float(m_minus.s << (m_minus.e - m_plus.e), m_plus.e), m_plus end function lowerboundaryiscloser(f::T) where T<:AbstractFloat - physical_significand_is_zero = bitand(uint_t(f), SignificandMask(T)) == 0 + physical_significand_is_zero = and(uint_t(f), SignificandMask(T)) == 0 return physical_significand_is_zero && (_exponent(f) != DenormalExponent(T)) end @@ -138,14 +138,14 @@ const FloatM32 = 0xFFFFFFFF function (*)(this::Float,other::Float) a::UInt64 = this.s >> 32 - b::UInt64 = bitand(this.s, FloatM32) + b::UInt64 = and(this.s, FloatM32) c::UInt64 = other.s >> 32 - d::UInt64 = bitand(other.s, FloatM32) + d::UInt64 = and(other.s, FloatM32) ac::UInt64 = a * c bc::UInt64 = b * c ad::UInt64 = a * d bd::UInt64 = b * d - tmp::UInt64 = (bd >> 32) + bitand(ad, FloatM32) + bitand(bc, FloatM32) + tmp::UInt64 = (bd >> 32) + and(ad, FloatM32) + and(bc, FloatM32) # By adding 1U << 31 to tmp we round the final result. # Halfway cases will be round up. tmp += UInt64(1) << 31 diff --git a/base/hashing.jl b/base/hashing.jl index d71eed5c023d2..f29513799f540 100644 --- a/base/hashing.jl +++ b/base/hashing.jl @@ -24,7 +24,7 @@ hash(@nospecialize(x), h::UInt) = hash_uint(3h - object_id(x)) function hash_64_64(n::UInt64) local a::UInt64 = n - a = bitnot(a) + a << 21 + a = not(a) + a << 21 a = a ⊻ a >> 24 a = a + a << 3 + a << 8 a = a ⊻ a >> 14 @@ -36,7 +36,7 @@ end function hash_64_32(n::UInt64) local a::UInt64 = n - a = bitnot(a) + a << 18 + a = not(a) + a << 18 a = a ⊻ a >> 31 a = a * 21 a = a ⊻ a >> 11 diff --git a/base/hashing2.jl b/base/hashing2.jl index 89a1b0775e58b..9f8610ad0657e 100644 --- a/base/hashing2.jl +++ b/base/hashing2.jl @@ -100,9 +100,9 @@ function decompose(x::Float16)::NTuple{3,Int} isnan(x) && return 0, 0, 0 isinf(x) && return ifelse(x < 0, -1, 1), 0, 0 n = reinterpret(UInt16, x) - s = bitand(n, 0x03ff) % Int16 - e = bitand(n, 0x7c00 >> 10) % Int - s = bitor(s, Int16(e != 0) << 10) + s = and(n, 0x03ff) % Int16 + e = and(n, 0x7c00 >> 10) % Int + s or= Int16(e != 0) << 10 d = ifelse(signbit(x), -1, 1) s, e - 25 + (e == 0), d end @@ -111,9 +111,9 @@ function decompose(x::Float32)::NTuple{3,Int} isnan(x) && return 0, 0, 0 isinf(x) && return ifelse(x < 0, -1, 1), 0, 0 n = reinterpret(UInt32, x) - s = bitand(n, 0x007fffff) % Int32 - e = bitand(n, 0x7f800000 >> 23) % Int - s = bitor(s, Int32(e != 0) << 23) + s = and(n, 0x007fffff) % Int32 + e = and(n, 0x7f800000 >> 23) % Int + s or= Int32(e != 0) << 23 d = ifelse(signbit(x), -1, 1) s, e - 150 + (e == 0), d end @@ -122,9 +122,9 @@ function decompose(x::Float64)::Tuple{Int64, Int, Int} isnan(x) && return 0, 0, 0 isinf(x) && return ifelse(x < 0, -1, 1), 0, 0 n = reinterpret(UInt64, x) - s = bitand(n, 0x000fffffffffffff) % Int64 - e = bitand(n, 0x7ff0000000000000 >> 52) % Int - s = bitor(s, Int64(e != 0) << 52) + s = and(n, 0x000fffffffffffff) % Int64 + e = and(n, 0x7ff0000000000000 >> 52) % Int + s or= Int64(e != 0) << 52 d = ifelse(signbit(x), -1, 1) s, e - 1075 + (e == 0), d end diff --git a/base/inference.jl b/base/inference.jl index 31586b5c0d0da..7bfff5bb99e1c 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -44,7 +44,7 @@ struct InferenceParams end end -# alloc_elim_pass! relies on `bitor(Slot_AssignedOnce, Slot_UsedUndef)` being +# alloc_elim_pass! relies on `or(Slot_AssignedOnce, Slot_UsedUndef)` being # SSA. This should be true now but can break if we start to track conditional # constants. e.g. # @@ -3610,7 +3610,7 @@ function optimize(me::InferenceState) end if proven_pure for fl in me.src.slotflags - if bitand(fl, Slot_UsedUndef) != 0 + if and(fl, Slot_UsedUndef) != 0 proven_pure = false break end @@ -3691,7 +3691,7 @@ function finish(me::InferenceState) # don't store inferred code if we've decided to interpret this function if !already_inferred && me.linfo.jlcall_api != 4 - const_flags = bitor((me.const_ret) << 1, me.const_api) + const_flags = or((me.const_ret) << 1, me.const_api) if me.const_ret if isa(me.bestguess, Const) inferred_const = (me.bestguess::Const).val @@ -3870,7 +3870,7 @@ function type_annotate!(sv::InferenceState) # finish marking used-undef variables for j = 1:nslots if undefs[j] - src.slotflags[j] = bitor(src.slotflags[j], Slot_UsedUndef) + src.slotflags[j] or= Slot_UsedUndef end end @@ -4111,7 +4111,7 @@ function effect_free(@nospecialize(e), src::CodeInfo, mod::Module, allow_volatil elseif isa(e, Symbol) return allow_volatile elseif isa(e, Slot) - return bitand(src.slotflags[slot_id(e)], Slot_UsedUndef) == 0 + return and(src.slotflags[slot_id(e)], Slot_UsedUndef) == 0 elseif isa(e, Expr) e = e::Expr head = e.head @@ -5573,7 +5573,7 @@ function find_sa_vars(src::CodeInfo, nargs::Int) # this transformation is not valid for vars used before def. # we need to preserve the point of assignment to know where to # throw errors (issue #4645). - if id > nargs && bitand(src.slotflags[id], Slot_UsedUndef) == 0 + if id > nargs && and(src.slotflags[id], Slot_UsedUndef) == 0 if !haskey(av, lhs) av[lhs] = e.args[2] else @@ -5636,7 +5636,7 @@ function occurs_outside_getfield(@nospecialize(e), @nospecialize(sym), end else if (head === :block && isa(sym, Slot) && - bitand(sv.src.slotflags[slot_id(sym)], Slot_UsedUndef) == 0) + and(sv.src.slotflags[slot_id(sym)], Slot_UsedUndef) == 0) ignore_void = true else ignore_void = false @@ -5662,7 +5662,7 @@ function void_use_elim_pass!(sv::OptimizationState) # Explicitly listed here for clarity return false elseif isa(ex, Slot) - return bitand(sv.src.slotflags[slot_id(ex)], Slot_UsedUndef) != 0 + return and(sv.src.slotflags[slot_id(ex)], Slot_UsedUndef) != 0 elseif isa(ex, GlobalRef) ex = ex::GlobalRef return !isdefined(ex.mod, ex.name) @@ -5989,7 +5989,7 @@ function alloc_elim_pass!(sv::OptimizationState) rhs = e.args[2] # Need to make sure LLVM can recognize this as LLVM ssa value too is_ssa = (isa(var, SSAValue) || - bitand(sv.src.slotflags[slot_id(var)], Slot_UsedUndef) == 0) + and(sv.src.slotflags[slot_id(var)], Slot_UsedUndef) == 0) else var = nothing rhs = e @@ -6042,7 +6042,7 @@ function alloc_elim_pass!(sv::OptimizationState) sv.src.slotnames[slot_id(var)]) tmpv_id = slot_id(tmpv) new_slots[j] = tmpv_id - sv.src.slotflags[tmpv_id] = bitor(sv.src.slotflags[tmpv_id], Slot_UsedUndef) + sv.src.slotflags[tmpv_id] or= Slot_UsedUndef end tmp = Expr(:(=), tmpv, tupelt) insert!(body, i+n_ins, tmp) diff --git a/base/int.jl b/base/int.jl index 3d86daf9fd37a..100fc1ca5594d 100644 --- a/base/int.jl +++ b/base/int.jl @@ -122,7 +122,7 @@ function abs end abs(x::Unsigned) = x abs(x::Signed) = flipsign(x,x) -bitnot(n::Integer) = -n-1 +not(n::Integer) = -n-1 unsigned(x::BitSigned) = reinterpret(typeof(convert(Unsigned, zero(x))), x) unsigned(x::Bool) = convert(Unsigned, x) @@ -242,62 +242,62 @@ end ## integer bitwise operations ## """ - bitnot(x) + not(x) Bitwise not. # Examples ```jldoctest -julia> bitnot(4) +julia> not(4) -5 -julia> bitnot(10) +julia> not(10) -11 -julia> bitnot(true) +julia> not(true) false ``` """ -bitnot(x::BitInteger) = not_int(x) +not(x::BitInteger) = not_int(x) """ - bitand(x, y) + and(x, y) Bitwise and. # Examples ```jldoctest -julia> bitand(4, 10) +julia> and(4, 10) 0 -julia> bitand(4, 12) +julia> and(4, 12) 4 ``` """ -bitand(x::T, y::T) where {T<:BitInteger} = and_int(x, y) +and(x::T, y::T) where {T<:BitInteger} = and_int(x, y) """ - bitor(x, y) + or(x, y) Bitwise or. # Examples ```jldoctest -julia> bitor(4, 10) +julia> or(4, 10) 14 -julia> bitor(4, 1) +julia> or(4, 1) 5 ``` """ -bitor(x::T, y::T) where {T<:BitInteger} = or_int(x, y) +or(x::T, y::T) where {T<:BitInteger} = or_int(x, y) """ - bitxor(x, y) + xor(x, y) ⊻(x, y) Bitwise exclusive or of `x` and `y`. The infix operation -`a ⊻ b` is a synonym for `bitxor(a,b)`, and +`a ⊻ b` is a synonym for `xor(a,b)`, and `⊻` can be typed by tab-completing `\\xor` or `\\veebar` in the Julia REPL. @@ -309,14 +309,14 @@ julia> bitstring(Int8(3)) julia> bitstring(Int8(5)) "00000101" -julia> bitstring(bitxor(Int8(3), Int8(5))) +julia> bitstring(xor(Int8(3), Int8(5))) "00000110" julia> bitstring(Int8(3) ⊻ Int8(5)) "00000110" ``` """ -bitxor(x::T, y::T) where {T<:BitInteger} = xor_int(x, y) +xor(x::T, y::T) where {T<:BitInteger} = xor_int(x, y) """ @@ -389,7 +389,7 @@ julia> count_zeros(Int32(2 ^ 16 - 1)) 16 ``` """ -count_zeros(x::Integer) = count_ones(bitnot(x)) +count_zeros(x::Integer) = count_ones(not(x)) """ leading_ones(x::Integer) -> Integer @@ -401,7 +401,7 @@ julia> leading_ones(UInt32(2 ^ 32 - 2)) 31 ``` """ -leading_ones(x::Integer) = leading_zeros(bitnot(x)) +leading_ones(x::Integer) = leading_zeros(not(x)) """ trailing_ones(x::Integer) -> Integer @@ -413,7 +413,7 @@ julia> trailing_ones(3) 2 ``` """ -trailing_ones(x::Integer) = trailing_zeros(bitnot(x)) +trailing_ones(x::Integer) = trailing_zeros(not(x)) ## integer comparisons ## @@ -491,7 +491,7 @@ for to in BitInteger_types, from in (BitInteger_types..., Bool) @eval rem(x::($from), ::Type{$to}) = trunc_int($to, x) elseif from === Bool # Bools use i8 storage and may have garbage in their 7 high bits - @eval convert(::Type{$to}, x::($from)) = bitand(zext_int($to, x), $to(1)) + @eval convert(::Type{$to}, x::($from)) = and(zext_int($to, x), $to(1)) @eval rem(x::($from), ::Type{$to}) = convert($to, x) elseif from.size < to.size if from <: Signed @@ -544,7 +544,7 @@ end rem(x::T, ::Type{T}) where {T<:Integer} = x rem(x::Integer, T::Type{<:Integer}) = convert(T, x) # `x % T` falls back to `convert` -rem(x::Integer, ::Type{Bool}) = !iszero(bitand(x, 1)) +rem(x::Integer, ::Type{Bool}) = !iszero(and(x, 1)) mod(x::Integer, ::Type{T}) where {T<:Integer} = rem(x, T) unsafe_trunc(::Type{T}, x::Integer) where {T<:Integer} = rem(x, T) @@ -719,14 +719,14 @@ if Core.sizeof(Int) == 4 local u0::UInt64, v0::UInt64, w0::UInt64 local u1::Int64, v1::Int64, w1::UInt64, w2::Int64, t::UInt64 - u0 = bitand(u, 0xffffffff); u1 = u >> 32 - v0 = bitand(v, 0xffffffff); v1 = v >> 32 + u0 = and(u, 0xffffffff); u1 = u >> 32 + v0 = and(v, 0xffffffff); v1 = v >> 32 w0 = u0 * v0 t = reinterpret(UInt64, u1) * v0 + (w0 >>> 32) w2 = reinterpret(Int64, t) >> 32 - w1 = u0 * reinterpret(UInt64, v1) + bitand(t, 0xffffffff) + w1 = u0 * reinterpret(UInt64, v1) + and(t, 0xffffffff) hi = u1 * v1 + w2 + (reinterpret(Int64, w1) >> 32) - lo = bitand(w0, 0xffffffff) + (w1 << 32) + lo = and(w0, 0xffffffff) + (w1 << 32) return Int128(hi) << 64 + Int128(lo) end @@ -734,14 +734,14 @@ if Core.sizeof(Int) == 4 local u0::UInt64, v0::UInt64, w0::UInt64 local u1::UInt64, v1::UInt64, w1::UInt64, w2::UInt64, t::UInt64 - u0 = bitand(u, 0xffffffff); u1 = u >>> 32 - v0 = bitand(v, 0xffffffff); v1 = v >>> 32 + u0 = and(u, 0xffffffff); u1 = u >>> 32 + v0 = and(v, 0xffffffff); v1 = v >>> 32 w0 = u0 * v0 t = u1 * v0 + (w0 >>> 32) w2 = t >>> 32 - w1 = u0 * v1 + bitand(t, 0xffffffff) + w1 = u0 * v1 + and(t, 0xffffffff) hi = u1 * v1 + w2 + (w1 >>> 32) - lo = bitand(w0, 0xffffffff) + (w1 << 32) + lo = and(w0, 0xffffffff) + (w1 << 32) return UInt128(hi) << 64 + UInt128(lo) end @@ -752,8 +752,8 @@ if Core.sizeof(Int) == 4 lohi = widemul(reinterpret(Int64, u0), v1) hilo = widemul(u1, reinterpret(Int64, v0)) t = reinterpret(UInt128, hilo) + (lolo >>> 64) - w1 = reinterpret(UInt128, lohi) + bitand(t, 0xffffffffffffffff) - return Int128(bitand(lolo, 0xffffffffffffffff)) + reinterpret(Int128, w1) << 64 + w1 = reinterpret(UInt128, lohi) + and(t, 0xffffffffffffffff) + return Int128(and(lolo, 0xffffffffffffffff)) + reinterpret(Int128, w1) << 64 end function *(u::UInt128, v::UInt128) @@ -763,8 +763,8 @@ if Core.sizeof(Int) == 4 lohi = widemul(u0, v1) hilo = widemul(u1, v0) t = hilo + (lolo >>> 64) - w1 = lohi + bitand(t, 0xffffffffffffffff) - return bitand(lolo, 0xffffffffffffffff) + UInt128(w1) << 64 + w1 = lohi + and(t, 0xffffffffffffffff) + return and(lolo, 0xffffffffffffffff) + UInt128(w1) << 64 end function div(x::Int128, y::Int128) @@ -796,7 +796,7 @@ else end # issue #15489: since integer ops are unchecked, they shouldn't check promotion -for op in (:+, :-, :*, bitand, :bitor, :bitxor) +for op in (:+, :-, :*, and, :or, :xor) @eval function $op(a::Integer, b::Integer) T = promote_typeof(a, b) return $op(a % T, b % T) diff --git a/base/intfuncs.jl b/base/intfuncs.jl index 0632390f9f96c..e2fd8b98d007a 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -558,7 +558,7 @@ function bin(x::Unsigned, pad::Int, neg::Bool) i = neg + max(pad,sizeof(x)<<3-leading_zeros(x)) a = StringVector(i) while i > neg - a[i] = '0' + bitand(x, 0x1) + a[i] = '0' + and(x, 0x1) x >>= 1 i -= 1 end @@ -570,7 +570,7 @@ function oct(x::Unsigned, pad::Int, neg::Bool) i = neg + max(pad,div((sizeof(x)<<3)-leading_zeros(x)+2,3)) a = StringVector(i) while i > neg - a[i] = '0' + bitand(x, 0x7) + a[i] = '0' + and(x, 0x7) x >>= 3 i -= 1 end @@ -594,7 +594,7 @@ function hex(x::Unsigned, pad::Int, neg::Bool) i = neg + max(pad,(sizeof(x)<<1)-(leading_zeros(x)>>2)) a = StringVector(i) while i > neg - d = bitand(x, 0xf) + d = and(x, 0xf) a[i] = '0'+d+39*(d>9) x >>= 4 i -= 1 diff --git a/base/io.jl b/base/io.jl index 7236919475d05..aa7537d91b028 100644 --- a/base/io.jl +++ b/base/io.jl @@ -406,17 +406,17 @@ function write(s::IO, ch::Char) if c < 0x80 return write(s, c%UInt8) elseif c < 0x800 - return (write(s, bitor(c >> 6 , 0xC0) % UInt8)) + - (write(s, bitor(bitand(c, 0x3F), 0x80) % UInt8)) + return (write(s, or(c >> 6 , 0xC0) % UInt8)) + + (write(s, or(and(c, 0x3F), 0x80) % UInt8)) elseif c < 0x10000 - return (write(s, bitor(c >> 12 , 0xE0) % UInt8)) + - (write(s, bitor(bitand(c >> 6, 0x3F), 0x80) % UInt8)) + - (write(s, bitor(bitand(c, 0x3F) , 0x80) % UInt8)) + return (write(s, or(c >> 12 , 0xE0) % UInt8)) + + (write(s, or(and(c >> 6, 0x3F), 0x80) % UInt8)) + + (write(s, or(and(c, 0x3F) , 0x80) % UInt8)) elseif c < 0x110000 - return (write(s, bitor(c >> 18 , 0xF0) % UInt8)) + - (write(s, bitor(bitand(c >> 12, 0x3F), 0x80) % UInt8)) + - (write(s, bitor(bitand(c >> 6, 0x3F) , 0x80) % UInt8)) + - (write(s, bitor(bitand(c, 0x3F) , 0x80) % UInt8)) + return (write(s, or(c >> 18 , 0xF0) % UInt8)) + + (write(s, or(and(c >> 12, 0x3F), 0x80) % UInt8)) + + (write(s, or(and(c >> 6, 0x3F) , 0x80) % UInt8)) + + (write(s, or(and(c, 0x3F) , 0x80) % UInt8)) else return write(s, '\ufffd') end diff --git a/base/libc.jl b/base/libc.jl index 1437feaf6d61b..bf499f2a69dcf 100644 --- a/base/libc.jl +++ b/base/libc.jl @@ -303,7 +303,7 @@ if Sys.iswindows() lpMsgBuf = Ref{Ptr{UInt16}}() lpMsgBuf[] = 0 len = ccall(:FormatMessageW, stdcall, UInt32, (Cint, Ptr{Void}, Cint, Cint, Ptr{Ptr{UInt16}}, Cint, Ptr{Void}), - bitor(FORMAT_MESSAGE_ALLOCATE_BUFFER, FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_MAX_WIDTH_MASK), + or(FORMAT_MESSAGE_ALLOCATE_BUFFER, FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_MAX_WIDTH_MASK), C_NULL, e, 0, lpMsgBuf, 0, C_NULL) p = lpMsgBuf[] len == 0 && return "" diff --git a/base/libdl.jl b/base/libdl.jl index 5367ef545cb5c..5d9010c16744a 100644 --- a/base/libdl.jl +++ b/base/libdl.jl @@ -94,10 +94,10 @@ between shared libraries. """ function dlopen end -dlopen(s::Symbol, flags::Integer = bitor(RTLD_LAZY, RTLD_DEEPBIND)) = +dlopen(s::Symbol, flags::Integer = or(RTLD_LAZY, RTLD_DEEPBIND)) = dlopen(string(s), flags) -dlopen(s::AbstractString, flags::Integer = bitor(RTLD_LAZY, RTLD_DEEPBIND)) = +dlopen(s::AbstractString, flags::Integer = or(RTLD_LAZY, RTLD_DEEPBIND)) = ccall(:jl_load_dynamic_library, Ptr{Void}, (Cstring,UInt32), s, flags) """ @@ -107,10 +107,10 @@ Similar to [`dlopen`](@ref), except returns a `NULL` pointer instead of raising """ function dlopen_e end -dlopen_e(s::Symbol, flags::Integer = bitor(RTLD_LAZY, RTLD_DEEPBIND)) = +dlopen_e(s::Symbol, flags::Integer = or(RTLD_LAZY, RTLD_DEEPBIND)) = dlopen_e(string(s), flags) -dlopen_e(s::AbstractString, flags::Integer = bitor(RTLD_LAZY, RTLD_DEEPBIND)) = +dlopen_e(s::AbstractString, flags::Integer = or(RTLD_LAZY, RTLD_DEEPBIND)) = ccall(:jl_load_dynamic_library_e, Ptr{Void}, (Cstring,UInt32), s, flags) """ diff --git a/base/libgit2/callbacks.jl b/base/libgit2/callbacks.jl index 258344b1ad2a7..5dcde909c9632 100644 --- a/base/libgit2/callbacks.jl +++ b/base/libgit2/callbacks.jl @@ -287,12 +287,12 @@ function credentials_callback(libgit2credptr::Ptr{Ptr{Void}}, url_ptr::Cstring, p.credential = Nullable(deepcopy(cred)) if isa(cred, SSHCredentials) - allowed_types = bitand(allowed_types, Cuint(Consts.CREDTYPE_SSH_KEY)) + allowed_types and= Cuint(Consts.CREDTYPE_SSH_KEY) elseif isa(cred, UserPasswordCredentials) - allowed_types = bitand(allowed_types, Cuint(Consts.CREDTYPE_USERPASS_PLAINTEXT)) + allowed_types and= Cuint(Consts.CREDTYPE_USERPASS_PLAINTEXT) else # just allowed_types = zero(allowed_types) ? - allowed_types = bitand(allowed_types, Cuint(0)) # Unhandled credential type + allowed_types and= Cuint(0) # Unhandled credential type end elseif !isnull(p.cache) cache = unsafe_get(p.cache) diff --git a/base/libgit2/consts.jl b/base/libgit2/consts.jl index 1273d47d5c80f..f89491eba3823 100644 --- a/base/libgit2/consts.jl +++ b/base/libgit2/consts.jl @@ -139,7 +139,7 @@ const IDXENTRY_NEW_SKIP_WORKTREE = Cint(1 << 9) const INDEXCAP_IGNORE_CASE = Cuint(1) const INDEXCAP_NO_FILEMODE = Cuint(2) const INDEXCAP_NO_SYMLINKS = Cuint(4) -const INDEXCAP_FROM_OWNER = bitnot(Cuint(0)) +const INDEXCAP_FROM_OWNER = not(Cuint(0)) const INDEX_ADD_DEFAULT = Cuint(0) const INDEX_ADD_FORCE = Cuint(1 << 0) diff --git a/base/libgit2/libgit2.jl b/base/libgit2/libgit2.jl index 436fcc9d45ef9..d81031da10904 100644 --- a/base/libgit2/libgit2.jl +++ b/base/libgit2/libgit2.jl @@ -883,7 +883,7 @@ function restore(s::State, repo::GitRepo) with(GitIndex, repo) do idx read_tree!(idx, s.work) # move work tree to index opts = CheckoutOptions( - checkout_strategy = bitor(Consts.CHECKOUT_FORCE, # check the index out to work + checkout_strategy = or(Consts.CHECKOUT_FORCE, # check the index out to work Consts.CHECKOUT_REMOVE_UNTRACKED)) # remove everything else checkout_index(repo, Nullable(idx), options = opts) diff --git a/base/libgit2/utils.jl b/base/libgit2/utils.jl index 432de3e6a069e..6f5b985bb63ff 100644 --- a/base/libgit2/utils.jl +++ b/base/libgit2/utils.jl @@ -44,14 +44,14 @@ const VERSION = version() Test whether the bits of `val` indexed by `flag` are set (`1`) or unset (`0`). """ -isset(val::Integer, flag::Integer) = bitand(val, flag) == flag +isset(val::Integer, flag::Integer) = and(val, flag) == flag """ reset(val::Integer, flag::Integer) Unset the bits of `val` indexed by `flag`, returning them to `0`. """ -reset(val::Integer, flag::Integer) = bitand(val, bitnot(flag)) +reset(val::Integer, flag::Integer) = and(val, not(flag)) """ toggle(val::Integer, flag::Integer) @@ -59,7 +59,7 @@ reset(val::Integer, flag::Integer) = bitand(val, bitnot(flag)) Flip the bits of `val` indexed by `flag`, so that if a bit is `0` it will be `1` after the toggle, and vice-versa. """ -toggle(val::Integer, flag::Integer) = bitor(val, flag) +toggle(val::Integer, flag::Integer) = or(val, flag) """ features() diff --git a/base/libgit2/walker.jl b/base/libgit2/walker.jl index 85fafeeeb9319..698041c5bf32f 100644 --- a/base/libgit2/walker.jl +++ b/base/libgit2/walker.jl @@ -75,7 +75,7 @@ function Base.push!(w::GitRevWalker, range::AbstractString) end function Base.sort!(w::GitRevWalker; by::Cint = Consts.SORT_NONE, rev::Bool=false) - rev && (by = bitor(by, Consts.SORT_REVERSE)) + rev && (by or= Consts.SORT_REVERSE) ccall((:git_revwalk_sorting, :libgit2), Void, (Ptr{Void}, Cint), w.ptr, by) return w end diff --git a/base/linalg/bitarray.jl b/base/linalg/bitarray.jl index c1786bbb48ea8..22b67144d40d1 100644 --- a/base/linalg/bitarray.jl +++ b/base/linalg/bitarray.jl @@ -7,7 +7,7 @@ function dot(x::BitVector, y::BitVector) xc = x.chunks yc = y.chunks @inbounds for i = 1:length(xc) - s += count_ones(bitand(xc[i], yc[i])) + s += count_ones(and(xc[i], yc[i])) end s end @@ -33,7 +33,7 @@ end #for j = 1:nB #for k = 1:col_ch ## TODO: improve - #C[i, j] += count_ones(bitand(aux_chunksA[k], aux_chunksB[j][k])) + #C[i, j] += count_ones(and(aux_chunksA[k], aux_chunksB[j][k])) #end #end #end @@ -133,21 +133,21 @@ function nonzero_chunks(chunks::Vector{UInt64}, pos0::Int, pos1::Int) delta_k = k1 - k0 z = UInt64(0) - u = bitnot(z) + u = not(z) if delta_k == 0 - msk_0 = bitand(u << l0, bitnot(u << l1 << 1)) + msk_0 = and(u << l0, not(u << l1 << 1)) else msk_0 = (u << l0) - msk_1 = bitnot(u << l1 << 1) + msk_1 = not(u << l1 << 1) end @inbounds begin - bitand(chunks[k0], msk_0) == z || return true + and(chunks[k0], msk_0) == z || return true delta_k == 0 && return false for i = k0 + 1 : k1 - 1 chunks[i] == z || return true end - bitand(chunks[k1], msk_1) == z || return true + and(chunks[k1], msk_1) == z || return true end return false end @@ -195,7 +195,7 @@ function findmin(a::BitArray) k == 64 || return (false, ti) end l = Base._mod64(length(a)-1) + 1 - @inbounds k = trailing_ones(bitand(ac[end], Base._msk_end(l))) + @inbounds k = trailing_ones(and(ac[end], Base._msk_end(l))) ti += k k == l || return (false, ti) return m, mi @@ -205,12 +205,12 @@ end # http://www.hackersdelight.org/hdcodetxt/transpose8.c.txt function transpose8x8(x::UInt64) y = x - t = bitand(bitxor(y, y >>> 7), 0x00aa00aa00aa00aa) - y = bitxor(y, t, t << 7) - t = bitand(bitxor(y, y >>> 14), 0x0000cccc0000cccc) - y = bitxor(y, t, t << 14) - t = bitand(bitxor(y, y >>> 28), 0x00000000f0f0f0f0) - return bitxor(y, t, t << 28) + t = and(xor(y, y >>> 7), 0x00aa00aa00aa00aa) + y = xor(y, t, t << 7) + t = and(xor(y, y >>> 14), 0x0000cccc0000cccc) + y = xor(y, t, t << 14) + t = and(xor(y, y >>> 28), 0x00000000f0f0f0f0) + return xor(y, t, t << 28) end function form_8x8_chunk(Bc::Vector{UInt64}, i1::Int, i2::Int, m::Int, cgap::Int, cinc::Int, nc::Int, msk8::UInt64) @@ -220,10 +220,10 @@ function form_8x8_chunk(Bc::Vector{UInt64}, i1::Int, i2::Int, m::Int, cgap::Int, r = 0 for j = 1:8 k > nc && break - x = bitor(x, bitand(Bc[k] >>> l, msk8) << r) + x or= and(Bc[k] >>> l, msk8) << r if l + 8 >= 64 && nc > k r0 = 8 - Base._mod64(l + 8) - x = bitor(x, bitand(Bc[k + 1], msk8 >>> r0) << (r + r0)) + x or= and(Bc[k + 1], msk8 >>> r0) << (r + r0) end k += cgap + (l + cinc >= 64 ? 1 : 0) l = Base._mod64(l + cinc) @@ -238,10 +238,10 @@ function put_8x8_chunk(Bc::Vector{UInt64}, i1::Int, i2::Int, x::UInt64, m::Int, r = 0 for j = 1:8 k > nc && break - Bc[k] = bitor(Bc[k], bitand(x >>> r, msk8) << l) + Bc[k] or= and(x >>> r, msk8) << l if l + 8 >= 64 && nc > k r0 = 8 - Base._mod64(l + 8) - Bc[k + 1] = bitor(Bc[k + 1], bitand(x >>> (r + r0), msk8 >>> r0)) + Bc[k + 1] or= and(x >>> (r + r0), msk8 >>> r0) end k += cgap + (l + cinc >= 64 ? 1 : 0) l = Base._mod64(l + cinc) diff --git a/base/math.jl b/base/math.jl index 1e0280ef2d6c4..bad104d147973 100644 --- a/base/math.jl +++ b/base/math.jl @@ -542,14 +542,14 @@ julia> ldexp(5., 2) """ function ldexp(x::T, e::Integer) where T<:IEEEFloat xu = reinterpret(Unsigned, x) - xs = bitand(xu, bitnot(sign_mask(T))) + xs = and(xu, not(sign_mask(T))) xs >= exponent_mask(T) && return x # NaN or Inf k = Int(xs >> significand_bits(T)) if k == 0 # x is subnormal xs == 0 && return x # +-0 m = leading_zeros(xs) - exponent_bits(T) ys = xs << unsigned(m) - xu = bitor(ys, bitand(xu, sign_mask(T))) + xu = or(ys, and(xu, sign_mask(T))) k = 1 - m # underflow, otherwise may have integer underflow in the following n + k e < -50000 && return flipsign(T(0.0), x) @@ -568,7 +568,7 @@ function ldexp(x::T, e::Integer) where T<:IEEEFloat return flipsign(T(Inf), x) end if k > 0 # normal case - xu = bitor(bitand(xu, bitnot(exponent_mask(T))), rem(k, uinttype(T)) << significand_bits(T)) + xu = or(and(xu, not(exponent_mask(T))), rem(k, uinttype(T)) << significand_bits(T)) return reinterpret(T, xu) else # subnormal case if k <= -significand_bits(T) # underflow @@ -578,7 +578,7 @@ function ldexp(x::T, e::Integer) where T<:IEEEFloat end k += significand_bits(T) z = T(2.0)^-significand_bits(T) - xu = bitor(bitand(xu, bitnot(exponent_mask(T))), rem(k, uinttype(T)) << significand_bits(T)) + xu = or(and(xu, not(exponent_mask(T))), rem(k, uinttype(T)) << significand_bits(T)) return z*reinterpret(T, xu) end end @@ -592,7 +592,7 @@ Get the exponent of a normalized floating-point number. function exponent(x::T) where T<:IEEEFloat @noinline throw1(x) = throw(DomainError(x, "Cannot be NaN or Inf.")) @noinline throw2(x) = throw(DomainError(x, "Cannot be subnormal converted to 0.")) - xs = bitand(reinterpret(Unsigned, x), bitnot(sign_mask(T))) + xs = and(reinterpret(Unsigned, x), not(sign_mask(T))) xs >= exponent_mask(T) && throw1(x) k = Int(xs >> significand_bits(T)) if k == 0 # x is subnormal @@ -621,15 +621,15 @@ julia> significand(15.2)*8 """ function significand(x::T) where T<:IEEEFloat xu = reinterpret(Unsigned, x) - xs = bitand(xu, bitnot(sign_mask(T))) + xs = and(xu, not(sign_mask(T))) xs >= exponent_mask(T) && return x # NaN or Inf - if xs <= bitand(bitnot(exponent_mask(T)), bitnot(sign_mask(T))) # x is subnormal + if xs <= and(not(exponent_mask(T)), not(sign_mask(T))) # x is subnormal xs == 0 && return x # +-0 m = unsigned(leading_zeros(xs) - exponent_bits(T)) xs <<= m - xu = bitor(xs, bitand(xu, sign_mask(T))) + xu = or(xs, and(xu, sign_mask(T))) end - xu = bitor(bitand(xu, bitnot(exponent_mask(T))), exponent_one(T)) + xu = or(and(xu, not(exponent_mask(T))), exponent_one(T)) return reinterpret(T, xu) end @@ -641,18 +641,18 @@ and `val` is equal to ``x \\times 2^{exp}``. """ function frexp(x::T) where T<:IEEEFloat xu = reinterpret(Unsigned, x) - xs = bitand(xu, bitnot(sign_mask(T))) + xs = and(xu, not(sign_mask(T))) xs >= exponent_mask(T) && return x, 0 # NaN or Inf k = Int(xs >> significand_bits(T)) if k == 0 # x is subnormal xs == 0 && return x, 0 # +-0 m = leading_zeros(xs) - exponent_bits(T) xs <<= unsigned(m) - xu = bitor(xs, bitand(xu, sign_mask(T))) + xu = or(xs, and(xu, sign_mask(T))) k = 1 - m end k -= (exponent_bias(T) - 1) - xu = bitor(bitand(xu, bitnot(exponent_mask(T))), exponent_half(T)) + xu = or(and(xu, not(exponent_mask(T))), exponent_half(T)) return reinterpret(T, xu), k end @@ -813,7 +813,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Nearest}) n,y = rem_pio2_kernel(x) if iseven(n) - if bitand(n, 2) == 2 # n % 4 == 2: add/subtract pi + if and(n, 2) == 2 # n % 4 == 2: add/subtract pi if y.hi <= 0 return add22condh(y.hi,y.lo,pi2o2_h,pi2o2_l) else @@ -823,7 +823,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Nearest}) return y.hi+y.lo end else - if bitand(n, 2) == 2 # n % 4 == 3: subtract pi/2 + if and(n, 2) == 2 # n % 4 == 3: subtract pi/2 return add22condh(y.hi,y.lo,-pi1o2_h,-pi1o2_l) else # n % 4 == 1: add pi/2 return add22condh(y.hi,y.lo,pi1o2_h,pi1o2_l) @@ -837,7 +837,7 @@ function rem2pi(x::Float64, ::RoundingMode{:ToZero}) n,y = rem_pio2_kernel(x) if iseven(n) - if bitand(n, 2) == 2 # n % 4 == 2: add pi + if and(n, 2) == 2 # n % 4 == 2: add pi z = add22condh(y.hi,y.lo,pi2o2_h,pi2o2_l) else # n % 4 == 0: add 0 or 2pi if y.hi > 0 @@ -847,7 +847,7 @@ function rem2pi(x::Float64, ::RoundingMode{:ToZero}) end end else - if bitand(n, 2) == 2 # n % 4 == 3: add 3pi/2 + if and(n, 2) == 2 # n % 4 == 3: add 3pi/2 z = add22condh(y.hi,y.lo,pi3o2_h,pi3o2_l) else # n % 4 == 1: add pi/2 z = add22condh(y.hi,y.lo,pi1o2_h,pi1o2_l) @@ -867,7 +867,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Down}) n,y = rem_pio2_kernel(x) if iseven(n) - if bitand(n, 2) == 2 # n % 4 == 2: add pi + if and(n, 2) == 2 # n % 4 == 2: add pi return add22condh(y.hi,y.lo,pi2o2_h,pi2o2_l) else # n % 4 == 0: add 0 or 2pi if y.hi > 0 @@ -877,7 +877,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Down}) end end else - if bitand(n, 2) == 2 # n % 4 == 3: add 3pi/2 + if and(n, 2) == 2 # n % 4 == 3: add 3pi/2 return add22condh(y.hi,y.lo,pi3o2_h,pi3o2_l) else # n % 4 == 1: add pi/2 return add22condh(y.hi,y.lo,pi1o2_h,pi1o2_l) @@ -896,7 +896,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Up}) n,y = rem_pio2_kernel(x) if iseven(n) - if bitand(n, 2) == 2 # n % 4 == 2: sub pi + if and(n, 2) == 2 # n % 4 == 2: sub pi return add22condh(y.hi,y.lo,-pi2o2_h,-pi2o2_l) else # n % 4 == 0: sub 0 or 2pi if y.hi < 0 @@ -906,7 +906,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Up}) end end else - if bitand(n, 2) == 2 # n % 4 == 3: sub pi/2 + if and(n, 2) == 2 # n % 4 == 3: sub pi/2 return add22condh(y.hi,y.lo,-pi1o2_h,-pi1o2_l) else # n % 4 == 1: sub 3pi/2 return add22condh(y.hi,y.lo,-pi3o2_h,-pi3o2_l) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index f2c6f2578b45b..778751e2131a5 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -487,7 +487,7 @@ done(L::LogicalIndex, s) = s[3] > length(L) i, n = s Bc = L.mask.chunks while true - if bitand(Bc[_div64(i)+1], UInt64(1) << _mod64(i)) != 0 + if and(Bc[_div64(i)+1], UInt64(1) << _mod64(i)) != 0 i += 1 return (i, (i, n+1)) end @@ -1199,10 +1199,10 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra u = _msk64 if delta_kd == 0 - msk_d0 = msk_d1 = bitor(bitnot(u << ld0), u << (ld1+1)) + msk_d0 = msk_d1 = or(not(u << ld0), u << (ld1+1)) lt0 = ld1 else - msk_d0 = bitnot(u << ld0) + msk_d0 = not(u << ld0) msk_d1 = (u << (ld1+1)) lt0 = 63 end @@ -1212,10 +1212,10 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra @inbounds if ld0 > 0 c = UInt64(0) for j = ld0:lt0 - c = bitor(c, UInt64(unchecked_bool_convert(C[ind])) << j) + c or= UInt64(unchecked_bool_convert(C[ind])) << j ind += 1 end - Bc[kd0] = bitor(bitand(Bc[kd0], msk_d0), bitand(c, bitnot(msk_d0))) + Bc[kd0] = or(and(Bc[kd0], msk_d0), and(c, not(msk_d0))) bind += 1 end @@ -1223,7 +1223,7 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra @inbounds for i = 1:nc c = UInt64(0) for j = 0:63 - c = bitor(c, UInt64(unchecked_bool_convert(C[ind])) << j) + c or= UInt64(unchecked_bool_convert(C[ind])) << j ind += 1 end Bc[bind] = c @@ -1234,10 +1234,10 @@ function copy_to_bitarray_chunks!(Bc::Vector{UInt64}, pos_d::Int, C::StridedArra @assert bind == kd1 c = UInt64(0) for j = 0:ld1 - c = bitor(c, UInt64(unchecked_bool_convert(C[ind])) << j) + c or= UInt64(unchecked_bool_convert(C[ind])) << j ind += 1 end - Bc[kd1] = bitor(bitand(Bc[kd1], msk_d1), bitand(c, bitnot(msk_d1))) + Bc[kd1] = or(and(Bc[kd1], msk_d1), and(c, not(msk_d1))) end end diff --git a/base/namedtuple.jl b/base/namedtuple.jl index 828faeab77ced..4f224bf47afcf 100644 --- a/base/namedtuple.jl +++ b/base/namedtuple.jl @@ -107,7 +107,7 @@ isequal(a::NamedTuple, b::NamedTuple) = false _nt_names(::NamedTuple{names}) where {names} = names _nt_names(::Type{T}) where {names,T<:NamedTuple{names}} = names -hash(x::NamedTuple, h::UInt) = bitxor(object_id(_nt_names(x)), hash(Tuple(x), h)) +hash(x::NamedTuple, h::UInt) = xor(object_id(_nt_names(x)), hash(Tuple(x), h)) isless(a::NamedTuple{n}, b::NamedTuple{n}) where {n} = isless(Tuple(a), Tuple(b)) # TODO: case where one argument's names are a prefix of the other's diff --git a/base/nullable.jl b/base/nullable.jl index 6819027d8a83a..76038b160e816 100644 --- a/base/nullable.jl +++ b/base/nullable.jl @@ -394,7 +394,7 @@ for op in (+, -, abs, abs2) null_safe_op(::typeof(op), ::Type{Rational{S}}) where {S} = null_safe_op(op, S) end -null_safe_op(::typeof(bitnot), ::NullSafeInts) = true +null_safe_op(::typeof(not), ::NullSafeInts) = true null_safe_op(::typeof(!), ::Type{Bool}) = true # Binary operators @@ -402,7 +402,7 @@ null_safe_op(::typeof(!), ::Type{Bool}) = true # Note this list does not include ^, ÷ and % # Operations between signed and unsigned types are not safe: promotion to unsigned # gives an InexactError for negative numbers -for op in (+, -, *, /, bitand, bitor, <<, >>, >>>, +for op in (+, -, *, /, and, or, <<, >>, >>>, scalarmin, scalarmax) # to fix ambiguities global null_safe_op diff --git a/base/operators.jl b/base/operators.jl index 24bade7343a07..9b61e931a9c85 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -443,11 +443,11 @@ identity(x) = x +(x::Number) = x *(x::Number) = x -bitand(x::Integer) = x -bitor(x::Integer) = x -bitxor(x::Integer) = x +and(x::Integer) = x +or(x::Integer) = x +xor(x::Integer) = x -const ⊻ = bitxor +const ⊻ = xor # foldl for argument lists. expand recursively up to a point, then # switch to a loop. this allows small cases like `a+b+c+d` to be inlined @@ -461,7 +461,7 @@ function afoldl(op,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,qs...) y end -for op in (:+, :*, :bitand, :bitor, :bitxor, :min, :max, :kron) +for op in (:+, :*, :and, :or, :xor, :min, :max, :kron) @eval begin # note: these definitions must not cause a dispatch loop when +(a,b) is # not defined, and must only try to call 2-argument definitions, so diff --git a/base/pcre.jl b/base/pcre.jl index dd7b3a7e80403..bd1c62864eac6 100644 --- a/base/pcre.jl +++ b/base/pcre.jl @@ -30,7 +30,7 @@ end # supported options for different use cases -const COMPILE_MASK = bitor( +const COMPILE_MASK = or( ANCHORED , CASELESS , DOLLAR_ENDONLY , @@ -49,7 +49,7 @@ const COMPILE_MASK = bitor( UNGREEDY ) UTF -const EXECUTE_MASK = bitor( +const EXECUTE_MASK = or( NEWLINE_ANY , NEWLINE_ANYCRLF , NEWLINE_CR , @@ -65,9 +65,9 @@ const EXECUTE_MASK = bitor( PARTIAL_SOFT ) -const OPTIONS_MASK = bitor(COMPILE_MASK, EXECUTE_MASK) +const OPTIONS_MASK = or(COMPILE_MASK, EXECUTE_MASK) -const UNSET = bitnot(Csize_t(0)) # Indicates that an output vector element is unset +const UNSET = not(Csize_t(0)) # Indicates that an output vector element is unset function info(regex::Ptr{Void}, what::Integer, ::Type{T}) where T buf = Ref{T}() @@ -173,7 +173,7 @@ function capture_names(re) # big-endian 16-bit value. high_byte = UInt16(unsafe_load(nametable_ptr, offset)) low_byte = UInt16(unsafe_load(nametable_ptr, offset+1)) - idx = bitor(high_byte << 8, low_byte) + idx = or(high_byte << 8, low_byte) # The capture group name is a null-terminated string located directly # after the index. names[idx] = unsafe_string(nametable_ptr+offset+1) diff --git a/base/printf.jl b/base/printf.jl index 5eea89225e6f4..494e705aa651b 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -828,7 +828,7 @@ function decode_oct(d::Integer) @handle_zero x pt = i = div((sizeof(x)<<3)-leading_zeros(x)+2,3) while i > 0 - DIGITS[i] = '0' + bitand(x, 0x7) + DIGITS[i] = '0' + and(x, 0x7) x >>= 3 i -= 1 end @@ -840,7 +840,7 @@ function decode_0ct(d::Integer) # doesn't need special handling for zero pt = i = div((sizeof(x)<<3)-leading_zeros(x)+5,3) while i > 0 - DIGITS[i] = '0' + bitand(x, 0x7) + DIGITS[i] = '0' + and(x, 0x7) x >>= 3 i -= 1 end @@ -864,7 +864,7 @@ function decode_hex(d::Integer, symbols::Array{UInt8,1}) @handle_zero x pt = i = (sizeof(x)<<1)-(leading_zeros(x)>>2) while i > 0 - DIGITS[i] = symbols[bitand(x, 0xf) + 1] + DIGITS[i] = symbols[and(x, 0xf) + 1] x >>= 4 i -= 1 end @@ -1046,13 +1046,13 @@ function ini_hex(x::SmallFloatingPoint, n::Int, symbols::Array{UInt8,1}) sigbits = 4*min(n-1,13) s = 0.25*round(ldexp(s,1+sigbits)) # ensure last 2 exponent bits either 01 or 10 - u = bitand(reinterpret(UInt64,s), 0x003f_ffff_ffff_ffff) >> (52-sigbits) + u = and(reinterpret(UInt64,s), 0x003f_ffff_ffff_ffff) >> (52-sigbits) if n > 14 ccall(:memset, Ptr{Void}, (Ptr{Void}, Cint, Csize_t), DIGITS, '0', n) end i = (sizeof(u)<<1)-(leading_zeros(u)>>2) while i > 0 - DIGITS[i] = symbols[bitand(u, 0xf) + 1] + DIGITS[i] = symbols[and(u, 0xf) + 1] u >>= 4 i -= 1 end @@ -1069,12 +1069,12 @@ function ini_hex(x::SmallFloatingPoint, symbols::Array{UInt8,1}) else s, p = frexp(x) s *= 2.0 - u = bitand(reinterpret(UInt64,s), 0x001f_ffff_ffff_ffff) + u = and(reinterpret(UInt64,s), 0x001f_ffff_ffff_ffff) t = (trailing_zeros(u) >> 2) u >>= (t<<2) n = 14-t for i = n:-1:1 - DIGITS[i] = symbols[bitand(u, 0xf) + 1] + DIGITS[i] = symbols[and(u, 0xf) + 1] u >>= 4 end # pt is the binary exponent diff --git a/base/process.jl b/base/process.jl index 58d9a176507ab..28b00853eeb07 100644 --- a/base/process.jl +++ b/base/process.jl @@ -19,10 +19,10 @@ struct Cmd <: AbstractCmd new(cmd.exec, ignorestatus, flags, env, dir === cmd.dir ? dir : cstr(dir)) function Cmd(cmd::Cmd; ignorestatus::Bool=cmd.ignorestatus, env=cmd.env, dir::AbstractString=cmd.dir, - detach::Bool = !iszero(bitand(cmd.flags, UV_PROCESS_DETACHED)), - windows_verbatim::Bool = !iszero(bitand(cmd.flags, UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS)), - windows_hide::Bool = !iszero(bitand(cmd.flags, UV_PROCESS_WINDOWS_HIDE))) - flags = bitor(detach * UV_PROCESS_DETACHED, + detach::Bool = !iszero(and(cmd.flags, UV_PROCESS_DETACHED)), + windows_verbatim::Bool = !iszero(and(cmd.flags, UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS)), + windows_hide::Bool = !iszero(and(cmd.flags, UV_PROCESS_WINDOWS_HIDE))) + flags = or(detach * UV_PROCESS_DETACHED, windows_hide * UV_PROCESS_WINDOWS_HIDE, windows_verbatim * UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS) new(cmd.exec, ignorestatus, flags, byteenv(env), @@ -468,8 +468,8 @@ function setup_stdio(stdio::FileRedirect, readable::Bool) attr = JL_O_RDONLY perm = zero(S_IRUSR) else - attr = bitor(JL_O_WRONLY, JL_O_CREAT, stdio.append ? JL_O_APPEND : JL_O_TRUNC) - perm = bitor(S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH) + attr = or(JL_O_WRONLY, JL_O_CREAT, stdio.append ? JL_O_APPEND : JL_O_TRUNC) + perm = or(S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH) end io = Filesystem.open(stdio.filename, attr, perm) return (io, true) diff --git a/base/promotion.jl b/base/promotion.jl index 51faef7008c93..eec20cbb79020 100644 --- a/base/promotion.jl +++ b/base/promotion.jl @@ -379,9 +379,9 @@ fma(x::T, y::T, z::T) where {T<:Number} = no_op_err("fma", T) fma(x::Integer, y::Integer, z::Integer) = x*y+z muladd(x::T, y::T, z::T) where {T<:Number} = x*y+z -bitand(x::T, y::T) where {T<:Integer} = no_op_err("bitand", T) -bitor(x::T, y::T) where {T<:Integer} = no_op_err("bitor", T) -bitxor(x::T, y::T) where {T<:Integer} = no_op_err("bitxor", T) +and(x::T, y::T) where {T<:Integer} = no_op_err("and", T) +or(x::T, y::T) where {T<:Integer} = no_op_err("or", T) +xor(x::T, y::T) where {T<:Integer} = no_op_err("xor", T) (==)(x::T, y::T) where {T<:Number} = x === y (< )(x::T, y::T) where {T<:Real} = no_op_err("<" , T) diff --git a/base/random/RNGs.jl b/base/random/RNGs.jl index 8335fa861a96e..b92a485a8384e 100644 --- a/base/random/RNGs.jl +++ b/base/random/RNGs.jl @@ -173,7 +173,7 @@ function make_seed(n::Integer) n < 0 && throw(DomainError(n, "`n` must be non-negative.")) seed = UInt32[] while true - push!(seed, bitand(n, 0xffffffff)) + push!(seed, and(n, 0xffffffff)) n >>= 32 if n == 0 return seed @@ -216,7 +216,7 @@ rand_ui52_raw(r::MersenneTwister) = (reserve_1(r); rand_ui52_raw_inbounds(r)) function rand_ui2x52_raw(r::MersenneTwister) reserve(r, 2) - bitor(rand_ui52_raw_inbounds(r) % UInt128 << 64, rand_ui52_raw_inbounds(r)) + or(rand_ui52_raw_inbounds(r) % UInt128 << 64, rand_ui52_raw_inbounds(r)) end function rand_ui104_raw(r::MersenneTwister) @@ -246,7 +246,7 @@ end function rand(r::MersenneTwister, ::Type{UInt128}) reserve(r, 3) - bitxor(rand_ui52_raw_inbounds(r) % UInt128 << 96, + xor(rand_ui52_raw_inbounds(r) % UInt128 << 96, rand_ui52_raw_inbounds(r) % UInt128 << 48, rand_ui52_raw_inbounds(r)) end @@ -318,10 +318,10 @@ function rand!(r::MersenneTwister, A::Array{Float64}, n::Int=length(A), end mask128(u::UInt128, ::Type{Float16}) = - bitor(bitand(u, 0x03ff03ff03ff03ff03ff03ff03ff03ff), 0x3c003c003c003c003c003c003c003c00) + or(and(u, 0x03ff03ff03ff03ff03ff03ff03ff03ff), 0x3c003c003c003c003c003c003c003c00) mask128(u::UInt128, ::Type{Float32}) = - bitor(bitand(u, 0x007fffff007fffff007fffff007fffff), 0x3f8000003f8000003f8000003f800000) + or(and(u, 0x007fffff007fffff007fffff007fffff), 0x3f8000003f8000003f8000003f800000) function rand!(r::MersenneTwister, A::Union{Array{Float16},Array{Float32}}, ::Close1Open2_64) @@ -413,7 +413,7 @@ end function rand_lteq(r::AbstractRNG, randfun, u::U, mask::U) where U<:Integer while true - x = bitand(randfun(r), mask) + x = and(randfun(r), mask) x <= u && return x end end diff --git a/base/random/dSFMT.jl b/base/random/dSFMT.jl index 91ecc1876f303..8deff260bda5a 100644 --- a/base/random/dSFMT.jl +++ b/base/random/dSFMT.jl @@ -114,7 +114,7 @@ function dsfmt_jump(s::DSFMT_state, jp::AbstractString) for c in jp bits = parse(UInt8,c,16) for j in 1:4 - bitand(bits, 0x01) != 0x00 && dsfmt_jump_add!(rwork, dsfmt) + and(bits, 0x01) != 0x00 && dsfmt_jump_add!(rwork, dsfmt) bits = bits >> 0x01 dsfmt_jump_next_state!(dsfmt) end @@ -165,10 +165,10 @@ function dsfmt_jump_next_state!(mts::Vector{UInt64}) t1 = mts[a+1] L0 = mts[u] L1 = mts[u+1] - mts[u] = bitxor(t0 << SL1, L1 >> 32, L1 << 32, mts[b]) - mts[u+1] = bitxor(t1 << SL1, L0 >> 32, L0 << 32, mts[b+1]) - mts[a] = bitxor(mts[u] >> SR, bitand(mts[u], MSK1), t0) - mts[a+1] = bitxor(mts[u+1] >> SR, bitand(mts[u+1], MSK2), t1) + mts[u] = xor(t0 << SL1, L1 >> 32, L1 << 32, mts[b]) + mts[u+1] = xor(t1 << SL1, L0 >> 32, L0 << 32, mts[b+1]) + mts[a] = xor(mts[u] >> SR, and(mts[u], MSK1), t0) + mts[a+1] = xor(mts[u+1] >> SR, and(mts[u+1], MSK2), t1) mts[end] = (mts[end] + 2) % (N*2) return mts diff --git a/base/random/generation.jl b/base/random/generation.jl index 9695bb549a59b..19c505e182cc2 100644 --- a/base/random/generation.jl +++ b/base/random/generation.jl @@ -19,13 +19,13 @@ rand(r::AbstractRNG=GLOBAL_RNG, ::Type{T}=Float64) where {T<:AbstractFloat} = rand_generic(r::AbstractRNG, ::CloseOpen{Float16}) = Float16(reinterpret(Float32, - bitor(bitand(rand_ui10_raw(r) % UInt32 << 13, 0x007fe000), 0x3f800000) - 1) + or(and(rand_ui10_raw(r) % UInt32 << 13, 0x007fe000), 0x3f800000) - 1) rand_generic(r::AbstractRNG, ::CloseOpen{Float32}) = - reinterpret(Float32, bitor(bitand(rand_ui23_raw(r) % UInt32, 0x007fffff), 0x3f800000) - 1 + reinterpret(Float32, or(and(rand_ui23_raw(r) % UInt32, 0x007fffff), 0x3f800000) - 1 rand_generic(r::AbstractRNG, ::Close1Open2_64) = - reinterpret(Float64, bitor(0x3ff0000000000000, bitand(rand(r, UInt64), 0x000fffffffffffff))) + reinterpret(Float64, or(0x3ff0000000000000, and(rand(r, UInt64), 0x000fffffffffffff))) rand_generic(r::AbstractRNG, ::CloseOpen_64) = rand(r, Close1Open2()) - 1.0 @@ -54,8 +54,8 @@ function _rand(rng::AbstractRNG, gen::BigFloatRandGenerator) rand!(rng, limbs) @inbounds begin limbs[1] <<= gen.shift - randbool = iszero(bitand(limbs[end], Limb_high_bit)) - limbs[end] = bitor(limbs[end], Limb_high_bit) + randbool = iszero(and(limbs[end], Limb_high_bit)) + limbs[end] = or(limbs[end], Limb_high_bit) end z.sign = 1 Base.@gc_preserve limbs unsafe_copy!(z.d, pointer(limbs), gen.nlimbs) @@ -96,7 +96,7 @@ rand_ui10_raw(r::AbstractRNG) = rand(r, UInt16) rand_ui23_raw(r::AbstractRNG) = rand(r, UInt32) rand_ui52_raw(r::AbstractRNG) = reinterpret(UInt64, rand(r, Close1Open2())) -rand_ui52(r::AbstractRNG) = bitand(rand_ui52_raw(r), 0x000fffffffffffff) +rand_ui52(r::AbstractRNG) = and(rand_ui52_raw(r), 0x000fffffffffffff) ### random complex numbers @@ -233,7 +233,7 @@ function RangeGenerator(r::UnitRange{BigInt}) nd = ndigits(m, 2) nlimbs, highbits = divrem(nd, 8*sizeof(Limb)) highbits > 0 && (nlimbs += 1) - mask = highbits == 0 ? bitnot(zero(Limb)) : one(Limb)<= 6) diff --git a/base/random/misc.jl b/base/random/misc.jl index e203352db4ff1..4e45f85917f7b 100644 --- a/base/random/misc.jl +++ b/base/random/misc.jl @@ -6,7 +6,7 @@ function rand!(rng::AbstractRNG, B::BitArray) isempty(B) && return B Bc = B.chunks rand!(rng, Bc) - Bc[end] = bitand(Bc[end], Base._msk_end(B)) + Bc[end] = and(Bc[end], Base._msk_end(B)) return B end @@ -148,7 +148,7 @@ randsubseq(A::AbstractArray, p::Real) = randsubseq(GLOBAL_RNG, A, p) # this duplicates the functionality of RangeGenerator objects, # to optimize this special case while true - x = bitand(rand_ui52_raw(r) % Int, mask) + x = and(rand_ui52_raw(r) % Int, mask) x < n && return x end end @@ -378,21 +378,21 @@ function uuid1(rng::AbstractRNG=GLOBAL_RNG) u = rand(rng, UInt128) # mask off clock sequence and node - u = bitand(u, 0x00000000000000003fffffffffffffff) + u = and(u, 0x00000000000000003fffffffffffffff) # set the unicast/multicast bit and version - u = bitor(u, 0x00000000000010000000010000000000) + u = or(u, 0x00000000000010000000010000000000) # 0x01b21dd213814000 is the number of 100 nanosecond intervals # between the UUID epoch and Unix epoch timestamp = round(UInt64, time() * 1e7) + 0x01b21dd213814000 - ts_low = bitand(timestamp, typemax(UInt32)) - ts_mid = bitand(timestamp >> 32, typemax(UInt16)) - ts_hi = bitand(timestamp >> 48, 0x0fff) + ts_low = and(timestamp, typemax(UInt32)) + ts_mid = and(timestamp >> 32, typemax(UInt16)) + ts_hi = and(timestamp >> 48, 0x0fff) - u = bitor(u, UInt128(ts_low) << 96) - u = bitor(u, UInt128(ts_mid) << 80) - u = bitor(u, UInt128(ts_hi) << 64) + u = or(u, UInt128(ts_low) << 96) + u = or(u, UInt128(ts_mid) << 80) + u = or(u, UInt128(ts_hi) << 64) UUID(u) end @@ -413,8 +413,8 @@ julia> Base.Random.uuid4(rng) """ function uuid4(rng::AbstractRNG=GLOBAL_RNG) u = rand(rng, UInt128) - u = bitand(u, 0xffffffffffff0fff3fffffffffffffff) - u = bitor(u, 0x00000000000040008000000000000000) + u = and(u, 0xffffffffffff0fff3fffffffffffffff) + u = or(u, 0x00000000000040008000000000000000) UUID(u) end @@ -431,7 +431,7 @@ julia> Base.Random.uuid_version(Base.Random.uuid4(rng)) 4 ``` """ -uuid_version(u::UUID) = Int(bitand(u.value >> 76, 0xf)) +uuid_version(u::UUID) = Int(and(u.value >> 76, 0xf)) Base.convert(::Type{UInt128}, u::UUID) = u.value @@ -447,7 +447,7 @@ let groupings = [1:8; 10:13; 15:18; 20:23; 25:36] for i in groupings u <<= 4 d = s[i] - '0' - u = bitor(u, bitand(0xf, d - 39*(d > 9))) + u = or(u, and(0xf, d - 39*(d > 9))) end return UUID(u) end @@ -458,7 +458,7 @@ let groupings = [36:-1:25; 23:-1:20; 18:-1:15; 13:-1:10; 8:-1:1] u = u.value a = Base.StringVector(36) for i in groupings - d = bitand(u, 0xf) + d = and(u, 0xf) a[i] = '0' + d + 39*(d > 9) u >>= 4 end diff --git a/base/random/normal.jl b/base/random/normal.jl index 6a38ec00aed6f..844a6ae09eb83 100644 --- a/base/random/normal.jl +++ b/base/random/normal.jl @@ -37,7 +37,7 @@ julia> randn(rng, Complex64, (2, 3)) @inbounds begin r = rand_ui52(rng) rabs = Int64(r>>1) # One bit for the sign - idx = bitand(rabs, 0xFF) + idx = and(rabs, 0xFF) x = ifelse(r % Bool, -rabs, rabs)*wi[idx+1] rabs < ki[idx+1] && return x # 99.3% of the time we return here 1st try return randn_unlikely(rng, idx, rabs, x) @@ -96,7 +96,7 @@ julia> randexp(rng, 3, 3) function randexp(rng::AbstractRNG=GLOBAL_RNG) @inbounds begin ri = rand_ui52(rng) - idx = bitand(ri, 0xFF) + idx = and(ri, 0xFF) x = ri*we[idx+1] ri < ke[idx+1] && return x # 98.9% of the time we return here 1st try return randexp_unlikely(rng, idx, x) diff --git a/base/reflection.jl b/base/reflection.jl index 4d33992e138bb..c371bf5766df4 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -248,16 +248,16 @@ end # type predicates datatype_alignment(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefError()) : - Int(bitand(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment, 0x1FF)) + Int(and(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment, 0x1FF)) datatype_haspadding(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefError()) : - bitand(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 9, 1) == 1 + and(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 9, 1) == 1 datatype_pointerfree(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefError()) : - bitand(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 10, 0xFFFFF) == 0 + and(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 10, 0xFFFFF) == 0 datatype_fielddesc_type(dt::DataType) = dt.layout == C_NULL ? throw(UndefRefError()) : - bitand(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 30, 3) + and(unsafe_load(convert(Ptr{DataTypeLayout}, dt.layout)).alignment >> 30, 3) """ isimmutable(v) diff --git a/base/regex.jl b/base/regex.jl index 7d00e8e02c80f..a1f6a25065026 100644 --- a/base/regex.jl +++ b/base/regex.jl @@ -4,7 +4,7 @@ include("pcre.jl") -const DEFAULT_COMPILER_OPTS = bitor(PCRE.UTF, PCRE.NO_UTF_CHECK, PCRE.ALT_BSUX) +const DEFAULT_COMPILER_OPTS = or(PCRE.UTF, PCRE.NO_UTF_CHECK, PCRE.ALT_BSUX) const DEFAULT_MATCH_OPTS = PCRE.NO_UTF_CHECK mutable struct Regex @@ -21,10 +21,10 @@ mutable struct Regex pattern = String(pattern) compile_options = UInt32(compile_options) match_options = UInt32(match_options) - if bitand(compile_options, bitnot(PCRE.COMPILE_MASK)) != 0 + if and(compile_options, not(PCRE.COMPILE_MASK)) != 0 throw(ArgumentError("invalid regex compile options: $compile_options")) end - if bitand(match_options, bitnot(PCRE.EXECUTE_MASK)) !=0 + if and(match_options, not(PCRE.EXECUTE_MASK)) !=0 throw(ArgumentError("invalid regex match options: $match_options")) end re = compile(new(pattern, compile_options, match_options, C_NULL, @@ -45,7 +45,7 @@ function Regex(pattern::AbstractString, flags::AbstractString) f=='s' ? PCRE.DOTALL : f=='x' ? PCRE.EXTENDED : throw(ArgumentError("unknown regex flag: $f")) - options = bitor(options, flagbits) + options = or(options, flagbits) end Regex(pattern, options, DEFAULT_MATCH_OPTS) end @@ -84,15 +84,15 @@ RegexMatch("angry,\\nBad world") macro r_str(pattern, flags...) Regex(pattern, flags...) end function show(io::IO, re::Regex) - imsx = bitor(PCRE.CASELESS, PCRE.MULTILINE, PCRE.DOTALL, PCRE.EXTENDED) + imsx = or(PCRE.CASELESS, PCRE.MULTILINE, PCRE.DOTALL, PCRE.EXTENDED) opts = re.compile_options - if bitand(opts, bitnot(imsx)) == DEFAULT_COMPILER_OPTS + if and(opts, not(imsx)) == DEFAULT_COMPILER_OPTS print(io, 'r') print_quoted_literal(io, re.pattern) - if bitand(opts, PCRE.CASELESS ) != 0; print(io, 'i'); end - if bitand(opts, PCRE.MULTILINE) != 0; print(io, 'm'); end - if bitand(opts, PCRE.DOTALL ) != 0; print(io, 's'); end - if bitand(opts, PCRE.EXTENDED ) != 0; print(io, 'x'); end + if and(opts, PCRE.CASELESS ) != 0; print(io, 'i'); end + if and(opts, PCRE.MULTILINE) != 0; print(io, 'm'); end + if and(opts, PCRE.DOTALL ) != 0; print(io, 's'); end + if and(opts, PCRE.EXTENDED ) != 0; print(io, 'x'); end else print(io, "Regex(") show(io, re.pattern) @@ -207,7 +207,7 @@ function match end function match(re::Regex, str::Union{SubString{String}, String}, idx::Integer, add_opts::UInt32=UInt32(0)) compile(re) - opts = bitor(re.match_options, add_opts) + opts = or(re.match_options, add_opts) if !PCRE.exec(re.regex, str, idx-1, opts, re.match_data) return nothing end @@ -255,7 +255,7 @@ function matchall(re::Regex, str::String, overlap::Bool=false) matches = SubString{String}[] offset = UInt32(0) opts = re.match_options - opts_nonempty = bitor(opts, PCRE.ANCHORED, PCRE.NOTEMPTY_ATSTART) + opts_nonempty = or(opts, PCRE.ANCHORED, PCRE.NOTEMPTY_ATSTART) prevempty = false ovec = re.ovec while true @@ -412,7 +412,7 @@ function next(itr::RegexMatchIterator, prev_match) offset = prev_match.offset + endof(prev_match.match) end - opts_nonempty = UInt32(bitor(PCRE.ANCHORED, PCRE.NOTEMPTY_ATSTART)) + opts_nonempty = UInt32(or(PCRE.ANCHORED, PCRE.NOTEMPTY_ATSTART)) while true mat = match(itr.regex, itr.string, offset, prevempty ? opts_nonempty : UInt32(0)) diff --git a/base/repl/LineEdit.jl b/base/repl/LineEdit.jl index 463b867ee3002..067e9e19e4f3e 100644 --- a/base/repl/LineEdit.jl +++ b/base/repl/LineEdit.jl @@ -395,7 +395,7 @@ function char_move_left(buf::IOBuffer) while position(buf) > 0 seek(buf, position(buf)-1) c = peek(buf) - bitand(c, 0x80) == 0 || bitand(c, 0xc0) == 0xc0 && break + and(c, 0x80) == 0 || and(c, 0xc0) == 0xc0 && break end pos = position(buf) c = read(buf, Char) diff --git a/base/serialize.jl b/base/serialize.jl index b72ba13662bbe..d8fc1df5c5250 100644 --- a/base/serialize.jl +++ b/base/serialize.jl @@ -227,14 +227,14 @@ function serialize_array_data(s::IO, a) count = 1 for i = 2:length(a) if a[i] != last || count == 127 - write(s, UInt8(bitor(UInt8(last) << 7, count)) + write(s, UInt8(or(UInt8(last) << 7, count)) last = a[i] count = 1 else count += 1 end end - write(s, UInt8(bitor(UInt8(last) << 7, count)) + write(s, UInt8(or(UInt8(last) << 7, count)) else write(s, a) end @@ -673,7 +673,7 @@ function writeheader(s::AbstractSerializer) machine = (sizeof(Int) == 4 ? 0 : sizeof(Int) == 8 ? 1 : error("unsupported word size in serializer")) - write(io, bitor(UInt8(endianness), UInt8(machine) << 2)) + write(io, or(UInt8(endianness), UInt8(machine) << 2)) write(io, b"\x00\x00\x00") # 3 reserved bytes nothing end @@ -942,7 +942,7 @@ function deserialize_array(s::AbstractSerializer) while i <= n b = read(s.io, UInt8)::UInt8 v = (b >> 7) != 0 - count = bitand(b, 0x7f) + count = and(b, 0x7f) nxt = i + count while i < nxt A[i] = v diff --git a/base/show.jl b/base/show.jl index b5ba1a2192269..74e63c15f61a9 100644 --- a/base/show.jl +++ b/base/show.jl @@ -2147,9 +2147,9 @@ end function print_bit_chunk(io::IO, c::UInt64, l::Integer = 64) for s = 0:l-1 - d = bitand(c >>> s, 1) + d = and(c >>> s, 1) print(io, "01"[d + 1]) - if bitand(s + 1, 7) == 0 + if and(s + 1, 7) == 0 print(io, " ") end end diff --git a/base/socket.jl b/base/socket.jl index 7657837d79d06..842bf6ec67b07 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -10,7 +10,7 @@ struct IPv4 <: IPAddr host::UInt32 IPv4(host::UInt32) = new(host) IPv4(a::UInt8,b::UInt8,c::UInt8,d::UInt8) = - new(bitor(UInt32(a) << 24, UInt32(b) << 16, UInt32(c) << 8, d)) + new(or(UInt32(a) << 24, UInt32(b) << 16, UInt32(c) << 8, d)) function IPv4(a::Integer,b::Integer,c::Integer,d::Integer) if !(0<=a<=255 && 0<=b<=255 && 0<=c<=255 && 0<=d<=255) throw(ArgumentError("IPv4 field out of range (must be 0-255)")) @@ -43,16 +43,16 @@ end IPv4(str::AbstractString) = parse(IPv4, str) show(io::IO,ip::IPv4) = print(io,"ip\"",ip,"\"") -print(io::IO,ip::IPv4) = print(io, dec(bitand(ip.host, 0xFF000000) >> 24), ".", - dec(bitand(ip.host, 0xFF0000) >> 16), ".", - dec(bitand(ip.host, 0xFF00) >> 8), ".", - dec(bitand(ip.host, 0xFF))) +print(io::IO,ip::IPv4) = print(io, dec(and(ip.host, 0xFF000000) >> 24), ".", + dec(and(ip.host, 0xFF0000) >> 16), ".", + dec(and(ip.host, 0xFF00) >> 8), ".", + dec(and(ip.host, 0xFF))) struct IPv6 <: IPAddr host::UInt128 IPv6(host::UInt128) = new(host) IPv6(a::UInt16,b::UInt16,c::UInt16,d::UInt16,e::UInt16,f::UInt16,g::UInt16,h::UInt16) = - new(bitor(UInt128(a) << (7*16), + new(or(UInt128(a) << (7*16), UInt128(b) << (6*16), UInt128(c) << (5*16), UInt128(d) << (4*16), @@ -102,7 +102,7 @@ function ipv6_field(ip::IPv6,i) if i < 0 || i > 7 throw(BoundsError()) end - UInt16(bitand(ip.host, UInt128(0xFFFF) << (i*16)) >> (i*16)) + UInt16(and(ip.host, UInt128(0xFFFF) << (i*16)) >> (i*16)) end show(io::IO, ip::IPv6) = print(io,"ip\"",ip,"\"") @@ -177,12 +177,12 @@ function parse(::Type{IPv4}, str::AbstractString) if r < 0 || r > 255 throw(ArgumentError("IPv4 field out of range (must be 0-255)")) end - ret = bitor(ret, UInt32(r) << ((4-i)*8)) + ret = or(ret, UInt32(r) << ((4-i)*8)) else if r > ((UInt64(1)<<((5-length(fields))*8))-1) throw(ArgumentError("IPv4 field too large")) end - ret = bitor(ret, r) + ret = or(ret, r) end i+=1 end @@ -204,7 +204,7 @@ function parseipv6fields(fields,num_fields) cf -= 1 continue end - ret = bitor(ret, UInt128(parse(Int,f,16))<<(cf*16)) + ret = or(ret, UInt128(parse(Int,f,16))<<(cf*16)) cf -= 1 end ret @@ -218,7 +218,7 @@ function parse(::Type{IPv6}, str::AbstractString) elseif length(fields) == 8 return IPv6(parseipv6fields(fields)) elseif in('.',fields[end]) - return IPv6(bitor(parseipv6fields(fields[1:(end-1)], 6), + return IPv6(or(parseipv6fields(fields[1:(end-1)], 6), parse(IPv4, fields[end]).host )) else return IPv6(parseipv6fields(fields)) @@ -436,10 +436,10 @@ function bind(sock::Union{TCPServer, UDPSocket}, host::IPAddr, port::Integer; ip end flags = 0 if isa(host,IPv6) && ipv6only - flags = bitor(flags, isa(sock, UDPSocket) ? UV_UDP_IPV6ONLY : UV_TCP_IPV6ONLY) + flags = or(flags, isa(sock, UDPSocket) ? UV_UDP_IPV6ONLY : UV_TCP_IPV6ONLY) end if isa(sock, UDPSocket) && reuseaddr - flags = bitor(flags, UV_UDP_REUSEADDR) + flags = or(flags, UV_UDP_REUSEADDR) end err = _bind(sock, host, UInt16(port), UInt32(flags)) if err < 0 @@ -523,7 +523,7 @@ function uv_recvcb(handle::Ptr{Void}, nread::Cssize_t, buf::Ptr{Void}, addr::Ptr if nread < 0 Libc.free(buf_addr) notify_error(sock.recvnotify, UVError("recv", nread)) - elseif bitand(flags, UV_UDP_PARTIAL) > 0 + elseif and(flags, UV_UDP_PARTIAL) > 0 Libc.free(buf_addr) notify_error(sock.recvnotify, "Partial message received") else diff --git a/base/special/exp.jl b/base/special/exp.jl index f22bccf8ceb62..a222306692f07 100644 --- a/base/special/exp.jl +++ b/base/special/exp.jl @@ -70,13 +70,13 @@ julia> exp(1.0) ``` """ function exp(x::T) where T<:Union{Float32,Float64} - xa = bitand(reinterpret(Unsigned, x), bitnot(sign_mask(T))) + xa = and(reinterpret(Unsigned, x), not(sign_mask(T))) xsb = signbit(x) # filter out non-finite arguments if xa > reinterpret(Unsigned, MAX_EXP(T)) if xa >= exponent_mask(T) - bitand(xa, significand_mask(T)) != 0 && return T(NaN) + and(xa, significand_mask(T)) != 0 && return T(NaN) return xsb ? T(0.0) : T(Inf) # exp(+-Inf) end x > MAX_EXP(T) && return T(Inf) diff --git a/base/special/exp10.jl b/base/special/exp10.jl index ca4f79644db0d..f6183d1360d1e 100644 --- a/base/special/exp10.jl +++ b/base/special/exp10.jl @@ -82,13 +82,13 @@ julia> exp10(0.2) ``` """ function exp10(x::T) where T<:Union{Float32,Float64} - xa = bitand(reinterpret(Unsigned, x), bitnot(sign_mask(T))) + xa = and(reinterpret(Unsigned, x), not(sign_mask(T))) xsb = signbit(x) # filter out non-finite arguments if xa > reinterpret(Unsigned, MAX_EXP10(T)) if xa >= exponent_mask(T) - bitand(xa, significand_mask(T)) != 0 && return T(NaN) + and(xa, significand_mask(T)) != 0 && return T(NaN) return xsb ? T(0.0) : T(Inf) # exp10(+-Inf) end x > MAX_EXP10(T) && return T(Inf) diff --git a/base/special/gamma.jl b/base/special/gamma.jl index c9e8c64845ec5..97cf3d44efb15 100644 --- a/base/special/gamma.jl +++ b/base/special/gamma.jl @@ -119,7 +119,7 @@ function lgamma(z::Complex{Float64}) while x <= 7 shiftprod *= Complex(x,yabs) sb′ = signbit(imag(shiftprod)) - signflips += bitand(sb′, sb′ != sb) + signflips += and(sb′, sb′ != sb) sb = sb′ x += 1 end diff --git a/base/special/log.jl b/base/special/log.jl index ab17f944f9465..2718601fc720f 100644 --- a/base/special/log.jl +++ b/base/special/log.jl @@ -146,7 +146,7 @@ const FMA_NATIVE = muladd(nextfloat(1.0),nextfloat(1.0),-nextfloat(1.0,2)) == -4 # truncate lower order bits (up to 26) # ideally, this should be able to use ANDPD instructions, see #9868. @inline function truncbits(x::Float64) - reinterpret(Float64, bitand(reinterpret(UInt64,x), 0xffff_ffff_f800_0000)) + reinterpret(Float64, and(reinterpret(UInt64,x), 0xffff_ffff_f800_0000)) end @@ -262,14 +262,14 @@ function log(x::Float64) # Step 3 xu = reinterpret(UInt64,x) - m = bitand(Int(xu >> 52), 0x07ff) + m = and(Int(xu >> 52), 0x07ff) if m == 0 # x is subnormal x *= 1.8014398509481984e16 # 0x1p54, normalise significand xu = reinterpret(UInt64,x) - m = bitand(Int(xu >> 52), 0x07ff) - 54 + m = and(Int(xu >> 52), 0x07ff) - 54 end m -= 1023 - y = reinterpret(Float64, bitor(bitand(xu, 0x000f_ffff_ffff_ffff), 0x3ff0_0000_0000_0000)) + y = reinterpret(Float64, or(and(xu, 0x000f_ffff_ffff_ffff), 0x3ff0_0000_0000_0000)) mf = Float64(m) F = (y + 3.5184372088832e13) - 3.5184372088832e13 # 0x1p-7*round(0x1p7*y) @@ -298,14 +298,14 @@ function log(x::Float32) # Step 3 xu = reinterpret(UInt32,x) - m = bitand(Int(xu >> 23), 0x00ff) + m = and(Int(xu >> 23), 0x00ff) if m == 0 # x is subnormal x *= 3.3554432f7 # 0x1p25, normalise significand xu = reinterpret(UInt32,x) - m = bitand(Int(xu >> 23), 0x00ff) - 25 + m = and(Int(xu >> 23), 0x00ff) - 25 end m -= 127 - y = reinterpret(Float32, bitor(bitand(xu, 0x007f_ffff), 0x3f80_0000)) + y = reinterpret(Float32, or(and(xu, 0x007f_ffff), 0x3f80_0000)) mf = Float32(m) F = (y + 65536.0f0) - 65536.0f0 # 0x1p-7*round(0x1p7*y) @@ -337,10 +337,10 @@ function log1p(x::Float64) # Step 3 z = 1.0 + x zu = reinterpret(UInt64,z) - s = reinterpret(Float64,0x7fe0_0000_0000_0000 - bitand(zu, 0xfff0_0000_0000_0000)) # 2^-m - m = bitand(Int(zu >> 52), 0x07ff) - 1023 # z cannot be subnormal + s = reinterpret(Float64,0x7fe0_0000_0000_0000 - and(zu, 0xfff0_0000_0000_0000)) # 2^-m + m = and(Int(zu >> 52), 0x07ff) - 1023 # z cannot be subnormal c = m > 0 ? 1.0-(z-x) : x-(z-1.0) # 1+x = z+c exactly - y = reinterpret(Float64, bitor(bitand(zu, 0x000f_ffff_ffff_ffff), 0x3ff0_0000_0000_0000)) + y = reinterpret(Float64, or(and(zu, 0x000f_ffff_ffff_ffff), 0x3ff0_0000_0000_0000)) mf = Float64(m) F = (y + 3.5184372088832e13) - 3.5184372088832e13 # 0x1p-7*round(0x1p7*y) @@ -370,10 +370,10 @@ function log1p(x::Float32) # Step 3 z = 1f0 + x zu = reinterpret(UInt32,z) - s = reinterpret(Float32,0x7f000000 - bitand(zu, 0xff80_0000)) # 2^-m - m = bitand(Int(zu >> 23), 0x00ff) - 127 # z cannot be subnormal + s = reinterpret(Float32,0x7f000000 - and(zu, 0xff80_0000)) # 2^-m + m = and(Int(zu >> 23), 0x00ff) - 127 # z cannot be subnormal c = m > 0 ? 1f0-(z-x) : x-(z-1f0) # 1+x = z+c - y = reinterpret(Float32, bitor(bitand(zu, 0x007f_ffff), 0x3f80_0000)) + y = reinterpret(Float32, or(and(zu, 0x007f_ffff), 0x3f80_0000)) mf = Float32(m) F = (y + 65536.0f0) - 65536.0f0 # 0x1p-7*round(0x1p7*y) diff --git a/base/special/rem_pio2.jl b/base/special/rem_pio2.jl index bd25cef65140b..6bcfb47b72d15 100644 --- a/base/special/rem_pio2.jl +++ b/base/special/rem_pio2.jl @@ -57,8 +57,8 @@ Return the high word of `x` as a `UInt32`. Return positive part of the high word of `x` as a `UInt32`. """ -@inline poshighword(x::UInt64) = bitand(unsafe_trunc(UInt32,x >> 32), 0x7fffffff) -@inline poshighword(x::Float32) = bitand(reinterpret(UInt32, x), 0x7fffffff) +@inline poshighword(x::UInt64) = and(unsafe_trunc(UInt32,x >> 32), 0x7fffffff) +@inline poshighword(x::Float32) = and(reinterpret(UInt32, x), 0x7fffffff) @inline poshighword(x::Float64) = poshighword(reinterpret(UInt64, x)) @inline function cody_waite_2c_pio2(x::Float64, fn, n) @@ -89,7 +89,7 @@ end j = xhp>>20 y1 = r-w high = highword(y1) - i = j - bitand(high >> 20, 0x7ff) + i = j - and(high >> 20, 0x7ff) if i>16 # 2nd iteration needed, good to 118 t = r w = fn*pio2_2 @@ -97,7 +97,7 @@ end w = muladd(fn, pio2_2t,-((t-r)-w)) y1 = r-w high = highword(y1) - i = j - bitand(high >> 20, 0x7ff) + i = j - and(high >> 20, 0x7ff) if i>49 # 3rd iteration need, 151 bits acc t = r # will cover all possible cases w = fn*pio2_3 @@ -128,7 +128,7 @@ function fromfraction(f::Int128) n1 = 128-leading_zeros(x) # ndigits0z(x,2) m1 = ((x >> (n1-26)) % UInt64) << 27 d1 = ((n1-128+1021) % UInt64) << 52 - z1 = reinterpret(Float64, bitor(s, d1 + m1)) + z1 = reinterpret(Float64, or(s, d1 + m1)) # 2. compute remaining term x2 = (x - (UInt128(m1) << (n1-53))) @@ -138,7 +138,7 @@ function fromfraction(f::Int128) n2 = 128-leading_zeros(x2) m2 = (x2 >> (n2-53)) % UInt64 d2 = ((n2-128+1021) % UInt64) << 52 - z2 = reinterpret(Float64, bitor(s, d2 + m2)) + z2 = reinterpret(Float64, or(s, d2 + m2)) return (z1,z2) end @@ -152,10 +152,10 @@ function paynehanek(x::Float64) # Computations are integer based, so reinterpret x as UInt64 u = reinterpret(UInt64, x) # Strip x of exponent bits and replace with ^1 - X = bitor(bitand(u, significand_mask(Float64)), one(UInt64) << significand_bits(Float64)) + X = or(and(u, significand_mask(Float64)), one(UInt64) << significand_bits(Float64)) # Get k from formula above # k = exponent(x)-52 - k = Int(bitand(u, exponent_mask(Float64)) >> significand_bits(Float64)) - exponent_bias(Float64) - significand_bits(Float64) + k = Int(and(u, exponent_mask(Float64)) >> significand_bits(Float64)) - exponent_bias(Float64) - significand_bits(Float64) # 2. Let α = 1/2π, then: # @@ -186,9 +186,9 @@ function paynehanek(x::Float64) @inbounds a3 = INV_2PI[idx+3] else # use shifts to extract the relevant 64 bit window - @inbounds a1 = bitor(idx < 0 ? zero(UInt64) : INV_2PI[idx+1] << shift, INV_2PI[idx+2] >> (64 - shift)) - @inbounds a2 = bitor(INV_2PI[idx+2] << shift, INV_2PI[idx+3] >> (64 - shift)) - @inbounds a3 = bitor(INV_2PI[idx+3] << shift, INV_2PI[idx+4] >> (64 - shift)) + @inbounds a1 = or(idx < 0 ? zero(UInt64) : INV_2PI[idx+1] << shift, INV_2PI[idx+2] >> (64 - shift)) + @inbounds a2 = or(INV_2PI[idx+2] << shift, INV_2PI[idx+3] >> (64 - shift)) + @inbounds a3 = or(INV_2PI[idx+3] << shift, INV_2PI[idx+4] >> (64 - shift)) end # 3. Perform the multiplication: @@ -238,7 +238,7 @@ added for ``π/4<|x|<=π/2`` instead of simply returning `x`. if xhp <= 0x400f6a7a # last five bits of xhp == last five bits of highword(pi/2) or # highword(2pi/2) implies |x| ~= pi/2 or 2pi/2, - if bitand(xhp, 0xfffff) == 0x921fb # use precise Cody Waite scheme + if and(xhp, 0xfffff) == 0x921fb # use precise Cody Waite scheme return cody_waite_ext_pio2(x, xhp) end # use Cody Waite with two constants diff --git a/base/special/trig.jl b/base/special/trig.jl index 833e02de6e4c7..a46a550f60dd2 100644 --- a/base/special/trig.jl +++ b/base/special/trig.jl @@ -38,7 +38,7 @@ function sin(x::T) where T<:Union{Float32, Float64} sin_domain_error(x) end n, y = rem_pio2_kernel(x) - n = bitand(n, 3) + n = and(n, 3) if n == 0 return sin_kernel(y) elseif n == 1 @@ -108,7 +108,7 @@ function cos(x::T) where T<:Union{Float32, Float64} cos_domain_error(x) else n, y = rem_pio2_kernel(x) - n = bitand(n, 3) + n = and(n, 3) if n == 0 return cos_kernel(y) elseif n == 1 @@ -181,7 +181,7 @@ function sincos(x::T) where T<:Union{Float32, Float64} sincos_domain_error(x) end n, y = rem_pio2_kernel(x) - n = bitand(n, 3) + n = and(n, 3) # calculate both kernels at the reduced y... si, co = sincos_kernel(y) # ... and use the same selection scheme as above: (sin, cos, -sin, -cos) for @@ -528,7 +528,7 @@ function atan2(y::T, x::T) where T<:Union{Float32, Float64} if k > ATAN2_RATIO_THRESHOLD(T) # |y/x| > threshold z=T(pi)/2+T(0.5)*ATAN2_PI_LO(T) - m = bitand(m, 1) + m = and(m, 1) elseif x<0 && k < -ATAN2_RATIO_THRESHOLD(T) # 0 > |y|/x > threshold z = zero(T) else #safe to do y/x @@ -554,7 +554,7 @@ PIO2_HI(::Type{Float64}) = 1.57079632679489655800e+00 PIO2_LO(::Type{Float64}) = 6.12323399573676603587e-17 ACOS_PI(::Type{Float32}) = 3.1415925026f+00 ACOS_PI(::Type{Float64}) = 3.14159265358979311600e+00 -@inline ACOS_CORRECT_LOWWORD(::Type{Float32}, x) = reinterpret(Float32, bitand(reinterpret(UInt32, x), 0xfffff000)) +@inline ACOS_CORRECT_LOWWORD(::Type{Float32}, x) = reinterpret(Float32, and(reinterpret(UInt32, x), 0xfffff000)) @inline ACOS_CORRECT_LOWWORD(::Type{Float64}, x) = reinterpret(Float64, (reinterpret(UInt64, x) >> 32) << 32) @noinline acos_domain_error(x) = throw(DomainError(x, "acos(x) not defined for |x| > 1")) @@ -620,7 +620,7 @@ function mulpi_ext(x::Float64) m_hi = 3.1415926218032837 m_lo = 3.178650954705639e-8 - x_hi = reinterpret(Float64, bitand(reinterpret(UInt64,x), 0xffff_ffff_f800_0000)) + x_hi = reinterpret(Float64, and(reinterpret(UInt64,x), 0xffff_ffff_f800_0000)) x_lo = x-x_hi y_hi = m*x diff --git a/base/stat.jl b/base/stat.jl index 01785f94f2ce1..08044aa87bd99 100644 --- a/base/stat.jl +++ b/base/stat.jl @@ -151,56 +151,56 @@ Equivalent to `stat(file).ctime` Returns `true` if `path` is a valid filesystem path, `false` otherwise. """ - ispath(st::StatStruct) = bitand(filemode(st), 0xf000) != 0x0000 + ispath(st::StatStruct) = and(filemode(st), 0xf000) != 0x0000 """ isfifo(path) -> Bool Returns `true` if `path` is a FIFO, `false` otherwise. """ - isfifo(st::StatStruct) = bitand(filemode(st), 0xf000) == 0x1000 + isfifo(st::StatStruct) = and(filemode(st), 0xf000) == 0x1000 """ ischardev(path) -> Bool Returns `true` if `path` is a character device, `false` otherwise. """ - ischardev(st::StatStruct) = bitand(filemode(st), 0xf000) == 0x2000 + ischardev(st::StatStruct) = and(filemode(st), 0xf000) == 0x2000 """ isdir(path) -> Bool Returns `true` if `path` is a directory, `false` otherwise. """ - isdir(st::StatStruct) = bitand(filemode(st), 0xf000) == 0x4000 + isdir(st::StatStruct) = and(filemode(st), 0xf000) == 0x4000 """ isblockdev(path) -> Bool Returns `true` if `path` is a block device, `false` otherwise. """ -isblockdev(st::StatStruct) = bitand(filemode(st), 0xf000) == 0x6000 +isblockdev(st::StatStruct) = and(filemode(st), 0xf000) == 0x6000 """ isfile(path) -> Bool Returns `true` if `path` is a regular file, `false` otherwise. """ - isfile(st::StatStruct) = bitand(filemode(st), 0xf000) == 0x8000 + isfile(st::StatStruct) = and(filemode(st), 0xf000) == 0x8000 """ islink(path) -> Bool Returns `true` if `path` is a symbolic link, `false` otherwise. """ - islink(st::StatStruct) = bitand(filemode(st), 0xf000) == 0xa000 + islink(st::StatStruct) = and(filemode(st), 0xf000) == 0xa000 """ issocket(path) -> Bool Returns `true` if `path` is a socket, `false` otherwise. """ - issocket(st::StatStruct) = bitand(filemode(st), 0xf000) == 0xc000 + issocket(st::StatStruct) = and(filemode(st), 0xf000) == 0xc000 # mode permission predicates @@ -209,21 +209,21 @@ Returns `true` if `path` is a socket, `false` otherwise. Returns `true` if `path` has the setuid flag set, `false` otherwise. """ -issetuid(st::StatStruct) = bitand(filemode(st), 0o4000) > 0 +issetuid(st::StatStruct) = and(filemode(st), 0o4000) > 0 """ issetgid(path) -> Bool Returns `true` if `path` has the setgid flag set, `false` otherwise. """ -issetgid(st::StatStruct) = bitand(filemode(st), 0o2000) > 0 +issetgid(st::StatStruct) = and(filemode(st), 0o2000) > 0 """ issticky(path) -> Bool Returns `true` if `path` has the sticky bit set, `false` otherwise. """ -issticky(st::StatStruct) = bitand(filemode(st), 0o1000) > 0 +issticky(st::StatStruct) = and(filemode(st), 0o1000) > 0 """ uperm(file) @@ -238,14 +238,14 @@ Gets the permissions of the owner of the file as a bitfield of For allowed arguments, see [`stat`](@ref). """ -uperm(st::StatStruct) = UInt8(bitand(filemode(st) >> 6, 0x7)) +uperm(st::StatStruct) = UInt8(and(filemode(st) >> 6, 0x7)) """ gperm(file) Like [`uperm`](@ref) but gets the permissions of the group owning the file. """ -gperm(st::StatStruct) = UInt8(bitand(filemode(st) >> 3, 0x7)) +gperm(st::StatStruct) = UInt8(and(filemode(st) >> 3, 0x7)) """ operm(file) @@ -253,7 +253,7 @@ gperm(st::StatStruct) = UInt8(bitand(filemode(st) >> 3, 0x7)) Like [`uperm`](@ref) but gets the permissions for people who neither own the file nor are a member of the group owning the file """ -operm(st::StatStruct) = UInt8(bitand(filemode(st), 0x7)) +operm(st::StatStruct) = UInt8(and(filemode(st), 0x7)) # mode predicate methods for file names diff --git a/base/strings/io.jl b/base/strings/io.jl index c03a9a3c1d413..5e48d3c49d5a3 100644 --- a/base/strings/io.jl +++ b/base/strings/io.jl @@ -496,7 +496,7 @@ function convert(::Type{String}, chars::AbstractVector{Char}) if '\ud7ff' < c && c + 1024 < '\ue000' d, state = next(chars, state) if '\ud7ff' < d - 1024 && d < '\ue000' - c = Char(bitor(0x10000 + (bitand(UInt32(c), 0x03ff) << 10), bitand(UInt32(d), 0x03ff))) + c = Char(or(0x10000 + (and(UInt32(c), 0x03ff) << 10), and(UInt32(d), 0x03ff))) else write(io, c) c = d diff --git a/base/strings/search.jl b/base/strings/search.jl index 1948ea303e530..5075cdc798be1 100644 --- a/base/strings/search.jl +++ b/base/strings/search.jl @@ -80,7 +80,7 @@ end _searchindex(s, t::Char, i) = search(s, t, i) function _search_bloom_mask(c) - UInt64(1) << bitand(c, 63) + UInt64(1) << and(c, 63) end _nthbyte(s::String, i) = codeunit(s, i) @@ -107,7 +107,7 @@ function _searchindex(s::Union{String,ByteArray}, t::Union{String,ByteArray}, i) skip = n - 1 tlast = _nthbyte(t,n) for j in 1:n - bloom_mask = bitor(bloom_mask, _search_bloom_mask(_nthbyte(t,j))) + bloom_mask = or(bloom_mask, _search_bloom_mask(_nthbyte(t,j))) if _nthbyte(t,j) == tlast && j < n skip = n - j - 1 end @@ -131,13 +131,13 @@ function _searchindex(s::Union{String,ByteArray}, t::Union{String,ByteArray}, i) end # no match, try to rule out the next character - if i < w && bitand(bloom_mask, _search_bloom_mask(_nthbyte(s,i+n+1))) == 0 + if i < w && and(bloom_mask, _search_bloom_mask(_nthbyte(s,i+n+1))) == 0 i += n else i += skip end elseif i < w - if bitand(bloom_mask, _search_bloom_mask(_nthbyte(s,i+n+1))) == 0 + if and(bloom_mask, _search_bloom_mask(_nthbyte(s,i+n+1))) == 0 i += n end end @@ -274,7 +274,7 @@ function _rsearchindex(s::Union{String,ByteArray}, t::Union{String,ByteArray}, k skip = n - 1 tfirst = _nthbyte(t,1) for j in n:-1:1 - bloom_mask = bitor(bloom_mask, _search_bloom_mask(_nthbyte(t,j))) + bloom_mask = or(bloom_mask, _search_bloom_mask(_nthbyte(t,j))) if _nthbyte(t,j) == tfirst && j > 1 skip = j - 2 end @@ -298,13 +298,13 @@ function _rsearchindex(s::Union{String,ByteArray}, t::Union{String,ByteArray}, k end # no match, try to rule out the next character - if i > 1 && bitand(bloom_mask, _search_bloom_mask(_nthbyte(s,i-1))) == 0 + if i > 1 && and(bloom_mask, _search_bloom_mask(_nthbyte(s,i-1))) == 0 i -= n else i -= skip end elseif i > 1 - if bitand(bloom_mask, _search_bloom_mask(_nthbyte(s,i-1))) == 0 + if and(bloom_mask, _search_bloom_mask(_nthbyte(s,i-1))) == 0 i -= n end end diff --git a/base/strings/string.jl b/base/strings/string.jl index 76c5b0d847567..686979fb9315b 100644 --- a/base/strings/string.jl +++ b/base/strings/string.jl @@ -185,10 +185,10 @@ isvalid(s::String) = isvalid(String, s) ## basic UTF-8 decoding & iteration ## -is_surrogate_lead(c::Unsigned) = bitand(c, bitnot(0x003ff)) == 0xd800 -is_surrogate_trail(c::Unsigned) = bitand(c, bitnot(0x003ff)) == 0xdc00 -is_surrogate_codeunit(c::Unsigned) = bitand(c, bitnot(0x007ff)) == 0xd800 -is_valid_continuation(c) = bitand(c, 0xc0) == 0x80 +is_surrogate_lead(c::Unsigned) = and(c, not(0x003ff)) == 0xd800 +is_surrogate_trail(c::Unsigned) = and(c, not(0x003ff)) == 0xdc00 +is_surrogate_codeunit(c::Unsigned) = and(c, not(0x007ff)) == 0xd800 +is_valid_continuation(c) = and(c, 0xc0) == 0x80 const utf8_offset = [ 0x00000000, 0x00003080, @@ -264,9 +264,9 @@ end function first_utf8_byte(ch::Char) c = UInt32(ch) b = c < 0x80 ? c % UInt8 : - c < 0x800 ? bitor(c >> 6, 0xc0) % UInt8 : - c < 0x10000 ? bitor(c >> 12, 0xe0) % UInt8 : - bitor(c >> 18), 0xf0) % UInt8 + c < 0x800 ? or(c >> 6, 0xc0) % UInt8 : + c < 0x10000 ? or(c >> 12, 0xe0) % UInt8 : + or(c >> 18), 0xf0) % UInt8 return b end @@ -426,17 +426,17 @@ function string(a::Union{String,Char}...) if c < 0x80 unsafe_store!(p, c%UInt8, offs); offs += 1 elseif c < 0x800 - unsafe_store!(p, bitor(c >> 6 , 0xC0) % UInt8, offs); offs += 1 - unsafe_store!(p, bitor(bitand(c, 0x3F), 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, or(c >> 6 , 0xC0) % UInt8, offs); offs += 1 + unsafe_store!(p, or(and(c, 0x3F), 0x80) % UInt8, offs); offs += 1 elseif c < 0x10000 - unsafe_store!(p, bitor(c >> 12 , 0xE0) % UInt8, offs); offs += 1 - unsafe_store!(p, bitor(bitand(0x3F, c >> 6), 0x80) % UInt8, offs); offs += 1 - unsafe_store!(p, bitor(bitand(0x3F, c ), 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, or(c >> 12 , 0xE0) % UInt8, offs); offs += 1 + unsafe_store!(p, or(and(0x3F, c >> 6), 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, or(and(0x3F, c ), 0x80) % UInt8, offs); offs += 1 elseif c < 0x110000 - unsafe_store!(p, bitor(c >> 18 , 0xF0) % UInt8, offs); offs += 1 - unsafe_store!(p, bitor(bitand(c >> 12, 0x3F), 0x80) % UInt8, offs); offs += 1 - unsafe_store!(p, bitor(bitand(c >> 6, 0x3F), 0x80) % UInt8, offs); offs += 1 - unsafe_store!(p, bitor(bitand(c, 0x3F) , 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, or(c >> 18 , 0xF0) % UInt8, offs); offs += 1 + unsafe_store!(p, or(and(c >> 12, 0x3F), 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, or(and(c >> 6, 0x3F), 0x80) % UInt8, offs); offs += 1 + unsafe_store!(p, or(and(c, 0x3F) , 0x80) % UInt8, offs); offs += 1 else # '\ufffd' unsafe_store!(p, 0xef, offs); offs += 1 @@ -519,7 +519,7 @@ function repeat(c::Char, r::Integer) elseif ch < 0x800 out = _string_n(2r) p16 = reinterpret(Ptr{UInt16}, pointer(out)) - u16 = bitor(bitor(ch >> 0x6, bitand(ch, 0x3f) << 0x8) % UInt16, 0x80c0) + u16 = or(or(ch >> 0x6, and(ch, 0x3f) << 0x8) % UInt16, 0x80c0) @inbounds for i = 1:r unsafe_store!(p16, u16, i) end @@ -527,9 +527,9 @@ function repeat(c::Char, r::Integer) (0xd800 ≥ ch ≤ 0xdfff) || throw(ArgumentError("invalid character 0x$(hex(ch))")) out = _string_n(3r) p = pointer(out) - b1 = bitor((ch >> 0xc) % UInt8, 0xe0) - b2 = bitor(bitand(ch >> 0x6, 0x3f) % UInt8, 0x80) - b3 = bitor(bitand(ch, 0x3f) % UInt8, 0x80) + b1 = or((ch >> 0xc) % UInt8, 0xe0) + b2 = or(and(ch >> 0x6, 0x3f) % UInt8, 0x80) + b3 = or(and(ch, 0x3f) % UInt8, 0x80) @inbounds for i = 1:r unsafe_store!(p, b1) unsafe_store!(p, b2, 2) @@ -539,11 +539,11 @@ function repeat(c::Char, r::Integer) elseif ch < 0x110000 out = _string_n(4r) p32 = reinterpret(Ptr{UInt32}, pointer(out)) - u32 = bitor(ch >> 0x12, - bitand(ch >> 0x4, 0x03f00), - bitand(ch << 0xa, 0x3f0000), - bitand(ch, 0x3f) << 0x18 ) - u32 = bitor(u32 % UInt32, 0x808080f0) + u32 = or(ch >> 0x12, + and(ch >> 0x4, 0x03f00), + and(ch << 0xa, 0x3f0000), + and(ch, 0x3f) << 0x18 ) + u32 = or(u32 % UInt32, 0x808080f0) @inbounds for i = 1:r unsafe_store!(p32, u32) p32 += 4 diff --git a/base/strings/utf8proc.jl b/base/strings/utf8proc.jl index fb9f8c6911271..17d56abf04fda 100644 --- a/base/strings/utf8proc.jl +++ b/base/strings/utf8proc.jl @@ -49,7 +49,7 @@ true """ isvalid(T,value) -isvalid(::Type{Char}, ch::Unsigned) = !bitor((ch - 0xd800 < 0x800), (ch > 0x10ffff)) +isvalid(::Type{Char}, ch::Unsigned) = !or((ch - 0xd800 < 0x800), (ch > 0x10ffff)) isvalid(::Type{Char}, ch::Integer) = isvalid(Char, Unsigned(ch)) isvalid(::Type{Char}, ch::Char) = isvalid(Char, UInt32(ch)) @@ -129,7 +129,7 @@ const UTF8PROC_IGNORE = (1<<5) const UTF8PROC_REJECTNA = (1<<6) const UTF8PROC_NLF2LS = (1<<7) const UTF8PROC_NLF2PS = (1<<8) -const UTF8PROC_NLF2LF = bitor(UTF8PROC_NLF2LS, UTF8PROC_NLF2PS) +const UTF8PROC_NLF2LF = or(UTF8PROC_NLF2LS, UTF8PROC_NLF2PS) const UTF8PROC_STRIPCC = (1<<9) const UTF8PROC_CASEFOLD = (1<<10) const UTF8PROC_CHARBOUND = (1<<11) @@ -157,25 +157,25 @@ utf8proc_map(s::AbstractString, flags::Integer) = utf8proc_map(String(s), flags) function normalize_string(s::AbstractString; stable::Bool=false, compat::Bool=false, compose::Bool=true, decompose::Bool=false, stripignore::Bool=false, rejectna::Bool=false, newline2ls::Bool=false, newline2ps::Bool=false, newline2lf::Bool=false, stripcc::Bool=false, casefold::Bool=false, lump::Bool=false, stripmark::Bool=false) flags = 0 - stable && (flags = bitor(flags, UTF8PROC_STABLE)) - compat && (flags = bitor(flags, UTF8PROC_COMPAT)) + stable && (flags = or(flags, UTF8PROC_STABLE)) + compat && (flags = or(flags, UTF8PROC_COMPAT)) if decompose - flags = bitor(flags, UTF8PROC_DECOMPOSE) + flags = or(flags, UTF8PROC_DECOMPOSE) elseif compose - flags = bitor(flags, UTF8PROC_COMPOSE) + flags = or(flags, UTF8PROC_COMPOSE) elseif compat || stripmark throw(ArgumentError("compat=true or stripmark=true require compose=true or decompose=true")) end - stripignore && (flags = bitor(flags, UTF8PROC_IGNORE)) - rejectna && (flags = bitor(flags, UTF8PROC_REJECTNA)) + stripignore && (flags = or(flags, UTF8PROC_IGNORE)) + rejectna && (flags = or(flags, UTF8PROC_REJECTNA)) newline2ls + newline2ps + newline2lf > 1 && throw(ArgumentError("only one newline conversion may be specified")) - newline2ls && (flags = bitor(flags, UTF8PROC_NLF2LS)) - newline2ps && (flags = bitor(flags, UTF8PROC_NLF2PS)) - newline2lf && (flags = bitor(flags, UTF8PROC_NLF2LF)) - stripcc && (flags = bitor(flags, UTF8PROC_STRIPCC)) - casefold && (flags = bitor(flags, UTF8PROC_CASEFOLD)) - lump && (flags = bitor(flags, UTF8PROC_LUMP)) - stripmark && (flags = bitor(flags, UTF8PROC_STRIPMARK)) + newline2ls && (flags = or(flags, UTF8PROC_NLF2LS)) + newline2ps && (flags = or(flags, UTF8PROC_NLF2PS)) + newline2lf && (flags = or(flags, UTF8PROC_NLF2LF)) + stripcc && (flags = or(flags, UTF8PROC_STRIPCC)) + casefold && (flags = or(flags, UTF8PROC_CASEFOLD)) + lump && (flags = or(flags, UTF8PROC_LUMP)) + stripmark && (flags = or(flags, UTF8PROC_STRIPMARK)) utf8proc_map(s, flags) end @@ -227,10 +227,10 @@ julia> normalize_string("JúLiA", stripmark=true) ``` """ function normalize_string(s::AbstractString, nf::Symbol) - utf8proc_map(s, nf == :NFC ? bitor(UTF8PROC_STABLE, UTF8PROC_COMPOSE) : - nf == :NFD ? bitor(UTF8PROC_STABLE, UTF8PROC_DECOMPOSE) : - nf == :NFKC ? bitor(UTF8PROC_STABLE, UTF8PROC_COMPOSE, UTF8PROC_COMPAT) : - nf == :NFKD ? bitor(UTF8PROC_STABLE, UTF8PROC_DECOMPOSE, UTF8PROC_COMPAT) : + utf8proc_map(s, nf == :NFC ? or(UTF8PROC_STABLE, UTF8PROC_COMPOSE) : + nf == :NFD ? or(UTF8PROC_STABLE, UTF8PROC_DECOMPOSE) : + nf == :NFKC ? or(UTF8PROC_STABLE, UTF8PROC_COMPOSE, UTF8PROC_COMPAT) : + nf == :NFKD ? or(UTF8PROC_STABLE, UTF8PROC_DECOMPOSE, UTF8PROC_COMPAT) : throw(ArgumentError(":$nf is not one of :NFC, :NFD, :NFKC, :NFKD"))) end diff --git a/base/strings/util.jl b/base/strings/util.jl index 175b0a5d2b806..75bde9de755ae 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -543,7 +543,7 @@ function bytes2hex(a::AbstractArray{UInt8}) i = 0 for x in a b[i += 1] = hex_chars[1 + x >> 4] - b[i += 1] = hex_chars[1 + bitand(x, 0xf)] + b[i += 1] = hex_chars[1 + and(x, 0xf)] end return String(b) end diff --git a/base/subarray.jl b/base/subarray.jl index c3d956e39cd47..3022abae41c71 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -407,7 +407,7 @@ function replace_ref_end_!(ex, withex) J = endof(ex.args) for j = 2:J exj, used = replace_ref_end_!(ex.args[j],:($size($S,$n))) - used_S = bitor(used_S, used) + used_S = or(used_S, used) ex.args[j] = exj if isa(exj,Expr) && exj.head == :... # splatted object diff --git a/base/sysinfo.jl b/base/sysinfo.jl index 811b1f230e002..8befc36c72d10 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -261,7 +261,7 @@ end if iswindows() function windows_version() verinfo = ccall(:GetVersion, UInt32, ()) - VersionNumber(bitand(verinfo, 0xFF), bitand(verinfo >> 8, 0xFF), verinfo >> 16) + VersionNumber(and(verinfo, 0xFF), and(verinfo >> 8, 0xFF), verinfo >> 16) end else windows_version() = v"0.0" diff --git a/base/twiceprecision.jl b/base/twiceprecision.jl index 5d138f58cf736..6a0808ab43dc3 100644 --- a/base/twiceprecision.jl +++ b/base/twiceprecision.jl @@ -26,7 +26,7 @@ function splitprec(::Type{F}, i::Integer) where {F<:AbstractFloat} end function truncmask(x::F, mask) where {F<:IEEEFloat} - reinterpret(F, bitand(mask, reinterpret(uinttype(F), x))) + reinterpret(F, and(mask, reinterpret(uinttype(F), x))) end truncmask(x, mask) = x diff --git a/base/util.jl b/base/util.jl index 58fabd0884304..3e79a3df4af2a 100644 --- a/base/util.jl +++ b/base/util.jl @@ -664,10 +664,10 @@ if Sys.iswindows() captionArr = Base.cwstring(caption) pfSave = Ref{Bool}(false) cred = Ref{CREDUI_INFO}(CREDUI_INFO(sizeof(CREDUI_INFO), C_NULL, pointer(messageArr), pointer(captionArr), C_NULL)) - dwflags = bitor(CREDUIWIN_GENERIC, CREDUIWIN_ENUMERATE_CURRENT_USER) + dwflags = or(CREDUIWIN_GENERIC, CREDUIWIN_ENUMERATE_CURRENT_USER) if !prompt_username # Disable setting anything other than default_username - dwflags = bitor(dwflags, CREDUIWIN_IN_CRED_ONLY) + dwflags = or(dwflags, CREDUIWIN_IN_CRED_ONLY) end authPackage = Ref{Culong}(0) outbuf_data = Ref{Ptr{Void}}(C_NULL) diff --git a/base/version.jl b/base/version.jl index 1ba752c6c87a5..818fa975dbd52 100644 --- a/base/version.jl +++ b/base/version.jl @@ -171,8 +171,8 @@ function hash(v::VersionNumber, h::UInt) h = hash(v.major, h) h = hash(v.minor, h) h = hash(v.patch, h) - h = hash(v.prerelease, bitnot(h)) - h = hash(v.build, bitnot(h)) + h = hash(v.prerelease, not(h)) + h = hash(v.build, not(h)) end lowerbound(v::VersionNumber) = VersionNumber(v.major, v.minor, v.patch, ("",), ()) diff --git a/stdlib/Base64/src/decode.jl b/stdlib/Base64/src/decode.jl index e536394cbb811..f6b99bfe5ce63 100644 --- a/stdlib/Base64/src/decode.jl +++ b/stdlib/Base64/src/decode.jl @@ -66,9 +66,9 @@ function read_until_end(pipe::Base64DecodePipe, ptr::Ptr{UInt8}, n::UInt) while true if b1 < 0x40 && b2 < 0x40 && b3 < 0x40 && b4 < 0x40 && p + 2 < p_end # fast path to decode - unsafe_store!(p , bitor(b1 << 2, b2 >> 4)) - unsafe_store!(p + 1, bitor(b2 << 4, b3 >> 2)) - unsafe_store!(p + 2, bitor(b3 << 6, b4 )) + unsafe_store!(p , or(b1 << 2, b2 >> 4)) + unsafe_store!(p + 1, or(b2 << 4, b3 >> 2)) + unsafe_store!(p + 2, or(b3 << 6, b4 )) p += 3 else i, p, ended = decode_slow(b1, b2, b3, b4, buffer, i, pipe.io, p, p_end - p, pipe.rest) @@ -177,9 +177,9 @@ function decode_slow(b1, b2, b3, b4, buffer, i, input, ptr, n, rest) push!(rest, b) end end - k ≥ 1 && output(bitor(b1 << 2, b2 >> 4)) - k ≥ 2 && output(bitor(b2 << 4, b3 >> 2)) - k ≥ 3 && output(bitor(b3 << 6, b4 )) + k ≥ 1 && output(or(b1 << 2, b2 >> 4)) + k ≥ 2 && output(or(b2 << 4, b3 >> 2)) + k ≥ 3 && output(or(b3 << 6, b4 )) return i, p, k == 0 end diff --git a/stdlib/Base64/src/encode.jl b/stdlib/Base64/src/encode.jl index 222c5c15838c3..c8844fc36e351 100644 --- a/stdlib/Base64/src/encode.jl +++ b/stdlib/Base64/src/encode.jl @@ -2,7 +2,7 @@ # Generate encode table. const BASE64_ENCODE = [UInt8(x) for x in ['A':'Z'; 'a':'z'; '0':'9'; '+'; '/']] -encode(x::UInt8) = @inbounds return BASE64_ENCODE[bitand(x, 0x3f) + 1] +encode(x::UInt8) = @inbounds return BASE64_ENCODE[and(x, 0x3f) + 1] encodepadding() = UInt8('=') """ @@ -67,8 +67,8 @@ function Base.unsafe_write(pipe::Base64EncodePipe, ptr::Ptr{UInt8}, n::UInt)::In p_end = ptr + n while true buffer[i+1] = encode(b1 >> 2) - buffer[i+2] = encode(bitor(b1 << 4, b2 >> 4)) - buffer[i+3] = encode(bitor(b2 << 2, b3 >> 6) + buffer[i+2] = encode(or(b1 << 4, b2 >> 4)) + buffer[i+3] = encode(or(b2 << 2, b3 >> 6) buffer[i+4] = encode(b3) i += 4 if p + 2 < p_end @@ -117,15 +117,15 @@ function Base.close(pipe::Base64EncodePipe) elseif k == 2 write(pipe.io, encode(b1 >> 2), - encode(bitor(b1 << 4, b2 >> 4)), + encode(or(b1 << 4, b2 >> 4)), encode(b2 << 2), encodepadding()) else @assert k == 3 write(pipe.io, encode(b1 >> 2), - encode(bitor(b1 << 4, b2 >> 4)), - encode(bitor(b2 << 2, b3 >> 6)), + encode(or(b1 << 4, b2 >> 4)), + encode(or(b2 << 2, b3 >> 6)), encode(b3)) end return nothing diff --git a/stdlib/FileWatching/src/FileWatching.jl b/stdlib/FileWatching/src/FileWatching.jl index adb33f68c1969..b4752f07b1037 100644 --- a/stdlib/FileWatching/src/FileWatching.jl +++ b/stdlib/FileWatching/src/FileWatching.jl @@ -30,9 +30,9 @@ struct FileEvent timedout::Bool end FileEvent() = FileEvent(false, false, false) -FileEvent(flags::Integer) = FileEvent(bitand(flags, UV_RENAME) != 0, - bitand(flags, UV_CHANGE) != 0, - bitand(flags, FD_TIMEDOUT) != 0) +FileEvent(flags::Integer) = FileEvent(and(flags, UV_RENAME) != 0, + and(flags, UV_CHANGE) != 0, + and(flags, FD_TIMEDOUT) != 0) fetimeout() = FileEvent(false, false, true) struct FDEvent @@ -50,10 +50,10 @@ const FD_TIMEDOUT = 8 isreadable(f::FDEvent) = f.readable iswritable(f::FDEvent) = f.writable FDEvent() = FDEvent(false, false, false, false) -FDEvent(flags::Integer) = FDEvent(bitand(flags, UV_READABLE) != 0, - bitand(flags, UV_WRITABLE) != 0, - bitand(flags, UV_DISCONNECT) != 0, - bitand(flags, FD_TIMEDOUT) != 0) +FDEvent(flags::Integer) = FDEvent(and(flags, UV_READABLE) != 0, + and(flags, UV_WRITABLE) != 0, + and(flags, UV_DISCONNECT) != 0, + and(flags, FD_TIMEDOUT) != 0) fdtimeout() = FDEvent(false, false, false, true) |(a::FDEvent, b::FDEvent) = FDEvent(a.readable | b.readable, @@ -288,7 +288,7 @@ function uv_pollcb(handle::Ptr{Void}, status::Int32, events::Int32) if status != 0 notify_error(t.notify, UVError("FDWatcher", status)) else - t.events = bitor(t.events, events) + t.events = or(t.events, events) if t.active[1] || t.active[2] if isempty(t.notify.waitq) # if we keep hearing about events when nobody appears to be listening, @@ -322,7 +322,7 @@ function start_watching(t::_FDWatcher) uv_error("start_watching (File Handle)", ccall(:uv_poll_start, Int32, (Ptr{Void}, Int32, Ptr{Void}), t.handle, - bitor(readable ? UV_READABLE : 0, writable ? UV_WRITABLE : 0), + or(readable ? UV_READABLE : 0, writable ? UV_WRITABLE : 0), uv_jl_pollcb::Ptr{Void})) t.active = (readable, writable) end @@ -375,14 +375,14 @@ function wait(fdw::_FDWatcher; readable=true, writable=true) while true if isa(events, FDEvent) events = events::FDEvent - events = bitor(events, FDEvent(fdw.events)) + events = or(events, FDEvent(fdw.events)) haveevent = false if readable && isreadable(events) - fdw.events = bitand(fdw.events, bitnot(UV_READABLE)) + fdw.events = and(fdw.events, not(UV_READABLE)) haveevent = true end if writable && iswritable(events) - fdw.events = bitand(fdw.events, bitnot(UV_WRITABLE)) + fdw.events = and(fdw.events, not(UV_WRITABLE)) haveevent = true end if haveevent diff --git a/stdlib/Mmap/src/Mmap.jl b/stdlib/Mmap/src/Mmap.jl index 722ca877a3d03..21afb1331bc3f 100644 --- a/stdlib/Mmap/src/Mmap.jl +++ b/stdlib/Mmap/src/Mmap.jl @@ -46,18 +46,18 @@ gethandle(io::IO) = fd(io) function settings(s::Int, shared::Bool) flags = shared ? MAP_SHARED : MAP_PRIVATE if s == INVALID_HANDLE_VALUE - flags = bitor(flags, MAP_ANONYMOUS) - prot = bitor(PROT_READ, PROT_WRITE) + flags = or(flags, MAP_ANONYMOUS) + prot = or(PROT_READ, PROT_WRITE) else mode = ccall(:fcntl,Cint,(Cint,Cint),s,F_GETFL) systemerror("fcntl F_GETFL", mode == -1) - mode = bitand(mode, 3) - prot = mode == 0 ? PROT_READ : mode == 1 ? PROT_WRITE : bitor(PROT_READ, PROT_WRITE) - if iszero(bitand(prot, PROT_READ)) + mode = and(mode, 3) + prot = mode == 0 ? PROT_READ : mode == 1 ? PROT_WRITE : or(PROT_READ, PROT_WRITE) + if iszero(and(prot, PROT_READ)) throw(ArgumentError("mmap requires read permissions on the file (open with \"r+\" mode to override)")) end end - return prot, flags, bitand(prot, PROT_WRITE) > 0 + return prot, flags, and(prot, PROT_WRITE) > 0 end # Before mapping, grow the file to sufficient size @@ -196,12 +196,12 @@ function mmap(io::IO, szfile = convert(Csize_t, len + offset) readonly && szfile > filesize(io) && throw(ArgumentError("unable to increase file size to $szfile due to read-only permissions")) handle = create ? ccall(:CreateFileMappingW, stdcall, Ptr{Void}, (Cptrdiff_t, Ptr{Void}, DWORD, DWORD, DWORD, Cwstring), - file_desc, C_NULL, readonly ? PAGE_READONLY : PAGE_READWRITE, szfile >> 32, bitand(szfile, typemax(UInt32)), name) : + file_desc, C_NULL, readonly ? PAGE_READONLY : PAGE_READWRITE, szfile >> 32, and(szfile, typemax(UInt32)), name) : ccall(:OpenFileMappingW, stdcall, Ptr{Void}, (DWORD, Cint, Cwstring), readonly ? FILE_MAP_READ : FILE_MAP_WRITE, true, name) handle == C_NULL && error("could not create file mapping: $(Libc.FormatMessage())") ptr = ccall(:MapViewOfFile, stdcall, Ptr{Void}, (Ptr{Void}, DWORD, DWORD, DWORD, Csize_t), - handle, readonly ? FILE_MAP_READ : FILE_MAP_WRITE, offset_page >> 32, bitand(offset_page, typemax(UInt32)), (offset - offset_page) + len) + handle, readonly ? FILE_MAP_READ : FILE_MAP_WRITE, offset_page >> 32, and(offset_page, typemax(UInt32)), (offset - offset_page) + len) ptr == C_NULL && error("could not create mapping view: $(Libc.FormatMessage())") end # os-test # convert mmapped region to Julia Array at `ptr + (offset - offset_page)` since file was mapped at offset_page @@ -251,9 +251,9 @@ function mmap(io::IOStream, ::Type{<:BitArray}, dims::NTuple{N,Integer}, nc = Base.num_bit_chunks(n) chunks = mmap(io, Vector{UInt64}, (nc,), offset; grow=grow, shared=shared) if !isreadonly(io) - chunks[end] = bitand(chunks[end], Base._msk_end(n)) + chunks[end] = and(chunks[end], Base._msk_end(n)) else - if chunks[end] != bitand(chunks[end], Base._msk_end(n)) + if chunks[end] != and(chunks[end], Base._msk_end(n)) throw(ArgumentError("the given file does not contain a valid BitArray of size $(join(dims, 'x')) (open with \"r+\" mode to override)")) end end diff --git a/stdlib/SharedArrays/src/SharedArrays.jl b/stdlib/SharedArrays/src/SharedArrays.jl index 25abc66fd7901..5273d3edad6fc 100644 --- a/stdlib/SharedArrays/src/SharedArrays.jl +++ b/stdlib/SharedArrays/src/SharedArrays.jl @@ -113,12 +113,12 @@ function SharedArray{T,N}(dims::Dims{N}; init=false, pids=Int[]) where {T,N} shm_seg_name = @sprintf("/jl%06u%s", getpid() % 10^6, randstring(20)) if onlocalhost shmmem_create_pid = myid() - s = shm_mmap_array(T, dims, shm_seg_name, bitor(JL_O_CREAT, JL_O_RDWR)) + s = shm_mmap_array(T, dims, shm_seg_name, or(JL_O_CREAT, JL_O_RDWR)) else # The shared array is created on a remote machine shmmem_create_pid = pids[1] remotecall_fetch(pids[1]) do - shm_mmap_array(T, dims, shm_seg_name, bitor(JL_O_CREAT, JL_O_RDWR)) + shm_mmap_array(T, dims, shm_seg_name, or(JL_O_CREAT, JL_O_RDWR)) nothing end end @@ -648,8 +648,8 @@ end if Sys.iswindows() function _shm_mmap_array(T, dims, shm_seg_name, mode) - readonly = bitand(mode, JL_O_RDWR) != JL_O_RDWR - create = bitand(mode, JL_O_CREAT) == JL_O_CREAT + readonly = and(mode, JL_O_RDWR) != JL_O_RDWR + create = and(mode, JL_O_CREAT) == JL_O_CREAT s = Mmap.Anonymous(shm_seg_name, readonly, create) Mmap.mmap(s, Array{T,length(dims)}, dims, zero(Int64)) end @@ -659,14 +659,14 @@ shm_unlink(shm_seg_name) = 0 else # !windows function _shm_mmap_array(T, dims, shm_seg_name, mode) - fd_mem = shm_open(shm_seg_name, mode, bitor(S_IRUSR, S_IWUSR)) + fd_mem = shm_open(shm_seg_name, mode, or(S_IRUSR, S_IWUSR)) systemerror("shm_open() failed for " * shm_seg_name, fd_mem < 0) s = fdio(fd_mem, true) # On OSX, ftruncate must to used to set size of segment, just lseek does not work. # and only at creation time - if bitand(mode, JL_O_CREAT) == JL_O_CREAT + if and(mode, JL_O_CREAT) == JL_O_CREAT rc = ccall(:jl_ftruncate, Cint, (Cint, Int64), fd_mem, prod(dims)*sizeof(T)) systemerror("ftruncate() failed for shm segment " * shm_seg_name, rc != 0) end diff --git a/test/TestHelpers.jl b/test/TestHelpers.jl index d105b15f6f2e9..be4163f6e18fd 100644 --- a/test/TestHelpers.jl +++ b/test/TestHelpers.jl @@ -27,7 +27,7 @@ function open_fake_pty() O_RDWR = Base.Filesystem.JL_O_RDWR O_NOCTTY = Base.Filesystem.JL_O_NOCTTY - fdm = ccall(:posix_openpt, Cint, (Cint,), bitor(O_RDWR, O_NOCTTY)) + fdm = ccall(:posix_openpt, Cint, (Cint,), or(O_RDWR, O_NOCTTY)) fdm == -1 && error("Failed to open PTY master") rc = ccall(:grantpt, Cint, (Cint,), fdm) rc != 0 && error("grantpt failed") @@ -35,7 +35,7 @@ function open_fake_pty() rc != 0 && error("unlockpt") fds = ccall(:open, Cint, (Ptr{UInt8}, Cint), - ccall(:ptsname, Ptr{UInt8}, (Cint,), fdm), bitor(O_RDWR, O_NOCTTY)) + ccall(:ptsname, Ptr{UInt8}, (Cint,), fdm), or(O_RDWR, O_NOCTTY)) # slave slave = RawFD(fds) diff --git a/test/arrayops.jl b/test/arrayops.jl index 2538147536b72..5b9893bee3dbf 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -2001,7 +2001,7 @@ end @test f15894(ones(Int, 100)) == 100 end -@testset "sign, conj, bitnot" begin +@testset "sign, conj, not" begin local A, B, C A = [-10,0,3] B = [-10.0,0.0,3.0] @@ -2019,8 +2019,8 @@ end @test typeof(conj(B)) == Vector{Float64} @test typeof(conj(C)) == Vector{Complex{Int}} - @test bitnot.(A) == [9,-1,-4] - @test typeof(bitnot.(A)) == Vector{Int} + @test not.(A) == [9,-1,-4] + @test typeof(not.(A)) == Vector{Int} end @testset "issue #16247" begin diff --git a/test/bigint.jl b/test/bigint.jl index c1a694687afee..fb0b62bd2ba38 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -181,9 +181,9 @@ end @test BigInt(-5) << -1 == -3 end @testset "boolean ops" begin - @test bitnot(BigInt(123)) == -124 - @test bitand(BigInt(123), BigInt(234)) == 106 - @test bitor(BigInt(123), BigInt(234)) == 251 + @test not(BigInt(123)) == -124 + @test and(BigInt(123), BigInt(234)) == 106 + @test or(BigInt(123), BigInt(234)) == 251 @test BigInt(123) ⊻ BigInt(234) == 145 @test gcd(BigInt(48), BigInt(180)) == 12 @@ -223,23 +223,23 @@ end @test *(a, b, c, d, f) == parse(BigInt,"-45258849200337190631492857400003938881995610529251881450243326128168934937055005474972396281351684800") @test *(a, b, c, d, f, g) == parse(BigInt,"45258849200337190631492857400003938881995610529251881450243326128168934937055005474972396281351684800") - @test bitxor(a, b) == parse(BigInt,"327299") - @test bitxor(a, b, c) == parse(BigInt,"3426495623485904783798472") - @test bitxor(a, b, c, d) == parse(BigInt,"-3426495623485906178489610") - @test bitxor(a, b, c, d, f) == parse(BigInt,"-2413804710837418037418307081437316711364709261074607933698") - @test bitxor(a, b, c, d, f, g) == parse(BigInt,"2413804710837418037418307081437316711364709261074607933697") + @test xor(a, b) == parse(BigInt,"327299") + @test xor(a, b, c) == parse(BigInt,"3426495623485904783798472") + @test xor(a, b, c, d) == parse(BigInt,"-3426495623485906178489610") + @test xor(a, b, c, d, f) == parse(BigInt,"-2413804710837418037418307081437316711364709261074607933698") + @test xor(a, b, c, d, f, g) == parse(BigInt,"2413804710837418037418307081437316711364709261074607933697") - @test bitand(a, b) == parse(BigInt,"124") - @test bitand(a, b, c) == parse(BigInt,"72") - @test bitand(a, b, c, d) == parse(BigInt,"8") - @test bitand(a, b, c, d, f) == parse(BigInt,"8") - @test bitand(a, b, c, d, f, g) == parse(BigInt,"8") + @test and(a, b) == parse(BigInt,"124") + @test and(a, b, c) == parse(BigInt,"72") + @test and(a, b, c, d) == parse(BigInt,"8") + @test and(a, b, c, d, f) == parse(BigInt,"8") + @test and(a, b, c, d, f, g) == parse(BigInt,"8") - @test bitor(a, b) == parse(BigInt,"327423") - @test bitor(a, b, c) == parse(BigInt,"3426495623485904783802111") - @test bitor(a, b, c, d) == parse(BigInt,"-1396834561") - @test bitor(a, b, c, d, f) == parse(BigInt,"-1358954753") - @test bitor(a, b, c, d, f, g) == parse(BigInt,"-1") + @test or(a, b) == parse(BigInt,"327423") + @test or(a, b, c) == parse(BigInt,"3426495623485904783802111") + @test or(a, b, c, d) == parse(BigInt,"-1396834561") + @test or(a, b, c, d, f) == parse(BigInt,"-1358954753") + @test or(a, b, c, d, f, g) == parse(BigInt,"-1") @test trailing_ones(a) == 8 @test trailing_zeros(b) == 2 @@ -263,7 +263,7 @@ function bigfib(n) r = [BigInt(1), BigInt(1), BigInt(0)] s = [BigInt(1), BigInt(0), BigInt(1)] while true - bitand(n, 1) == 1 && (s = mul(s,r)) + and(n, 1) == 1 && (s = mul(s,r)) (n >>= 1) == 0 && return s[1] r = mul(r,r) end diff --git a/test/bitarray.jl b/test/bitarray.jl index 5b3bbd7c6a5b7..ae1eb357f34fd 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -742,7 +742,7 @@ timesofar("dequeue") @testset "Unary operators" begin b1 = bitrand(n1, n2) - @check_bit_operation broadcast(bitnot, b1) BitMatrix + @check_bit_operation broadcast(not, b1) BitMatrix @check_bit_operation broadcast(!, b1) BitMatrix @check_bit_operation (-)(b1) Matrix{Int} @check_bit_operation broadcast(sign, b1) BitMatrix @@ -751,7 +751,7 @@ timesofar("dequeue") @check_bit_operation conj(b1) BitMatrix b0 = falses(0) - @check_bit_operation broadcast(bitnot, b0) BitVector + @check_bit_operation broadcast(not, b0) BitVector @check_bit_operation broadcast(!, b0) BitVector @check_bit_operation (-)(b0) Vector{Int} @check_bit_operation broadcast(sign, b0) BitVector @@ -759,7 +759,7 @@ timesofar("dequeue") @testset "flipbits!" begin b1 = bitrand(n1, n2) i1 = Array(b1) - @test flipbits!(b1) == bitnot.(i1) + @test flipbits!(b1) == not.(i1) @test bitcheck(b1) end end @@ -1095,13 +1095,13 @@ timesofar("datamove") b1 = trues(v1) for i = 0:(v1-1) @test findfirst(b1 >> i) == i+1 - @test Base.findfirstnot(bitnot.(b1 >> i)) == i+1 + @test Base.findfirstnot(not.(b1 >> i)) == i+1 end for i = 3:(v1-1), j = 2:i submask = b1 << (v1-j+1) @test findnext((b1 >> i) .| submask, j) == i+1 - @test findnextnot((bitnot.(b1 >> i)) .⊻ submask, j) == i+1 + @test findnextnot((not.(b1 >> i)) .⊻ submask, j) == i+1 end b1 = bitrand(n1, n2) @@ -1140,7 +1140,7 @@ timesofar("nnz&find") for c = [falses, trues] b1 = c(n) b1[elts] = .!b1[elts] - b2 = bitnot.(b1) + b2 = not.(b1) i1 = Array(b1) for i = 1:n @test findprev(b1, i) == findprev(i1, i) == findprevnot(b2, i) == findprev(!, b2, i) @@ -1151,7 +1151,7 @@ timesofar("nnz&find") b1 = falses(1000) b1[77] = true b1[777] = true - b2 = bitnot.(b1) + b2 = not.(b1) @test_throws BoundsError findprev(b1, 1001) @test_throws BoundsError findprevnot(b2, 1001) @test_throws BoundsError findprev(!, b2, 1001) @@ -1207,13 +1207,13 @@ timesofar("nnz&find") @test findprev(t, l) == findprevnot(f, l) == l b1 = falses(l) b1[end] = true - b2 = bitnot.(b1) + b2 = not.(b1) @test findprev(b1, l) == findprevnot(b2, l) == l @test findprevnot(b1, l) == findprev(b2, l) == l-1 if l > 1 b1 = falses(l) b1[end-1] = true - b2 = bitnot.(b1) + b2 = not.(b1) @test findprev(b1, l) == findprevnot(b2, l) == l-1 @test findprevnot(b1, l) == findprev(b2, l) == l end @@ -1246,7 +1246,7 @@ timesofar("reductions") for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401] b1 = bitrand(l) b2 = bitrand(l) - @test map(bitnot, b1) == map(x->bitnot(x), b1) == broadcast(bitnot, b1) + @test map(not, b1) == map(x->not(x), b1) == broadcast(not, b1) @test map(identity, b1) == map(x->x, b1) == b1 @test map(&, b1, b2) == map((x,y)->x&y, b1, b2) == broadcast(&, b1, b2) @@ -1268,8 +1268,8 @@ timesofar("reductions") @testset "map! for length $l" begin b = BitArray(l) - @test map!(bitnot, b, b1) == map!(x->bitnot(x), b, b1) == broadcast(bitnot, b1) == b - @test map!(!, b, b1) == map!(x->!x, b, b1) == broadcast(bitnot, b1) == b + @test map!(not, b, b1) == map!(x->not(x), b, b1) == broadcast(not, b1) == b + @test map!(!, b, b1) == map!(x->!x, b, b1) == broadcast(not, b1) == b @test map!(identity, b, b1) == map!(x->x, b, b1) == b1 == b @test map!(zero, b, b1) == map!(x->false, b, b1) == falses(l) == b @test map!(one, b, b1) == map!(x->true, b, b1) == trues(l) == b @@ -1298,7 +1298,7 @@ timesofar("reductions") B17970 = map(x -> x ? 1 : 2, A17970) @test B17970::Array{Int,1} == [2,1,2] C17970 = map(x -> x ? false : true, A17970) - @test C17970::BitArray{1} == map(bitnot, A17970) + @test C17970::BitArray{1} == map(not, A17970) end end diff --git a/test/core.jl b/test/core.jl index c73e502d3aa47..441af610b2ec7 100644 --- a/test/core.jl +++ b/test/core.jl @@ -567,7 +567,7 @@ let end # tricky space sensitive syntax cases -@test [-1 bitnot(1)] == [(-1) (bitnot(1))] +@test [-1 not(1)] == [(-1) (not(1))] # undefinedness mutable struct UndefField @@ -1748,7 +1748,7 @@ f5254(a, b) = 1 let i = 0, x = 65 @test (i, i+=1, i+=1) === (0, 1, 2) @test i == 2 - @test [x, x = bitor(x, 0x20)] == [65, 97] + @test [x, x = or(x, 0x20)] == [65, 97] end # issue #5312 diff --git a/test/fastmath.jl b/test/fastmath.jl index 6aaf32921866a..878b6f50c6eca 100644 --- a/test/fastmath.jl +++ b/test/fastmath.jl @@ -198,7 +198,7 @@ end # test fallthrough for unsupported ops local c = 0 - @test @fastmath(c = bitor(c, 1)) == 1 + @test @fastmath(c = or(c, 1)) == 1 end @testset "issue #23218" begin diff --git a/test/file.jl b/test/file.jl index 9207cb4538d90..20a6ccdf93fb4 100644 --- a/test/file.jl +++ b/test/file.jl @@ -60,23 +60,23 @@ end @test isfile(file) @test !islink(file) -@test bitand(filemode(file), 0o444) > 0 # readable -@test bitand(filemode(file), 0o222) > 0 # writable -chmod(file, bitand(filemode(file), 0o7555)) -@test bitand(filemode(file), 0o222) == 0 -chmod(file, bitor(filemode(file), 0o222)) -@test bitand(filemode(file), 0o111) == 0 +@test and(filemode(file), 0o444) > 0 # readable +@test and(filemode(file), 0o222) > 0 # writable +chmod(file, and(filemode(file), 0o7555)) +@test and(filemode(file), 0o222) == 0 +chmod(file, or(filemode(file), 0o222)) +@test and(filemode(file), 0o111) == 0 @test filesize(file) == 0 if Sys.iswindows() permissions = 0o444 - @test bitand(filemode(dir), 0o777) != permissions - @test bitand(filemode(subdir), 0o777) != permissions - @test bitand(filemode(file), 0o777) != permissions + @test and(filemode(dir), 0o777) != permissions + @test and(filemode(subdir), 0o777) != permissions + @test and(filemode(file), 0o777) != permissions chmod(dir, permissions, recursive=true) - @test bitand(filemode(dir), 0o777) == permissions - @test bitand(filemode(subdir), 0o777) == permissions - @test bitand(filemode(file), 0o777) == permissions + @test and(filemode(dir), 0o777) == permissions + @test and(filemode(subdir), 0o777) == permissions + @test and(filemode(file), 0o777) == permissions chmod(dir, 0o666, recursive=true) # Reset permissions in case someone wants to use these later else mktempdir() do tmpdir @@ -86,18 +86,18 @@ else linkfile=joinpath(dir, "tempfile.txt") symlink(tmpfile, linkfile) permissions=0o776 - @test bitand(filemode(dir), 0o777) != permissions - @test bitand(filemode(subdir), 0o777) != permissions - @test bitand(filemode(file), 0o777) != permissions - @test bitand(filemode(linkfile), 0o777) != permissions - @test bitand(filemode(tmpfile), 0o777) != permissions + @test and(filemode(dir), 0o777) != permissions + @test and(filemode(subdir), 0o777) != permissions + @test and(filemode(file), 0o777) != permissions + @test and(filemode(linkfile), 0o777) != permissions + @test and(filemode(tmpfile), 0o777) != permissions chmod(dir, permissions, recursive=true) - @test bitand(filemode(dir), 0o777) == permissions - @test bitand(filemode(subdir), 0o777) == permissions - @test bitand(filemode(file), 0o777) == permissions - @test bitand(lstat(link).mode, 0o777) != permissions # Symbolic links are not modified. - @test bitand(filemode(linkfile), 0o777) != permissions # Symbolic links are not followed. - @test bitand(filemode(tmpfile), 0o777) != permissions + @test and(filemode(dir), 0o777) == permissions + @test and(filemode(subdir), 0o777) == permissions + @test and(filemode(file), 0o777) == permissions + @test and(lstat(link).mode, 0o777) != permissions # Symbolic links are not modified. + @test and(filemode(linkfile), 0o777) != permissions # Symbolic links are not followed. + @test and(filemode(tmpfile), 0o777) != permissions rm(linkfile) end end diff --git a/test/int.jl b/test/int.jl index 710d84218c246..c436168ccfeed 100644 --- a/test/int.jl +++ b/test/int.jl @@ -102,7 +102,7 @@ end @test mod(123, UInt8) == 0x7b primitive type MyBitsType <: Integer 8 end -@test_throws MethodError bitnot(reinterpret(MyBitsType, 0x7b)) +@test_throws MethodError not(reinterpret(MyBitsType, 0x7b)) UItypes = Base.BitUnsigned_types SItypes = Base.BitSigned_types @@ -227,8 +227,8 @@ end @test 0x00007ffea27edaa0 + (-40) === (-40) + 0x00007ffea27edaa0 === 0x00007ffea27eda78 @test UInt64(1) * Int64(-1) === typemax(UInt64) @test UInt(1) - (-1) == 2 -@test bitand(UInt64(15), -4) === UInt64(12) -@test bitor(UInt64(15), -4) === typemax(UInt64) +@test and(UInt64(15), -4) === UInt64(12) +@test or(UInt64(15), -4) === typemax(UInt64) @test UInt64(15) ⊻ -4 === 0xfffffffffffffff3 diff --git a/test/linalg/generic.jl b/test/linalg/generic.jl index c79b63ed7e235..db443e159a44d 100644 --- a/test/linalg/generic.jl +++ b/test/linalg/generic.jl @@ -433,4 +433,4 @@ end @test !isdiag(lbidiag) @test isdiag(adiag) end -end \ No newline at end of file +end diff --git a/test/nullable.jl b/test/nullable.jl index 43c9432ddfeb4..929b6af35e6e8 100644 --- a/test/nullable.jl +++ b/test/nullable.jl @@ -511,7 +511,7 @@ end for op in (+, *, -) for b1 in (false, true) for b2 in (false, true) - @test Nullable{Int}(op(1, 2), bitand(b1, b2)) === + @test Nullable{Int}(op(1, 2), and(b1, b2)) === @inferred(broadcast(op, Nullable{Int}(1, b1), Nullable{Int}(2, b2))) end diff --git a/test/numbers.jl b/test/numbers.jl index d004b95de997e..990098fd9df69 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -19,8 +19,8 @@ const ≣ = isequal # convenient for comparing NaNs @test true != false @test false != true - @test bitnot(true) == false - @test bitnot(false) == true + @test not(true) == false + @test not(false) == true @test false & false == false @test true & false == false @@ -2059,9 +2059,9 @@ end @test signif(Float16(1.1), 70) === Float16(1.1) end @testset "issue #1308" begin - @test hex(bitnot(UInt128(0))) == "f"^32 - @test(bitnot(0)%UInt128 == bitnot(UInt128(0)) - @test Int128(bitnot(0)) == bitnot(Int128(0)) + @test hex(not(UInt128(0))) == "f"^32 + @test(not(0)%UInt128 == not(UInt128(0)) + @test Int128(not(0)) == not(Int128(0)) end @testset "issue 1552" begin @test isa(rationalize(Int8, float(pi)), Rational{Int8}) @@ -2289,7 +2289,7 @@ end @testset "ispow2" begin @test ispow2(64) @test !ispow2(42) - @test !ispow2(bitnot(typemax(Int))) + @test !ispow2(not(typemax(Int))) end @testset "nextpow/prevpow" begin @test nextpow(2,1) == 1 @@ -2353,8 +2353,8 @@ end for T = (UInt8,Int8,UInt16,Int16,UInt32,Int32,UInt64,Int64,UInt128,Int128) for n = 1:2:1000 - @test bitand(n*(n^typemax(T)), typemax(T)) == 1 - n = bitor(rand(T), one(T)) + @test and(n*(n^typemax(T)), typemax(T)) == 1 + n = or(rand(T), one(T)) @test n*(n^typemax(T)) == 1 end end @@ -2874,12 +2874,12 @@ end let types = (Base.BitInteger_types..., BigInt, Bool) for S in types - T = @inferred Base.promote_op(bitnot, S) - t = @inferred bitnot(one(S)) + T = @inferred Base.promote_op(not, S) + t = @inferred not(one(S)) @test T === typeof(t) for R in types - for op in (bitand, bitor, <<, >>, (>>>), %, ÷) + for op in (and, or, <<, >>, (>>>), %, ÷) T = @inferred Base.promote_op(op, S, R) t = @inferred op(one(S), one(R)) @test T === typeof(t) @@ -3051,7 +3051,7 @@ end sig = [11, 24, 53] for i = 1:length(F), j = 1:length(F) for _ = 1:100 - nan = reinterpret(F[i], bitor(rand(U[i]), reinterpret(U[i], nans[i]))) + nan = reinterpret(F[i], or(rand(U[i]), reinterpret(U[i], nans[i]))) z = sig[i] - sig[j] nan′ = i <= j ? nan : reinterpret(F[i], reinterpret(U[i], nan) >> z << z) @test convert(F[i], convert(F[j], nan)) === nan′ diff --git a/test/operators.jl b/test/operators.jl index 80d2d7aade47d..4863a52fed6a7 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -48,8 +48,8 @@ p = 1=>:foo @test endof(p) == 2 @test p[endof(p)] == p[end] == p[2] == :foo -@test bitor(2) == 2 -@test bitxor(2) == 2 +@test or(2) == 2 +@test xor(2) == 2 @test (⊻)(2) == 2 @test_throws ArgumentError Base.scalarmin(['a','b'],['c','d']) diff --git a/test/perf/kernel/ziggurat.jl b/test/perf/kernel/ziggurat.jl index 706bfcb0e8bf3..87944286c611b 100644 --- a/test/perf/kernel/ziggurat.jl +++ b/test/perf/kernel/ziggurat.jl @@ -115,8 +115,8 @@ function randn_zig() while (true) U = rand(UInt32) - i = 1 + bitand(U, 0x0000007F) # 7 bit to choose the step - sign = bitand(U, 0x00000080) # 1 bit for the sign + i = 1 + and(U, 0x0000007F) # 7 bit to choose the step + sign = and(U, 0x00000080) # 1 bit for the sign j = U>>8 # 24 bit for the x-value x = j*wtab[i] diff --git a/test/perf/shootout/mandelbrot.jl b/test/perf/shootout/mandelbrot.jl index 6b934a5d8f233..4b5e85b466d2f 100644 --- a/test/perf/shootout/mandelbrot.jl +++ b/test/perf/shootout/mandelbrot.jl @@ -25,7 +25,7 @@ function draw_mandel(M::Array{UInt8, 2}, n::Int) c = complex(2x/n - 1.5, ci) if ismandel(c) k = div(x, 8) + 1, y + 1 - M[k] = bitor(M[k], 1 << UInt8(7 - x%8)) + M[k] = or(M[k], 1 << UInt8(7 - x%8)) end end end diff --git a/test/perf/shootout/meteor_contest.jl b/test/perf/shootout/meteor_contest.jl index f1b1ffaeb2160..4973ca0777e89 100644 --- a/test/perf/shootout/meteor_contest.jl +++ b/test/perf/shootout/meteor_contest.jl @@ -47,13 +47,13 @@ const masks = zeros(UInt64, 10) const masksAtCell = Array{Any}(width*height, height) valid(x, y) = (0 <= x < width) && (0 <= y < height) -legal(mask::UInt64, board::UInt64) = bitand(mask, board) == 0 +legal(mask::UInt64, board::UInt64) = and(mask, board) == 0 zerocount(mask::UInt64) = 50 - count_ones(mask) function findFreeCell(board::UInt64) for y in 0:height-1 for x in 0:width-1 - if bitand(board, UInt64(1) << (x + width*y)) == 0 + if and(board, UInt64(1) << (x + width*y)) == 0 return x, y end end @@ -66,13 +66,13 @@ function floodFill(board::UInt64, fixme) return board end - if bitand(board, UInt64(1) << (x + width*y)) != 0 + if and(board, UInt64(1) << (x + width*y)) != 0 return board end - board = bitor(board, UInt64(1) << (x + width*y)) + board = or(board, UInt64(1) << (x + width*y)) for f in values(move) - board = bitor(board, floodFill(board, f(x, y))) + board = or(board, floodFill(board, f(x, y))) end return board @@ -105,7 +105,7 @@ function getBitmask(x, y, piece) for cell_ in piece x, y = move[cell_](x,y) if valid(x, y) - mask = bitor(mask, UInt64(1) << (x + width*y)) + mask = or(mask, UInt64(1) << (x + width*y)) else return false, UInt64(0) end @@ -148,7 +148,7 @@ function generateBitmasks() j = length(masks) - 1 while j >= 0 - if bitand(masks[j + 1], cellMask) == cellMask + if and(masks[j + 1], cellMask) == cellMask push!(masksAtCell[cellCounter + 1, color + 1], masks[j + 1]) j -= 1 else @@ -173,7 +173,7 @@ function solveCell(cell_, board::UInt64, n) return end - if bitand(board, UInt64(1) << cell_) != 0 + if and(board, UInt64(1) << cell_) != 0 # Cell full solveCell(cell_ - 1, UInt64(board), n) return @@ -189,7 +189,7 @@ function solveCell(cell_, board::UInt64, n) for mask in masksAtCell[cell_ + 1, color + 1] if legal(mask, board) masks[color + 1] = mask - solveCell(cell_ - 1, UInt64(bitor(board, mask)), n) + solveCell(cell_ - 1, UInt64(or(board, mask)), n) masks[color + 1] = 0 end end @@ -208,7 +208,7 @@ function stringOfMasks(masks) for y in 0:height-1 for x in 0:width-1 for color in 0:9 - if bitand(masks[color+1], mask) != 0 + if and(masks[color+1], mask) != 0 s = string(s, color) break elseif color == 9 diff --git a/test/random.jl b/test/random.jl index 57343d3ebddf3..1f7a8218a0b47 100644 --- a/test/random.jl +++ b/test/random.jl @@ -315,7 +315,7 @@ end # make sure reading 128-bit ints from RandomDevice works let a = [rand(RandomDevice(), UInt128) for i=1:10] - @test reduce(bitor, a)>>>64 != 0 + @test reduce(or, a)>>>64 != 0 end # test all rand APIs diff --git a/test/ranges.jl b/test/ranges.jl index 811eaeeb880c3..3c91c8a8be092 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -1031,7 +1031,7 @@ end @test size(similar(r, size(r))) == size(similar(r, length(r))) end end -@testset "sign, conj, bitnot (Issue #16067)" begin +@testset "sign, conj, not (Issue #16067)" begin A = -1:1 B = -1.0:1.0 @test sign.(A) == [-1,0,1] @@ -1042,8 +1042,8 @@ end @test conj(A) === A @test conj(B) === B - @test bitnot.(A) == [0,-1,-2] - @test typeof(bitnot.(A)) == Vector{Int} + @test not.(A) == [0,-1,-2] + @test typeof(not.(A)) == Vector{Int} end @testset "conversion to Array" begin diff --git a/test/read.jl b/test/read.jl index d57fa5f558cff..31b5c7c38e47b 100644 --- a/test/read.jl +++ b/test/read.jl @@ -443,7 +443,7 @@ close(f1) close(f2) rm(f) -io = Base.Filesystem.open(f, bitor(Base.Filesystem.JL_O_WRONLY, Base.Filesystem.JL_O_CREAT, Base.Filesystem.JL_O_EXCL), 0o000) +io = Base.Filesystem.open(f, or(Base.Filesystem.JL_O_WRONLY, Base.Filesystem.JL_O_CREAT, Base.Filesystem.JL_O_EXCL), 0o000) @test write(io, "abc") == 3 close(io) if !Sys.iswindows() && get(ENV, "USER", "") != "root" && get(ENV, "HOME", "") != "/root" diff --git a/test/reduce.jl b/test/reduce.jl index 4c6128ea6df35..96a4b0c82cef2 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -48,8 +48,8 @@ @test mapreduce(abs2, +, Float64[]) === 0.0 @test mapreduce(abs2, Base.scalarmax, Float64[]) === 0.0 @test mapreduce(abs, max, Float64[]) === 0.0 -@test_throws ArgumentError mapreduce(abs2, bitand, Float64[]) -@test_throws ArgumentError mapreduce(abs2, bitor, Float64[]) +@test_throws ArgumentError mapreduce(abs2, and, Float64[]) +@test_throws ArgumentError mapreduce(abs2, or, Float64[]) # mapreduce() type stability @test typeof(mapreduce(*, +, Int8[10])) === @@ -401,6 +401,6 @@ test18695(r) = sum( t^2 for t in r ) # issue #21107 @test foldr(-,2:2) == 2 -# test neutral element not picked incorrectly for bitand, bitor -@test @inferred(foldl(bitand, Int[1])) === 1 -@test_throws ArgumentError foldl(bitand, Int[]) +# test neutral element not picked incorrectly for and, or +@test @inferred(foldl(and, Int[1])) === 1 +@test_throws ArgumentError foldl(and, Int[]) diff --git a/test/reducedim.jl b/test/reducedim.jl index 110fdf05dbc36..69f04b3b38c11 100644 --- a/test/reducedim.jl +++ b/test/reducedim.jl @@ -109,7 +109,7 @@ end @test sum(Union{Float32, Float64}[1.0], 1) == [1.0] @test prod(Union{Float32, Float64}[1.0], 1) == [1.0] -@test reducedim((a,b) -> bitor(a, b), [true false; false false], 1, false) == [true false] +@test reducedim((a,b) -> or(a, b), [true false; false false], 1, false) == [true false] let R = reducedim((a,b) -> a+b, [1 2; 3 4], 2, 0.0) @test eltype(R) == Float64 @test R ≈ [3,7] diff --git a/test/serialize.jl b/test/serialize.jl index 005ef5798397c..71c1ef93a1ecd 100644 --- a/test/serialize.jl +++ b/test/serialize.jl @@ -507,8 +507,8 @@ let io = IOBuffer() @test b[1] == Serializer.HEADER_TAG @test b[2:3] == b"JL" @test b[4] == Serializer.ser_version - @test bitand(b[5], 0x3) == (ENDIAN_BOM == 0x01020304) - @test bitand(b[5], 0xc) >> 2 == (sizeof(Int) == 8) - @test bitand(b[5], 0xf0) == 0 + @test and(b[5], 0x3) == (ENDIAN_BOM == 0x01020304) + @test and(b[5], 0xc) >> 2 == (sizeof(Int) == 8) + @test and(b[5], 0xf0) == 0 @test all(b[6:8] .== 0) end diff --git a/test/show.jl b/test/show.jl index ee1a596146ce8..5c32155e83b24 100644 --- a/test/show.jl +++ b/test/show.jl @@ -66,7 +66,7 @@ end @test_repr "2e" @test_repr "!x" @test_repr "f(1, 2, 3)" -@test_repr "x = bitnot(y)" +@test_repr "x = not(y)" @test_repr ":(:x, :y)" @test_repr ":(:(:(x)))" @@ -185,17 +185,17 @@ end""" # line meta if delta_kd == 0 # line meta - msk_d0 = bitor(bitnot(u << ld0), u << ld1 << 1) + msk_d0 = or(not(u << ld0), u << ld1 << 1) else # line meta - msk_d0 = bitnot(u << ld0) + msk_d0 = not(u << ld0) # line meta msk_d1 = (u << ld1 << 1) end # line meta if delta_ks == 0 # line meta - msk_s0 = bitand(u << ls0, bitnot(u << ls1 << 1)) + msk_s0 = and(u << ls0, not(u << ls1 << 1)) else # line meta msk_s0 = (u << ls0) @@ -203,7 +203,7 @@ end""" # line meta chunk_s0 = glue_src_bitchunks(src, ks0, ks1, msk_s0, ls0) # line meta - dest[kd0] = bitor(bitand(dest[kd0], msk_d0), bitand(chunk_s0 << ld0, bitnot(msk_d0))) + dest[kd0] = or(and(dest[kd0], msk_d0), and(chunk_s0 << ld0, not(msk_d0))) # line meta if delta_kd == 0 # line meta @@ -214,7 +214,7 @@ end""" # line meta chunk_s1 = glue_src_bitchunks(src, ks0 + i, ks1, msk_s0, ls0) # line meta - chunk_s = bitor(chunk_s0 >>> (63 - ld0) >>> 1, chunk_s1 << ld0) + chunk_s = or(chunk_s0 >>> (63 - ld0) >>> 1, chunk_s1 << ld0) # line meta dest[kd0 + i] = chunk_s # line meta @@ -229,9 +229,9 @@ end""" chunk_s1 = UInt64(0) end # line meta - chunk_s = bitor(chunk_s0 >>> (63 - ld0) >>> 1, chunk_s1 << ld0) + chunk_s = or(chunk_s0 >>> (63 - ld0) >>> 1, chunk_s1 << ld0) # line meta - dest[kd1] = bitor(bitand(dest[kd1], msk_d1), bitand(chunk_s, bitnot(msk_d1))) + dest[kd1] = or(and(dest[kd1], msk_d1), and(chunk_s, not(msk_d1))) # line meta return end""" diff --git a/test/sorting.jl b/test/sorting.jl index d3c5f762a06b0..7fc468b09fa59 100644 --- a/test/sorting.jl +++ b/test/sorting.jl @@ -216,7 +216,7 @@ end end ## more advanced sorting tests ## -randnans(n) = reinterpret(Float64, [bitor(rand(UInt64), 0x7ff8000000000000) for i=1:n]) +randnans(n) = reinterpret(Float64, [or(rand(UInt64), 0x7ff8000000000000) for i=1:n]) function randn_with_nans(n,p) v = randn(n) diff --git a/test/sparse/sparse.jl b/test/sparse/sparse.jl index e9b48016f0cc0..496335c763ae8 100644 --- a/test/sparse/sparse.jl +++ b/test/sparse/sparse.jl @@ -65,9 +65,9 @@ do33 = ones(3) @test_throws DimensionMismatch map(min, sqrfloatmat, colfloatmat) @test_throws DimensionMismatch map(max, sqrfloatmat, colfloatmat) sqrboolmat, colboolmat = sprand(Bool, 4, 4, 0.5), sprand(Bool, 4, 1, 0.5) - @test_throws DimensionMismatch map(bitand, sqrboolmat, colboolmat) - @test_throws DimensionMismatch map(bitor, sqrboolmat, colboolmat) - @test_throws DimensionMismatch map(bitxor, sqrboolmat, colboolmat) + @test_throws DimensionMismatch map(and, sqrboolmat, colboolmat) + @test_throws DimensionMismatch map(or, sqrboolmat, colboolmat) + @test_throws DimensionMismatch map(xor, sqrboolmat, colboolmat) end end @@ -1705,11 +1705,11 @@ end A13024 = sparse([1,2,3,4,5], [1,2,3,4,5], fill(true,5)) B13024 = sparse([1,2,4,5], [1,2,3,5], fill(true,4)) - @test broadcast(bitand, A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3)) - @test typeof(broadcast(bitand, A13024, B13024)) == SparseMatrixCSC{Bool,Int} + @test broadcast(and, A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3)) + @test typeof(broadcast(and, A13024, B13024)) == SparseMatrixCSC{Bool,Int} - @test broadcast(bitor, A13024, B13024) == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6)) - @test typeof(broadcast(bitor, A13024, B13024)) == SparseMatrixCSC{Bool,Int} + @test broadcast(or, A13024, B13024) == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6)) + @test typeof(broadcast(or, A13024, B13024)) == SparseMatrixCSC{Bool,Int} @test broadcast(⊻, A13024, B13024) == sparse([3,4,4], [3,3,4], fill(true,3), 5, 5) @test typeof(broadcast(⊻, A13024, B13024)) == SparseMatrixCSC{Bool,Int} @@ -1723,7 +1723,7 @@ end for op in (+, -) @test op(A13024, B13024) == op(Array(A13024), Array(B13024)) end - for op in (max, min, bitand, bitor, bitxor) + for op in (max, min, and, or, xor) @test op.(A13024, B13024) == op.(Array(A13024), Array(B13024)) end end