
Raymond Toy pushed to branch issue-425-correctly-rounded-math-functions at cmucl / cmucl Commits: 5150b97d by Raymond Toy at 2025-08-09T15:24:38-07:00 Define new temp to old the FPU Cw We were using edx as a temp to old the FPU CW, but that might interfere with the actual use of the edx register. This showed up with a segfault in computing (abs #c(-3d0 4d0)) (from the ansi-tests). Hence, define a new temp reg that we can for the FPU CW. - - - - - efb5b304 by Raymond Toy at 2025-08-09T15:26:47-07:00 Register :core-math as a runtime feature for Linux Add a new feature :core-math to enable the use of the core-math functions. This is so we can continue to run CI on Darwin until we can figure out if we can use core-math on the ancient version of Darwin that we're using for CI. Thus, set the :core-math feature in Linux-os.lisp. Update irrat.lisp to use core-math only if :core-math is defined. Otherwise, we use fdlibm, as before. Update Config.x86_common to define the core-math object files when FEATURE_CORE_MATH is defined (because we registered :core-math as a runtime feature). Move the core-math object files from GNUmakefile to Config.x86_linux_common. - - - - - 5 changed files: - src/code/irrat.lisp - src/code/linux-os.lisp - src/compiler/x86/sse2-c-call.lisp - src/lisp/Config.x86_common - src/lisp/GNUmakefile Changes: ===================================== src/code/irrat.lisp ===================================== @@ -63,6 +63,8 @@ ;;; Please refer to the Unix man pages for details about these routines. +#+core-math +(progn ;;; Trigonometric. (def-math-rtn ("cr_sin" %sin) 1) (def-math-rtn ("cr_cos" %cos) 1) @@ -91,6 +93,39 @@ (def-math-rtn ("cr_log1p" %log1p) 1) (def-math-rtn ("cr_expm1" %expm1) 1) +) + +#-core-math +(progn +;;; Trigonometric. +(def-math-rtn ("fdlibm_sin" %sin) 1) +(def-math-rtn ("fdlibm_cos" %cos) 1) +(def-math-rtn ("fdlibm_tan" %tan) 1) +(def-math-rtn ("fdlibm_atan" %atan) 1) +(def-math-rtn ("__ieee754_atan2" %atan2) 2) +(def-math-rtn ("__ieee754_asin" %asin) 1) +(def-math-rtn ("__ieee754_acos" %acos) 1) +(def-math-rtn ("__ieee754_sinh" %sinh) 1) +(def-math-rtn ("__ieee754_cosh" %cosh) 1) +(def-math-rtn ("fdlibm_tanh" %tanh) 1) +(def-math-rtn ("fdlibm_asinh" %asinh) 1) +(def-math-rtn ("__ieee754_acosh" %acosh) 1) +(def-math-rtn ("__ieee754_atanh" %atanh) 1) + +;;; Exponential and Logarithmic. +(def-math-rtn ("__ieee754_exp" %exp) 1) +(def-math-rtn ("__ieee754_log" %log) 1) +(def-math-rtn ("__ieee754_log10" %log10) 1) +(def-math-rtn ("cmucl_log2" %log2) 1) + +(def-math-rtn ("__ieee754_pow" %pow) 2) +#-(or x86 sparc-v7 sparc-v8 sparc-v9) +(def-math-rtn "sqrt" 1) +(def-math-rtn ("hypot" %hypot) 2) + +(def-math-rtn ("fdlibm_log1p" %log1p) 1) +(def-math-rtn ("fdlibm_expm1" %expm1) 1) +) (declaim (inline %scalbn)) (export '%scalbn) ===================================== src/code/linux-os.lisp ===================================== @@ -25,6 +25,7 @@ (register-lisp-feature :linux) (register-lisp-feature :elf) (register-lisp-runtime-feature :executable) +(register-lisp-runtime-feature :core-math) (setq *software-type* "Linux") ===================================== src/compiler/x86/sse2-c-call.lisp ===================================== @@ -36,22 +36,29 @@ :from :eval :to :result) edx) (:temporary (:sc single-stack) temp-single) (:temporary (:sc double-stack) temp-double) + #+core-math (:temporary (:sc unsigned-stack) save-fpu-cw) + #+core-math (:temporary (:sc unsigned-stack) fpu-cw) + #+core-math + (:temporary (:sc unsigned-reg) temp-cw) (:node-var node) (:vop-var vop) (:save-p t) - (:ignore args ecx #+nil edx) + (:ignore args ecx edx) (:guard (backend-featurep :sse2)) (:generator 0 - ;; Save the x87 FPU control word. Then modify it to set the - ;; precision bits to double (2). - (inst fnstcw save-fpu-cw) - (move edx save-fpu-cw) - (inst and edx (dpb 0 (byte 2 8) #xffff)) ; Zap the precision control bits - (inst or edx (dpb 2 (byte 2 8) 0)) ; Set precision control to double - (move fpu-cw edx) - (inst fldcw fpu-cw) ; New CW + #+core-math + (progn + ;; Save the x87 FPU control word. Then modify it to set the + ;; precision bits to double (2). + (inst fnstcw save-fpu-cw) + (move temp-cw save-fpu-cw) + (inst and temp-cw (dpb 0 (byte 2 8) #xffff)) ; Zap the precision control bits + (inst or temp-cw (dpb 2 (byte 2 8) 0)) ; Set precision control to double + (move fpu-cw temp-cw) + (inst fldcw fpu-cw) ; New CW + ) (cond ((policy node (> space speed)) (move eax function) @@ -76,6 +83,7 @@ (inst fstpd (ea-for-df-stack temp-double)) (inst movsd xmm0-tn (ea-for-df-stack temp-double))))) ;; Restore the x87 FPU control settings + #+core-math (inst fldcw save-fpu-cw))) (define-vop (alloc-number-stack-space) ===================================== src/lisp/Config.x86_common ===================================== @@ -36,6 +36,36 @@ ifdef FEATURE_ELF CPP_DEFINE_OPTIONS += -DFEATURE_ELF endif +# If core-math feature is set, we use core-math routines for the +# special functions. + +ifdef FEATURE_CORE_MATH +CORE_MATH_64=core-math/src/binary64 + +CORE64_OBJS=\ + $(CORE_MATH_64)/sin/sin.o \ + $(CORE_MATH_64)/cos/cos.o \ + $(CORE_MATH_64)/tan/tan.o \ + $(CORE_MATH_64)/atan2/atan2.o \ + $(CORE_MATH_64)/asin/asin.o \ + $(CORE_MATH_64)/acos/acos.o \ + $(CORE_MATH_64)/atan/atan.o \ + $(CORE_MATH_64)/sinh/sinh.o \ + $(CORE_MATH_64)/cosh/cosh.o \ + $(CORE_MATH_64)/tanh/tanh.o \ + $(CORE_MATH_64)/asinh/asinh.o \ + $(CORE_MATH_64)/acosh/acosh.o \ + $(CORE_MATH_64)/atanh/atanh.o \ + $(CORE_MATH_64)/exp/exp.o \ + $(CORE_MATH_64)/log/log.o \ + $(CORE_MATH_64)/log10/log10.o \ + $(CORE_MATH_64)/log2/log2.o \ + $(CORE_MATH_64)/pow/pow.o \ + $(CORE_MATH_64)/hypot/hypot.o \ + $(CORE_MATH_64)/log1p/log1p.o \ + $(CORE_MATH_64)/expm1/expm1.o +endif + ifeq ($(filter 2% 3%, $(shell $(CC) -dumpversion)),) CPP_INCLUDE_OPTIONS := -iquote . -iquote $(PATH1) else ===================================== src/lisp/GNUmakefile ===================================== @@ -36,30 +36,6 @@ SRCS = lisp.c coreparse.c alloc.c monitor.c print.c interr.c \ runprog.c time.c case-mapping.c exec-init.c \ ${FDLIBM} ${ARCH_SRC} ${ASSEM_SRC} ${OS_SRC} ${GC_SRC} -CORE_MATH_64=core-math/src/binary64 - -CORE64_OBJS=\ - $(CORE_MATH_64)/sin/sin.o \ - $(CORE_MATH_64)/cos/cos.o \ - $(CORE_MATH_64)/tan/tan.o \ - $(CORE_MATH_64)/atan2/atan2.o \ - $(CORE_MATH_64)/asin/asin.o \ - $(CORE_MATH_64)/acos/acos.o \ - $(CORE_MATH_64)/atan/atan.o \ - $(CORE_MATH_64)/sinh/sinh.o \ - $(CORE_MATH_64)/cosh/cosh.o \ - $(CORE_MATH_64)/tanh/tanh.o \ - $(CORE_MATH_64)/asinh/asinh.o \ - $(CORE_MATH_64)/acosh/acosh.o \ - $(CORE_MATH_64)/atanh/atanh.o \ - $(CORE_MATH_64)/exp/exp.o \ - $(CORE_MATH_64)/log/log.o \ - $(CORE_MATH_64)/log10/log10.o \ - $(CORE_MATH_64)/log2/log2.o \ - $(CORE_MATH_64)/pow/pow.o \ - $(CORE_MATH_64)/hypot/hypot.o \ - $(CORE_MATH_64)/log1p/log1p.o \ - $(CORE_MATH_64)/expm1/expm1.o OBJS = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(patsubst %.s,%.o,$(SRCS)))) View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/44d0795cfada2045adb9d39... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/44d0795cfada2045adb9d39... You're receiving this email because of your account on gitlab.common-lisp.net.
participants (1)
-
Raymond Toy (@rtoy)