Skip to content

Commit

Permalink
<<, >>, >>>: use intrinsics for more mixed-type shift operations.
Browse files Browse the repository at this point in the history
LLVM isn't able to eliminate the additional checks done by fallbacks
for the mixed-type bitshift operations, so this change just calls
the intrinsics directly, which minimizes the amount of work done.
The fallback now avoids conversion checking as well and just returns
zero if the second argument is too large to fit in an Int.
  • Loading branch information
StefanKarpinski committed Jun 9, 2015
1 parent 444a058 commit c6882a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ for T in IntTypes
else
@eval >>(x::$T, y::Int) = box($T,ashr_int(unbox($T,x),unbox(Int,y)))
end
for S in IntTypes
(S === Int128 || S === UInt128) && continue
@eval begin
<<(x::$T, y::$S) = box($T, shl_int(unbox($T,x),unbox($S,y)))
>>>(x::$T, y::$S) = box($T,lshr_int(unbox($T,x),unbox($S,y)))
end
if issubtype(T,Unsigned)
@eval >>(x::$T, y::$S) = box($T,lshr_int(unbox($T,x),unbox($S,y)))
else
@eval >>(x::$T, y::$S) = box($T,ashr_int(unbox($T,x),unbox($S,y)))
end
end
end

bswap(x::Int8) = x
Expand Down
6 changes: 3 additions & 3 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ const .≠ = .!=
<<(x,y::Int) = no_op_err("<<", typeof(x))
>>(x,y::Int) = no_op_err(">>", typeof(x))
>>>(x,y::Int) = no_op_err(">>>", typeof(x))
<<(x,y::Integer) = x << convert(Int,y)
>>(x,y::Integer) = x >> convert(Int,y)
>>>(x,y::Integer) = x >>> convert(Int,y)
<<(x,y::Integer) = typemax(Int) < y ? zero(x) : x << (y % Int)
>>(x,y::Integer) = typemax(Int) < y ? zero(x) : x >> (y % Int)
>>>(x,y::Integer) = typemax(Int) < y ? zero(x) : x >>> (y % Int)

# fallback div, fld, and cld implementations
# NOTE: C89 fmod() and x87 FPREM implicitly provide truncating float division,
Expand Down

0 comments on commit c6882a9

Please sign in to comment.