Skip to content

Commit

Permalink
remove size-specific trunc, sext, and zext intrinsics
Browse files Browse the repository at this point in the history
DRY up more of the conversion definitions
this requires 'make clean'
  • Loading branch information
JeffBezanson committed Feb 16, 2013
1 parent b198961 commit 24268cc
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 264 deletions.
7 changes: 3 additions & 4 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,9 @@ export
#fptrunc32, fpuiround32, fpuiround64, le_float, lefsi64, lefui64, lesif64,
#leuif64, lshr_int, lt_float, ltfsi64, ltfui64, ltsif64, ltuif64, mul_float,
#mul_int, ne_float, ne_int, neg_float, neg_int, not_int, or_int, rem_float,
#sdiv_int, sext16, sext32, sext64, shl_int, sitofp32, sitofp64, sle_int,
#slt_int, smod_int, srem_int, sub_float, sub_int, trunc16, trunc32,
#trunc64, trunc8, trunc_int, udiv_int, uitofp32, uitofp64, ule_int, ult_int,
#unbox, urem_int, xor_int, zext16, zext32, zext64, sext_int, zext_int
#sdiv_int, shl_int, sitofp32, sitofp64, sle_int, slt_int, smod_int,
#srem_int, sub_float, sub_int, trunc_int, udiv_int, uitofp32, uitofp64,
#ule_int, ult_int, unbox, urem_int, xor_int, sext_int, zext_int


type Nothing; end
Expand Down
16 changes: 0 additions & 16 deletions base/char.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
## char conversions ##

convert(::Type{Char}, x::Bool ) = box(Char,sext32(unbox(Bool,x)))
convert(::Type{Char}, x::Int8 ) = box(Char,sext32(unbox(Int8,x)))
convert(::Type{Char}, x::Uint8 ) = box(Char,zext32(unbox(Uint8,x)))
convert(::Type{Char}, x::Int16 ) = box(Char,sext32(unbox(Int16,x)))
convert(::Type{Char}, x::Uint16 ) = box(Char,zext32(unbox(Uint16,x)))
convert(::Type{Char}, x::Int32 ) = box(Char,unbox(Int32,x))
convert(::Type{Char}, x::Uint32 ) = box(Char,unbox(Uint32,x))
convert(::Type{Char}, x::Int64 ) = box(Char,trunc32(unbox(Int64,x)))
convert(::Type{Char}, x::Uint64 ) = box(Char,trunc32(unbox(Uint64,x)))
convert(::Type{Char}, x::Int128 ) = box(Char,trunc32(unbox(Int128,x)))
convert(::Type{Char}, x::Uint128) = box(Char,trunc32(unbox(Uint128,x)))
convert(::Type{Char}, x::Float32) = char(convert(Int, x))
convert(::Type{Char}, x::Float64) = char(convert(Int, x))

char(x) = convert(Char, x)
char(x::FloatingPoint) = char(iround(x))

Expand Down
8 changes: 4 additions & 4 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ end
complex128(r::Real, i::Real) = complex128(float64(r),float64(i))
complex128(z) = complex128(real(z), imag(z))

real(c::Complex128) = box(Float64,trunc64(c))
imag(c::Complex128) = box(Float64,trunc64(ashr_int(c, 64)))
real(c::Complex128) = box(Float64,trunc_int(Int64,c))
imag(c::Complex128) = box(Float64,trunc_int(Int64,ashr_int(c, 64)))

convert(::Type{Complex128}, x::Real) = complex128(x,0)
convert(::Type{Complex128}, z::Complex128) = z
Expand Down Expand Up @@ -90,8 +90,8 @@ end
complex64(r::Real, i::Real) = complex64(float32(r),float32(i))
complex64(z) = complex64(real(z), imag(z))

real(c::Complex64) = box(Float32,trunc32(c))
imag(c::Complex64) = box(Float32,trunc32(ashr_int(c, 32)))
real(c::Complex64) = box(Float32,trunc_int(Int32,c))
imag(c::Complex64) = box(Float32,trunc_int(Int32,ashr_int(c, 32)))

convert(::Type{Complex64}, x::Real) = complex64(x,0)
convert(::Type{Complex64}, z::Complex64) = z
Expand Down
2 changes: 1 addition & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ end

bitmix(a::Union(Int32,Uint32), b::Union(Int32,Uint32)) =
ccall(:int64to32hash, Uint32, (Uint64,),
or_int(shl_int(zext64(unbox(Uint32,a)), 32), zext64(unbox(Uint32,b))))
or_int(shl_int(zext_int(Uint64,unbox(Uint32,a)), 32), zext_int(Uint64,unbox(Uint32,b))))

bitmix(a::Union(Int64,Uint64), b::Union(Int64, Uint64)) =
ccall(:int64hash, Uint64, (Uint64,),
Expand Down
20 changes: 10 additions & 10 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ else
itrunc(x::Float64) = int32(box(Int64,fptosi64(unbox(Float64,x))))
end

iround(::Type{Int8}, x::Float32) = box(Int8,trunc8(fpsiround32(unbox(Float32,x))))
iround(::Type{Int8}, x::Float64) = box(Int8,trunc8(fpsiround64(unbox(Float64,x))))
iround(::Type{Uint8}, x::Float32) = box(Uint8,trunc8(fpuiround32(unbox(Float32,x))))
iround(::Type{Uint8}, x::Float64) = box(Uint8,trunc8(fpuiround64(unbox(Float64,x))))
iround(::Type{Int16}, x::Float32) = box(Int16,trunc16(fpsiround32(unbox(Float32,x))))
iround(::Type{Int16}, x::Float64) = box(Int16,trunc16(fpsiround64(unbox(Float64,x))))
iround(::Type{Uint16}, x::Float32) = box(Uint16,trunc16(fpuiround32(unbox(Float32,x))))
iround(::Type{Uint16}, x::Float64) = box(Uint16,trunc16(fpuiround64(unbox(Float64,x))))
for to in (Int8, Uint8, Int16, Uint16)
@eval begin
iround(::Type{$to}, x::Float32) = box($to,trunc_int($to,fpsiround32(unbox(Float32,x))))
iround(::Type{$to}, x::Float64) = box($to,trunc_int($to,fpsiround64(unbox(Float64,x))))
end
end

iround(::Type{Int32}, x::Float32) = box(Int32,fpsiround32(unbox(Float32,x)))
iround(::Type{Int32}, x::Float64) = box(Int32,trunc32(fpsiround64(unbox(Float64,x))))
iround(::Type{Int32}, x::Float64) = box(Int32,trunc_int(Int32,fpsiround64(unbox(Float64,x))))
iround(::Type{Uint32}, x::Float32) = box(Uint32,fpuiround32(unbox(Float32,x)))
iround(::Type{Uint32}, x::Float64) = box(Uint32,trunc32(fpuiround64(unbox(Float64,x))))
iround(::Type{Uint32}, x::Float64) = box(Uint32,trunc_int(Uint32,fpuiround64(unbox(Float64,x))))
iround(::Type{Int64}, x::Float32) = box(Int64,fpsiround64(fpext64(unbox(Float32,x))))
iround(::Type{Int64}, x::Float64) = box(Int64,fpsiround64(unbox(Float64,x)))
iround(::Type{Uint64}, x::Float32) = box(Uint64,fpuiround64(fpext64(unbox(Float32,x))))
iround(::Type{Uint64}, x::Float64) = box(Uint64,fpuiround64(unbox(Float64,x)))

iround(::Type{Int128}, x::Float32) = convert(Int128,round(x))
iround(::Type{Int128}, x::Float64) = convert(Int128,round(x))
iround(::Type{Uint128}, x::Float32) = convert(Uint128,round(x))
Expand Down
Loading

0 comments on commit 24268cc

Please sign in to comment.