Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<<, >>, >>>: use intrinsics for more mixed-type shift operations. #11629

Merged
merged 1 commit into from
Jun 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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