Skip to content

Commit

Permalink
Merge pull request JuliaLang#11629 from JuliaLang/sk/shifts
Browse files Browse the repository at this point in the history
<<, >>, >>>: use intrinsics for more mixed-type shift operations.
  • Loading branch information
StefanKarpinski committed Jun 9, 2015
2 parents e8302b2 + c6882a9 commit bee46ee
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 bee46ee

Please sign in to comment.