[Git][cmucl/cmucl][issue-425-correctly-rounded-math-functions] Set 64-bit precision (80-bit float) in call-out

Raymond Toy pushed to branch issue-425-correctly-rounded-math-functions at cmucl / cmucl Commits: 5ff177cb by Raymond Toy at 2025-08-13T15:06:30-07:00 Set 64-bit precision (80-bit float) in call-out Add some tests for the special functions where we were computing the incorrect value when the precision was not set to 64-bit (80-bit float). - - - - - 2 changed files: - src/compiler/x86/sse2-c-call.lisp - tests/irrat.lisp Changes: ===================================== src/compiler/x86/sse2-c-call.lisp ===================================== @@ -41,7 +41,7 @@ #+core-math (:temporary (:sc unsigned-stack) fpu-cw) #+core-math - (:temporary (:sc unsigned-reg) temp-cw) + (:temporary (:sc unsigned-reg :offset esi-offset) temp-cw) (:node-var node) (:vop-var vop) (:save-p t) @@ -51,11 +51,14 @@ #+core-math (progn ;; Save the x87 FPU control word. Then modify it to set the - ;; precision bits to double (2). + ;; precision bits to 3 for 64-bit mantissas for 80-bit + ;; arithmetic. If we don't some of some special functions + ;; return incorrect values because the x87 precision was set to + ;; single. (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 + (inst or temp-cw (dpb 3 (byte 3 8) 0)) ; Set precision control bits (move fpu-cw temp-cw) (inst fldcw fpu-cw) ; New CW ) ===================================== tests/irrat.lisp ===================================== @@ -245,3 +245,18 @@ (tanh #c(200w0 200w0)))) +(define-test cos-tiny + (:tag issues) + ;; This test comes from the Maxima testsuite where core-math was not + ;; computing cos(8.881784197001252d-16) correctly. It should be + ;; exactly 1. We were getting one bit less. + (assert-eql 1d0 + (cos (kernel:make-double-float 1020264448 0)))) + +(define-test log.special-value + (:tag issues) + ;; This test comes from the Maxima testsuite where core-math was not + ;; computing log(0.6899991035461426d0) => -0.37106498060016496d0. + ;; The computed result looked it had like a single-precision accuracy. + (assert-eql -0.37106498060016496d0 + (kernel:%log (kernel:make-double-float (+ 1071644672 398457) 0)))) View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/5ff177cb9f69fcd1042dbdfe... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/5ff177cb9f69fcd1042dbdfe... You're receiving this email because of your account on gitlab.common-lisp.net.
participants (1)
-
Raymond Toy (@rtoy)