Skip to content

Commit

Permalink
Replace use of fdlibm with openlibm.
Browse files Browse the repository at this point in the history
  • Loading branch information
ViralBShah committed Oct 25, 2012
1 parent 31b6d18 commit 29cb79b
Show file tree
Hide file tree
Showing 241 changed files with 180 additions and 20,369 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ install: release
cp $(BUILD)/bin/*julia* $(PREFIX)/bin
cd $(PREFIX)/bin && ln -s julia-release-$(DEFAULT_REPL) julia
cp -R -L $(BUILD)/lib/julia/* $(PREFIX)/lib/julia
-cp $(BUILD)/lib/lib{Rmath,amd,amos,arpack,cholmod,colamd,fdm,fftw3,fftw3f,fftw3_threads,fftw3f_threads,glpk,glpk_wrapper,gmp,gmp_wrapper,grisu,history,julia-release,$(OPENBLASNAME),openlibm,pcre,random,readline,suitesparse_wrapper,tk_wrapper,umfpack,z}.$(SHLIB_EXT) $(PREFIX)/lib
-cp $(BUILD)/lib/lib{Rmath,amd,amos,arpack,cholmod,colamd,openlibm,fftw3,fftw3f,fftw3_threads,fftw3f_threads,glpk,glpk_wrapper,gmp,gmp_wrapper,grisu,history,julia-release,$(OPENBLASNAME),openlibm,pcre,random,readline,suitesparse_wrapper,tk_wrapper,umfpack,z}.$(SHLIB_EXT) $(PREFIX)/lib
# Web-REPL stuff
-cp $(BUILD)/lib/mod* $(PREFIX)/lib
-cp $(BUILD)/sbin/* $(PREFIX)/sbin
Expand Down
2 changes: 1 addition & 1 deletion base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ iround(::Type{Uint64}, x::Float64) = box(Uint64,fpuiround64(unbox(Float64,x)))
# TODO: Int128

# this is needed very early because it is used by Range and colon
floor(x::Float64) = ccall(dlsym(_jl_libfdm,:floor), Float64, (Float64,), x)
floor(x::Float64) = ccall(dlsym(libopenlibm,:floor), Float64, (Float64,), x)

iceil(x::FloatingPoint) = itrunc(ceil(x)) # TODO: fast primitive for iceil
ifloor(x::FloatingPoint) = itrunc(floor(x)) # TOOD: fast primitive for ifloor
Expand Down
157 changes: 0 additions & 157 deletions base/math_libm.jl

This file was deleted.

157 changes: 157 additions & 0 deletions base/openlibm.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
libopenlibm = dlopen("libopenlibm")

macro libopenlibmfunc_1arg_float(T,f)
quote
$(esc(f))(x::Float64) = ccall(dlsym(libopenlibm,$(string(f))), Float64, (Float64,), x)
$(esc(f))(x::Float32) = ccall(dlsym(libopenlibm,$(string(f,"f"))), Float32, (Float32,), x)
$(esc(f))(x::Real) = ($f)(float(x))
@vectorize_1arg $T $f
end
end

macro libopenlibmfunc_1arg_float(T,f)
quote
$(esc(f))(x::Float64) = ccall(dlsym(libopenlibm,$(string(f))), Float64, (Float64,), x)
$(esc(f))(x::Float32) = ccall(dlsym(libopenlibm,$(string(f,"f"))), Float32, (Float32,), x)
$(esc(f))(x::Real) = ($f)(float(x))
@vectorize_1arg $T $f
end
end

macro libopenlibmfunc_1arg_int(T,f,name...)
if length(name)>0
fname = name[1]
else
fname = f
end
quote
$(esc(fname))(x::Float64) = ccall(dlsym(libopenlibm,$(string(f))), Int32, (Float64,), x)
$(esc(fname))(x::Float32) = ccall(dlsym(libopenlibm,$(string(f,"f"))), Int32, (Float32,), x)
@vectorize_1arg $T $fname
end
end

macro libopenlibmfunc_2arg(T,f)
quote
$(esc(f))(x::Float64, y::Float64) = ccall(dlsym(libopenlibm,$(string(f))), Float64, (Float64, Float64,), x, y)
$(esc(f))(x::Float32, y::Float32) = ccall(dlsym(libopenlibm,$(string(f,"f"))), Float32, (Float32, Float32), x, y)
@vectorize_2arg $T $f
end
end

@libopenlibmfunc_1arg_float Number cbrt
@libopenlibmfunc_1arg_float Number sin
@libopenlibmfunc_1arg_float Number cos
@libopenlibmfunc_1arg_float Number tan
@libopenlibmfunc_1arg_float Number sinh
@libopenlibmfunc_1arg_float Number cosh
@libopenlibmfunc_1arg_float Number tanh
@libopenlibmfunc_1arg_float Number asin
@libopenlibmfunc_1arg_float Number acos
@libopenlibmfunc_1arg_float Number atan
@libopenlibmfunc_1arg_float Number asinh
@libopenlibmfunc_1arg_float Number acosh
@libopenlibmfunc_1arg_float Number atanh
@libopenlibmfunc_1arg_float Number log
@libopenlibmfunc_1arg_float Number log2
@libopenlibmfunc_1arg_float Number log10
@libopenlibmfunc_1arg_float Real log1p
@libopenlibmfunc_1arg_float Real logb
@libopenlibmfunc_1arg_float Number exp
@libopenlibmfunc_1arg_float Real expm1
@libopenlibmfunc_1arg_float Number erf
@libopenlibmfunc_1arg_float Number erfc
@libopenlibmfunc_1arg_float Real ceil
@libopenlibmfunc_1arg_float Real floor
#@libopenlibmfunc_1arg_float Real rint
@libopenlibmfunc_1arg_float Number lgamma

@libopenlibmfunc_1arg_float Number sqrt
@libopenlibmfunc_1arg_float Number exp2
#@libopenlibmfunc_1arg_float Real nearbyint
@libopenlibmfunc_1arg_float Real trunc
@libopenlibmfunc_1arg_float Real round

@libopenlibmfunc_2arg Number atan2
atan2(x::Real, y::Real) = atan2(float64(x), float64(y))
@libopenlibmfunc_2arg Number hypot
hypot(x::Float32, y::Float64) = hypot(float64(x), y)
hypot(x::Float64, y::Float32) = hypot(x, float64(y))

gamma(x::Float64) = ccall(dlsym(libopenlibm, :tgamma), Float64, (Float64,), x)
gamma(x::Float32) = float32(gamma(float64(x)))
gamma(x::Real) = gamma(float(x))
@vectorize_1arg Number gamma

lfact(x::Real) = (x<=1 ? zero(x) : lgamma(x+one(x)))
@vectorize_1arg Number lfact

max(x::Float64, y::Float64) = ccall(dlsym(libopenlibm, :fmax), Float64, (Float64,Float64), x, y)
max(x::Float32, y::Float32) = ccall(dlsym(libopenlibm, :fmaxf), Float32, (Float32,Float32), x, y)
@vectorize_2arg Real max

min(x::Float64, y::Float64) = ccall(dlsym(libopenlibm, :fmin), Float64, (Float64,Float64), x, y)
min(x::Float32, y::Float32) = ccall(dlsym(libopenlibm, :fminf), Float32, (Float32,Float32), x, y)
@vectorize_2arg Real min

#@libopenlibmfunc_1arg_int Real lrint
#@libopenlibmfunc_1arg_int Real lround iround
function ilogb(x::Float64)
if x==0 || isnan(x)
throw(DomainError())
end
int(ccall(dlsym(libopenlibm,:ilogb), Int32, (Float64,), x))
end
function ilogb(x::Float32)
if x==0 || isnan(x)
throw(DomainError())
end
int(ccall(dlsym(libopenlibm,:ilogbf), Int32, (Float32,), x))
end
@vectorize_1arg Real ilogb

@libopenlibmfunc_1arg_float Real significand

ldexp(x::Float64,e::Int) = ccall(dlsym(libopenlibm, :ldexp), Float64, (Float64,Int32), x, int32(e))
ldexp(x::Float32,e::Int) = ccall(dlsym(libopenlibm, :ldexpf), Float32, (Float32,Int32), x, int32(e))
# TODO: vectorize does not do the right thing for these argument types
#@vectorize_2arg Real ldexp

begin
local exp::Array{Int32,1} = zeros(Int32,1)
global frexp
function frexp(x::Float64)
s = ccall(dlsym(libopenlibm,:frexp), Float64, (Float64, Ptr{Int32}), x, exp)
(s, int(exp[1]))
end
function frexp(x::Float32)
s = ccall(dlsym(libopenlibm,:frexpf), Float32, (Float32, Ptr{Int32}), x, exp)
(s, int(exp[1]))
end
function frexp(A::Array{Float64})
f = similar(A)
e = Array(Int, size(A))
for i = 1:numel(A)
f[i] = ccall(dlsym(libopenlibm,:frexp), Float64, (Float64, Ptr{Int32}), A[i], exp)
e[i] = exp[1]
end
return (f, e)
end
function frexp(A::Array{Float32})
f = similar(A)
e = Array(Int, size(A))
for i = 1:numel(A)
f[i] = ccall(dlsym(libopenlibm,:frexpf), Float32, (Float32, Ptr{Int32}), A[i], exp)
e[i] = exp[1]
end
return (f, e)
end
end

modf(x) = rem(x,one(x)), trunc(x)

^(x::Float64, y::Float64) = ccall(dlsym(libopenlibm, :pow), Float64, (Float64,Float64), x, y)
^(x::Float32, y::Float32) = ccall(dlsym(libopenlibm, :powf), Float32, (Float32,Float32), x, y)

^(x::Float64, y::Integer) = x^float64(y)
^(x::Float32, y::Integer) = x^float32(y)
3 changes: 1 addition & 2 deletions base/start_image.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ _jl_lib = ccall(:jl_load_dynamic_library,Ptr{Void},(Ptr{None},),C_NULL)
# Essential libraries
libpcre = dlopen("libpcre")
libgrisu = dlopen("libgrisu")
_jl_libm = dlopen("libm")
_jl_libfdm = dlopen("libfdm")
librandom = dlopen("librandom")
libopenlibm = dlopen("libopenlibm")
@windows_only _jl_advapi32 = dlopen("Advapi32")

# Optional libraries
Expand Down
4 changes: 2 additions & 2 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ include("operators.jl")
include("pointer.jl")

_jl_lib = ccall(:jl_load_dynamic_library,Ptr{Void},(Ptr{None},),C_NULL)
_jl_libfdm = dlopen("libfdm")
libopenlibm = dlopen("libopenlibm")

include("float.jl")
include("reduce.jl")
Expand Down Expand Up @@ -105,7 +105,7 @@ include("client.jl")
include("intfuncs.jl")
include("floatfuncs.jl")
include("math.jl")
include("math_libm.jl")
include("openlibm.jl")
include("sort.jl")
include("combinatorics.jl")
include("statistics.jl")
Expand Down
Loading

0 comments on commit 29cb79b

Please sign in to comment.