From e38211a12ceccae3b59938fd4815ab9055d6d5b8 Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Tue, 26 Aug 2014 20:33:54 -0700
Subject: [PATCH] Implement a simpler (and faster?) algorithm to convert a
 double to an int.

---
 src/compiler/sparc/float.lisp | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/compiler/sparc/float.lisp b/src/compiler/sparc/float.lisp
index 013f18471..74f279dd3 100644
--- a/src/compiler/sparc/float.lisp
+++ b/src/compiler/sparc/float.lisp
@@ -1252,17 +1252,13 @@
     (inst fdtox r x)
     (inst fxtod r r)))
 
+;; See Listing 2.2: Conversion from FP to int in in "CR-LIBM: A
+;; library of correctly rounded elementary functions in
+;; double-precision".
 #+sun4
 (deftransform %unary-round ((x) (float) (signed-byte 32))
-  '(let* ((trunc (truly-the (signed-byte 32) (%unary-truncate x)))
-	  (extra (- x trunc))
-	  (absx (abs extra))
-	  (one-half (float 1/2 x)))
-     (if (if (oddp trunc)
-	     (>= absx one-half)
-	     (> absx one-half))
-	 (truly-the (signed-byte 32) (%unary-truncate (+ x extra)))
-	 trunc)))
+   '(kernel:double-float-low-bits (+ x (+ (scale-float 1d0 52)
+					  (scale-float 1d0 51)))))
 
 (define-vop (make-single-float)
   (:args (bits :scs (signed-reg) :target res
-- 
GitLab