Skip to content

Commit

Permalink
entirely hookup runtime-intrinsics
Browse files Browse the repository at this point in the history
all intrinsics (but one) are now fully error-checking and runtime-interpreter-compatible
  • Loading branch information
vtjnash committed Oct 3, 2016
1 parent a8962f3 commit 5595287
Show file tree
Hide file tree
Showing 5 changed files with 739 additions and 886 deletions.
32 changes: 16 additions & 16 deletions base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@

## floating-point functions ##

copysign(x::Float64, y::Float64) = box(Float64,copysign_float(unbox(Float64,x),unbox(Float64,y)))
copysign(x::Float32, y::Float32) = box(Float32,copysign_float(unbox(Float32,x),unbox(Float32,y)))
copysign(x::Float64, y::Float64) = box(Float64, copysign_float(x, y))
copysign(x::Float32, y::Float32) = box(Float32, copysign_float(x, y))
copysign(x::Float32, y::Real) = copysign(x, Float32(y))
copysign(x::Float64, y::Real) = copysign(x, Float64(y))

flipsign(x::Float64, y::Float64) = box(Float64,xor_int(unbox(Float64,x),and_int(unbox(Float64,y),0x8000000000000000)))
flipsign(x::Float32, y::Float32) = box(Float32,xor_int(unbox(Float32,x),and_int(unbox(Float32,y),0x80000000)))
flipsign(x::Float64, y::Float64) = box(Float64, xor_int(box(UInt64, x), and_int(box(UInt64, y), 0x8000000000000000)))
flipsign(x::Float32, y::Float32) = box(Float32, xor_int(box(UInt32, x), and_int(box(UInt32, y), 0x80000000)))
flipsign(x::Float32, y::Real) = flipsign(x, Float32(y))
flipsign(x::Float64, y::Real) = flipsign(x, Float64(y))

signbit(x::Float64) = signbit(reinterpret(Int64,x))
signbit(x::Float32) = signbit(reinterpret(Int32,x))
signbit(x::Float16) = signbit(reinterpret(Int16,x))
signbit(x::Float64) = signbit(box(Int64, x))
signbit(x::Float32) = signbit(box(Int32, x))
signbit(x::Float16) = signbit(box(Int16, x))

maxintfloat(::Type{Float64}) = 9007199254740992.
maxintfloat(::Type{Float32}) = Float32(16777216.)
maxintfloat(::Type{Float16}) = Float16(2048f0)
maxintfloat{T<:AbstractFloat}(x::T) = maxintfloat(T)
maxintfloat() = maxintfloat(Float64)

isinteger(x::AbstractFloat) = x-trunc(x) == 0
isinteger(x::AbstractFloat) = (x - trunc(x) == 0)

num2hex(x::Float16) = hex(reinterpret(UInt16,x), 4)
num2hex(x::Float32) = hex(box(UInt32,unbox(Float32,x)),8)
num2hex(x::Float64) = hex(box(UInt64,unbox(Float64,x)),16)
num2hex(x::Float16) = hex(box(UInt16, x), 4)
num2hex(x::Float32) = hex(box(UInt32, x), 8)
num2hex(x::Float64) = hex(box(UInt64, x), 16)

function hex2num(s::AbstractString)
if length(s) <= 4
return box(Float16,unbox(UInt16,parse(UInt16,s,16)))
return box(Float16, parse(UInt16, s, 16))
end
if length(s) <= 8
return box(Float32,unbox(UInt32,parse(UInt32,s,16)))
return box(Float32, parse(UInt32, s, 16))
end
return box(Float64,unbox(UInt64,parse(UInt64,s,16)))
return box(Float64, parse(UInt64, s, 16))
end

"""
Expand Down Expand Up @@ -249,9 +249,9 @@ fma_libm(x::Float32, y::Float32, z::Float32) =
fma_libm(x::Float64, y::Float64, z::Float64) =
ccall(("fma", libm_name), Float64, (Float64,Float64,Float64), x, y, z)
fma_llvm(x::Float32, y::Float32, z::Float32) =
box(Float32,fma_float(unbox(Float32,x),unbox(Float32,y),unbox(Float32,z)))
box(Float32, fma_float(x, y, z))
fma_llvm(x::Float64, y::Float64, z::Float64) =
box(Float64,fma_float(unbox(Float64,x),unbox(Float64,y),unbox(Float64,z)))
box(Float64, fma_float(x, y, z))
# Disable LLVM's fma if it is incorrect, e.g. because LLVM falls back
# onto a broken system libm; if so, use openlibm's fma instead
# 1.0000305f0 = 1 + 1/2^15
Expand Down
Loading

0 comments on commit 5595287

Please sign in to comment.