Skip to content

Commit

Permalink
quaviver: use alexandria:with-gensyms
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzchak committed Jul 17, 2024
1 parent 09265c9 commit 9ef39fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
27 changes: 16 additions & 11 deletions code/bits-float-form.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
#+abcl
`(system:make-single-float ,value)
#+allegro
(let ((v (gensym)))
(alexandria:with-gensyms
(v)
`(let ((,v ,value))
(excl:shorts-to-single-float (ldb (byte 16 16) ,v)
(ldb (byte 16 0) ,v))))
Expand All @@ -47,7 +48,8 @@
#+ecl
`(system:bits-single-float ,value)
#+lispworks
(let ((m (gensym)))
(alexandria:with-gensyms
(m)
`(let ((,m (sys:make-typed-aref-vector 4)))
(declare (optimize (speed 3) (float 0) (safety 0))
(dynamic-extent ,m))
Expand All @@ -62,14 +64,16 @@
#+abcl
`(system:make-double-float ,value)
#+allegro
(let ((v (gensym)))
(alexandria:with-gensyms
(v)
`(let ((,v ,value))
(excl:shorts-to-double-float (ldb (byte 16 48) ,v)
(ldb (byte 16 32) ,v)
(ldb (byte 16 16) ,v)
(ldb (byte 16 0) ,v))))
#+ccl
(let ((v (gensym)))
(alexandria:with-gensyms
(v)
`(let ((,v ,value))
(ccl::double-float-from-bits (ldb (byte 32 32) ,v)
(ldb (byte 32 0) ,v))))
Expand All @@ -81,15 +85,16 @@
(setf (ffi:slot (ffi:foreign-value u) 'bits) ,value)
(ffi:slot (ffi:foreign-value u) 'value))
#+cmucl
(let ((v (gensym)))
(alexandria:with-gensyms
(v)
`(let ((,v ,value))
(kernel:make-double-float (ub32-sb32 (ldb (byte 32 32) ,v))
(ldb (byte 32 0) ,v))))
#+ecl
`(system:bits-double-float ,value)
#+lispworks
(let ((m (gensym))
(v (gensym)))
(alexandria:with-gensyms
(m v)
`(let ((,m (sys:make-typed-aref-vector 8))
(,v ,value))
(declare (optimize (speed 3) (float 0) (safety 0))
Expand All @@ -104,7 +109,8 @@
#+mezzano
`(mezzano.extensions:ieee-binary64-to-double-float ,value)
#+sbcl
(let ((v (gensym)))
(alexandria:with-gensyms
(v)
`(let ((,v ,value))
(sb-kernel:make-double-float (ub32-sb32 (ldb (byte 32 32) ,v))
(ldb (byte 32 0) ,v)))))
Expand All @@ -119,9 +125,8 @@
#-quaviver/long-float-fallback
`(system:bits-long-float ,value)
#+quaviver/long-float-fallback
(let ((m (gensym))
(n (gensym))
(v (gensym)))
(alexandria:with-gensyms
(m n v)
`(let ((,v ,value))
(ffi:with-foreign-object (,m 'long-float/uint128)
(let ((,n (ffi:get-slot-value ,m 'long-float/uint128 'u)))
Expand Down
33 changes: 18 additions & 15 deletions code/float-bits-form.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#+abcl
`(system:single-float-bits ,value)
#+allegro
(let ((us1 (gensym))
(us0 (gensym)))
(alexandria:with-gensyms
(us1 us0)
`(multiple-value-bind (,us1 ,us0)
(excl:single-float-to-shorts ,value)
(logior (ash ,us1 16) ,us0)))
Expand All @@ -33,7 +33,8 @@
#+ecl
`(system:single-float-bits ,value)
#+lispworks
(let ((m (gensym)))
(alexandria:with-gensyms
(m)
`(let ((,m (sys:make-typed-aref-vector 4)))
(declare (optimize (speed 3) (float 0) (safety 0))
(dynamic-extent ,m))
Expand All @@ -46,21 +47,20 @@

(defmethod float-bits-form ((float-type (eql 'double-float)) value)
#+abcl
(let ((v (gensym)))
(alexandria:with-gensyms
(v)
`(let ((,v ,value))
(logior (ash (system:double-float-high-bits ,v) 32)
(system:double-float-low-bits ,v))))
#+allegro
(let ((us3 (gensym))
(us2 (gensym))
(us1 (gensym))
(us0 (gensym)))
(alexandria:with-gensyms
(us3 us2 us1 us0)
`(multiple-value-bind (,us3 ,us2 ,us1 ,us0)
(excl:double-float-to-shorts ,value)
(logior (ash ,us3 48) (ash ,us2 32) (ash ,us1 16) ,us0)))
#+ccl
(let ((upper (gensym))
(lower (gensym)))
(alexandria:with-gensyms
(upper lower)
`(multiple-value-bind (,upper ,lower)
(ccl::double-float-bits ,value)
(logior (ash ,upper 32) ,lower)))
Expand All @@ -72,14 +72,16 @@
(setf (ffi:slot (ffi:foreign-value u) 'value) ,value)
(ffi:slot (ffi:foreign-value u) 'bits))
#+cmucl
(let ((v (gensym)))
(alexandria:with-gensyms
(v)
`(let ((,v ,value))
(logior (ash (ldb (byte 32 0) (kernel:double-float-high-bits ,v)) 32)
(kernel:double-float-low-bits ,v))))
#+ecl
`(system:double-float-bits ,value)
#+lispworks
(let ((m (gensym)))
(alexandria:with-gensyms
(m)
`(let ((,m (sys:make-typed-aref-vector 8)))
(declare (optimize (speed 3) (float 0) (safety 0))
(dynamic-extent ,m))
Expand All @@ -93,7 +95,8 @@
#+mezzano
`(mezzano.extensions:double-float-to-ieee-binary64 ,value)
#+sbcl
(let ((v (gensym)))
(alexandria:with-gensyms
(v)
`(let ((,v ,value))
(logior (ash (ldb (byte 32 0) (sb-kernel:double-float-high-bits ,v)) 32)
(sb-kernel:double-float-low-bits ,v)))))
Expand All @@ -103,8 +106,8 @@
#-quaviver/long-float-fallback
`(system:long-float-bits ,value)
#+quaviver/long-float-fallback
(let ((m (gensym))
(n (gensym)))
(alexandria:with-gensyms
(m n)
`(ffi:with-foreign-object (,m 'long-float/uint128)
(setf (ffi:get-slot-value ,m 'long-float/uint128 'f) ,value)
(let ((,n (ffi:get-slot-value ,m 'long-float/uint128 'u)))
Expand Down
6 changes: 2 additions & 4 deletions code/internal-integer-float-form.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
(max-exponent max-exponent)
(significand-size significand-size))
float-type
(let ((exponent-var (gensym))
(significand-var (gensym))
(sign-var (gensym))
(bits-var (gensym)))
(alexandria:with-gensyms
(exponent-var significand-var sign-var bits-var)
`(let ((,bits-var 0)
(,exponent-var ,exponent)
(,significand-var ,significand)
Expand Down

0 comments on commit 9ef39fa

Please sign in to comment.