Skip to content

Commit

Permalink
Use system libm everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
ViralBShah committed Sep 18, 2021
1 parent f8d3bd2 commit f274420
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
6 changes: 2 additions & 4 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ USE_SYSTEM_LLVM:=0
USE_SYSTEM_LIBUNWIND:=0
DISABLE_LIBUNWIND:=0
USE_SYSTEM_PCRE:=0
USE_SYSTEM_LIBM:=0
#USE_SYSTEM_LIBM:=0
USE_SYSTEM_LIBM:=1
USE_SYSTEM_OPENLIBM:=0
UNTRUSTED_SYSTEM_LIBM:=0
USE_SYSTEM_DSFMT:=0
Expand Down Expand Up @@ -1123,9 +1124,6 @@ endif
ifeq ($(USE_SYSTEM_LIBM), 1)
LIBM := -lm
LIBMNAME := libm
else
LIBM := -lopenlibm
LIBMNAME := libopenlibm
endif

ifeq ($(USE_SYSTEM_LIBUV), 1)
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ ifeq ($(BUNDLE_DEBUG_LIBS),1)
-$(INSTALL_M) $(build_bindir)/libjulia-debug.dll $(DESTDIR)$(bindir)/
-$(INSTALL_M) $(build_libdir)/libjulia-debug.dll.a $(DESTDIR)$(libdir)/
endif
ifeq ($(USE_SYSTEM_LIBM),0)
-$(INSTALL_M) $(build_bindir)/libopenlibm.dll.a $(DESTDIR)$(libdir)/
endif
else

# Copy over .dSYM directories directly for Darwin
Expand Down
11 changes: 5 additions & 6 deletions base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ ifeq ($(XC_HOST),)
else
@echo "const MACHINE = \"$(XC_HOST)\"" >> $@
endif
@echo "const libm_name = \"$(LIBMNAME)\"" >> $@
@echo "const libblas_name = \"$(LIBBLASNAME)\"" >> $@
@echo "const liblapack_name = \"$(LIBLAPACKNAME)\"" >> $@
ifeq ($(USE_BLAS64), 1)
Expand Down Expand Up @@ -187,11 +186,11 @@ endef

# the following excludes: libuv.a, libutf8proc.a

ifneq ($(USE_SYSTEM_LIBM),0)
$(eval $(call symlink_system_library,LIBM,$(LIBMNAME)))
else ifneq ($(USE_SYSTEM_OPENLIBM),0)
$(eval $(call symlink_system_library,OPENLIBM,$(LIBMNAME)))
endif
#ifneq ($(USE_SYSTEM_LIBM),0)
#$(eval $(call symlink_system_library,LIBM,$(LIBMNAME)))
#else ifneq ($(USE_SYSTEM_OPENLIBM),0)
#$(eval $(call symlink_system_library,OPENLIBM,$(LIBMNAME)))
#endif

$(eval $(call symlink_system_library,CSL,libgcc_s,1))
ifneq (,$(LIBGFORTRAN_VERSION))
Expand Down
4 changes: 2 additions & 2 deletions base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ algorithms. See [`muladd`](@ref).
function fma end

fma_libm(x::Float32, y::Float32, z::Float32) =
ccall(("fmaf", libm_name), Float32, (Float32,Float32,Float32), x, y, z)
ccall("fmaf", Float32, (Float32,Float32,Float32), x, y, z)
fma_libm(x::Float64, y::Float64, z::Float64) =
ccall(("fma", libm_name), Float64, (Float64,Float64,Float64), x, y, z)
ccall("fma", Float64, (Float64,Float64,Float64), x, y, z)
fma_llvm(x::Float32, y::Float32, z::Float32) = fma_float(x, y, z)
fma_llvm(x::Float64, y::Float64, z::Float64) = fma_float(x, y, z)
# Disable LLVM's fma if it is incorrect, e.g. because LLVM falls back
Expand Down
10 changes: 4 additions & 6 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,6 @@ log(b::Number, x::Number) = log(promote(b,x)...)

# type specific math functions

const libm = Base.libm_name

# functions with no domain error
"""
sinh(x)
Expand Down Expand Up @@ -875,9 +873,9 @@ function frexp(x::T) where T<:IEEEFloat
end

rem(x::Float64, y::Float64, ::RoundingMode{:Nearest}) =
ccall((:remainder, libm),Float64,(Float64,Float64),x,y)
ccall(:remainder, Float64,(Float64,Float64),x,y)
rem(x::Float32, y::Float32, ::RoundingMode{:Nearest}) =
ccall((:remainderf, libm),Float32,(Float32,Float32),x,y)
ccall(:remainderf, Float32,(Float32,Float32),x,y)
rem(x::Float16, y::Float16, r::RoundingMode{:Nearest}) = Float16(rem(Float32(x), Float32(y), r))


Expand All @@ -900,13 +898,13 @@ modf(x) = isinf(x) ? (flipsign(zero(x), x), x) : (rem(x, one(x)), trunc(x))

function modf(x::Float32)
temp = Ref{Float32}()
f = ccall((:modff, libm), Float32, (Float32, Ptr{Float32}), x, temp)
f = ccall(:modff, Float32, (Float32, Ptr{Float32}), x, temp)
f, temp[]
end

function modf(x::Float64)
temp = Ref{Float64}()
f = ccall((:modf, libm), Float64, (Float64, Ptr{Float64}), x, temp)
f = ccall(:modf, Float64, (Float64, Ptr{Float64}), x, temp)
f, temp[]
end

Expand Down
6 changes: 3 additions & 3 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ endif

# list all targets
DEP_LIBS_STAGED_ALL := llvm llvm-tools clang llvmunwind unwind libuv pcre \
openlibm dsfmt blastrampoline openblas lapack gmp mpfr patchelf utf8proc \
dsfmt blastrampoline openblas lapack gmp mpfr patchelf utf8proc \
objconv mbedtls libssh2 nghttp2 curl libgit2 libwhich zlib p7zip csl \
libsuitesparse
libsuitesparse # openlibm
DEP_LIBS_ALL := $(DEP_LIBS_STAGED_ALL)

ifneq ($(USE_BINARYBUILDER_OPENBLAS),0)
Expand Down Expand Up @@ -204,7 +204,7 @@ include $(SRCDIR)/csl.mk
include $(SRCDIR)/llvm.mk
include $(SRCDIR)/libuv.mk
include $(SRCDIR)/pcre.mk
include $(SRCDIR)/openlibm.mk
#include $(SRCDIR)/openlibm.mk
include $(SRCDIR)/dsfmt.mk
include $(SRCDIR)/objconv.mk
include $(SRCDIR)/blastrampoline.mk
Expand Down

0 comments on commit f274420

Please sign in to comment.