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
-
efb5b304
by Raymond Toy at 2025-08-09T15:26:47-07:00
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:
... | ... | @@ -63,6 +63,8 @@ |
63 | 63 | |
64 | 64 | ;;; Please refer to the Unix man pages for details about these routines.
|
65 | 65 | |
66 | +#+core-math
|
|
67 | +(progn
|
|
66 | 68 | ;;; Trigonometric.
|
67 | 69 | (def-math-rtn ("cr_sin" %sin) 1)
|
68 | 70 | (def-math-rtn ("cr_cos" %cos) 1)
|
... | ... | @@ -91,6 +93,39 @@ |
91 | 93 | |
92 | 94 | (def-math-rtn ("cr_log1p" %log1p) 1)
|
93 | 95 | (def-math-rtn ("cr_expm1" %expm1) 1)
|
96 | +)
|
|
97 | + |
|
98 | +#-core-math
|
|
99 | +(progn
|
|
100 | +;;; Trigonometric.
|
|
101 | +(def-math-rtn ("fdlibm_sin" %sin) 1)
|
|
102 | +(def-math-rtn ("fdlibm_cos" %cos) 1)
|
|
103 | +(def-math-rtn ("fdlibm_tan" %tan) 1)
|
|
104 | +(def-math-rtn ("fdlibm_atan" %atan) 1)
|
|
105 | +(def-math-rtn ("__ieee754_atan2" %atan2) 2)
|
|
106 | +(def-math-rtn ("__ieee754_asin" %asin) 1)
|
|
107 | +(def-math-rtn ("__ieee754_acos" %acos) 1)
|
|
108 | +(def-math-rtn ("__ieee754_sinh" %sinh) 1)
|
|
109 | +(def-math-rtn ("__ieee754_cosh" %cosh) 1)
|
|
110 | +(def-math-rtn ("fdlibm_tanh" %tanh) 1)
|
|
111 | +(def-math-rtn ("fdlibm_asinh" %asinh) 1)
|
|
112 | +(def-math-rtn ("__ieee754_acosh" %acosh) 1)
|
|
113 | +(def-math-rtn ("__ieee754_atanh" %atanh) 1)
|
|
114 | + |
|
115 | +;;; Exponential and Logarithmic.
|
|
116 | +(def-math-rtn ("__ieee754_exp" %exp) 1)
|
|
117 | +(def-math-rtn ("__ieee754_log" %log) 1)
|
|
118 | +(def-math-rtn ("__ieee754_log10" %log10) 1)
|
|
119 | +(def-math-rtn ("cmucl_log2" %log2) 1)
|
|
120 | + |
|
121 | +(def-math-rtn ("__ieee754_pow" %pow) 2)
|
|
122 | +#-(or x86 sparc-v7 sparc-v8 sparc-v9)
|
|
123 | +(def-math-rtn "sqrt" 1)
|
|
124 | +(def-math-rtn ("hypot" %hypot) 2)
|
|
125 | + |
|
126 | +(def-math-rtn ("fdlibm_log1p" %log1p) 1)
|
|
127 | +(def-math-rtn ("fdlibm_expm1" %expm1) 1)
|
|
128 | +)
|
|
94 | 129 | |
95 | 130 | (declaim (inline %scalbn))
|
96 | 131 | (export '%scalbn)
|
... | ... | @@ -25,6 +25,7 @@ |
25 | 25 | (register-lisp-feature :linux)
|
26 | 26 | (register-lisp-feature :elf)
|
27 | 27 | (register-lisp-runtime-feature :executable)
|
28 | +(register-lisp-runtime-feature :core-math)
|
|
28 | 29 | |
29 | 30 | (setq *software-type* "Linux")
|
30 | 31 |
... | ... | @@ -36,22 +36,29 @@ |
36 | 36 | :from :eval :to :result) edx)
|
37 | 37 | (:temporary (:sc single-stack) temp-single)
|
38 | 38 | (:temporary (:sc double-stack) temp-double)
|
39 | + #+core-math
|
|
39 | 40 | (:temporary (:sc unsigned-stack) save-fpu-cw)
|
41 | + #+core-math
|
|
40 | 42 | (:temporary (:sc unsigned-stack) fpu-cw)
|
43 | + #+core-math
|
|
44 | + (:temporary (:sc unsigned-reg) temp-cw)
|
|
41 | 45 | (:node-var node)
|
42 | 46 | (:vop-var vop)
|
43 | 47 | (:save-p t)
|
44 | - (:ignore args ecx #+nil edx)
|
|
48 | + (:ignore args ecx edx)
|
|
45 | 49 | (:guard (backend-featurep :sse2))
|
46 | 50 | (:generator 0
|
47 | - ;; Save the x87 FPU control word. Then modify it to set the
|
|
48 | - ;; precision bits to double (2).
|
|
49 | - (inst fnstcw save-fpu-cw)
|
|
50 | - (move edx save-fpu-cw)
|
|
51 | - (inst and edx (dpb 0 (byte 2 8) #xffff)) ; Zap the precision control bits
|
|
52 | - (inst or edx (dpb 2 (byte 2 8) 0)) ; Set precision control to double
|
|
53 | - (move fpu-cw edx)
|
|
54 | - (inst fldcw fpu-cw) ; New CW
|
|
51 | + #+core-math
|
|
52 | + (progn
|
|
53 | + ;; Save the x87 FPU control word. Then modify it to set the
|
|
54 | + ;; precision bits to double (2).
|
|
55 | + (inst fnstcw save-fpu-cw)
|
|
56 | + (move temp-cw save-fpu-cw)
|
|
57 | + (inst and temp-cw (dpb 0 (byte 2 8) #xffff)) ; Zap the precision control bits
|
|
58 | + (inst or temp-cw (dpb 2 (byte 2 8) 0)) ; Set precision control to double
|
|
59 | + (move fpu-cw temp-cw)
|
|
60 | + (inst fldcw fpu-cw) ; New CW
|
|
61 | + )
|
|
55 | 62 | |
56 | 63 | (cond ((policy node (> space speed))
|
57 | 64 | (move eax function)
|
... | ... | @@ -76,6 +83,7 @@ |
76 | 83 | (inst fstpd (ea-for-df-stack temp-double))
|
77 | 84 | (inst movsd xmm0-tn (ea-for-df-stack temp-double)))))
|
78 | 85 | ;; Restore the x87 FPU control settings
|
86 | + #+core-math
|
|
79 | 87 | (inst fldcw save-fpu-cw)))
|
80 | 88 | |
81 | 89 | (define-vop (alloc-number-stack-space)
|
... | ... | @@ -36,6 +36,36 @@ ifdef FEATURE_ELF |
36 | 36 | CPP_DEFINE_OPTIONS += -DFEATURE_ELF
|
37 | 37 | endif
|
38 | 38 | |
39 | +# If core-math feature is set, we use core-math routines for the
|
|
40 | +# special functions.
|
|
41 | + |
|
42 | +ifdef FEATURE_CORE_MATH
|
|
43 | +CORE_MATH_64=core-math/src/binary64
|
|
44 | + |
|
45 | +CORE64_OBJS=\
|
|
46 | + $(CORE_MATH_64)/sin/sin.o \
|
|
47 | + $(CORE_MATH_64)/cos/cos.o \
|
|
48 | + $(CORE_MATH_64)/tan/tan.o \
|
|
49 | + $(CORE_MATH_64)/atan2/atan2.o \
|
|
50 | + $(CORE_MATH_64)/asin/asin.o \
|
|
51 | + $(CORE_MATH_64)/acos/acos.o \
|
|
52 | + $(CORE_MATH_64)/atan/atan.o \
|
|
53 | + $(CORE_MATH_64)/sinh/sinh.o \
|
|
54 | + $(CORE_MATH_64)/cosh/cosh.o \
|
|
55 | + $(CORE_MATH_64)/tanh/tanh.o \
|
|
56 | + $(CORE_MATH_64)/asinh/asinh.o \
|
|
57 | + $(CORE_MATH_64)/acosh/acosh.o \
|
|
58 | + $(CORE_MATH_64)/atanh/atanh.o \
|
|
59 | + $(CORE_MATH_64)/exp/exp.o \
|
|
60 | + $(CORE_MATH_64)/log/log.o \
|
|
61 | + $(CORE_MATH_64)/log10/log10.o \
|
|
62 | + $(CORE_MATH_64)/log2/log2.o \
|
|
63 | + $(CORE_MATH_64)/pow/pow.o \
|
|
64 | + $(CORE_MATH_64)/hypot/hypot.o \
|
|
65 | + $(CORE_MATH_64)/log1p/log1p.o \
|
|
66 | + $(CORE_MATH_64)/expm1/expm1.o
|
|
67 | +endif
|
|
68 | + |
|
39 | 69 | ifeq ($(filter 2% 3%, $(shell $(CC) -dumpversion)),)
|
40 | 70 | CPP_INCLUDE_OPTIONS := -iquote . -iquote $(PATH1)
|
41 | 71 | else
|
... | ... | @@ -36,30 +36,6 @@ SRCS = lisp.c coreparse.c alloc.c monitor.c print.c interr.c \ |
36 | 36 | runprog.c time.c case-mapping.c exec-init.c \
|
37 | 37 | ${FDLIBM} ${ARCH_SRC} ${ASSEM_SRC} ${OS_SRC} ${GC_SRC}
|
38 | 38 | |
39 | -CORE_MATH_64=core-math/src/binary64
|
|
40 | - |
|
41 | -CORE64_OBJS=\
|
|
42 | - $(CORE_MATH_64)/sin/sin.o \
|
|
43 | - $(CORE_MATH_64)/cos/cos.o \
|
|
44 | - $(CORE_MATH_64)/tan/tan.o \
|
|
45 | - $(CORE_MATH_64)/atan2/atan2.o \
|
|
46 | - $(CORE_MATH_64)/asin/asin.o \
|
|
47 | - $(CORE_MATH_64)/acos/acos.o \
|
|
48 | - $(CORE_MATH_64)/atan/atan.o \
|
|
49 | - $(CORE_MATH_64)/sinh/sinh.o \
|
|
50 | - $(CORE_MATH_64)/cosh/cosh.o \
|
|
51 | - $(CORE_MATH_64)/tanh/tanh.o \
|
|
52 | - $(CORE_MATH_64)/asinh/asinh.o \
|
|
53 | - $(CORE_MATH_64)/acosh/acosh.o \
|
|
54 | - $(CORE_MATH_64)/atanh/atanh.o \
|
|
55 | - $(CORE_MATH_64)/exp/exp.o \
|
|
56 | - $(CORE_MATH_64)/log/log.o \
|
|
57 | - $(CORE_MATH_64)/log10/log10.o \
|
|
58 | - $(CORE_MATH_64)/log2/log2.o \
|
|
59 | - $(CORE_MATH_64)/pow/pow.o \
|
|
60 | - $(CORE_MATH_64)/hypot/hypot.o \
|
|
61 | - $(CORE_MATH_64)/log1p/log1p.o \
|
|
62 | - $(CORE_MATH_64)/expm1/expm1.o
|
|
63 | 39 | |
64 | 40 | OBJS = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(patsubst %.s,%.o,$(SRCS))))
|
65 | 41 |