On 2012-01-16 06:49:50 +0000, Frode V. Fjeld said:
> There are I believe two options wrt. avoiding the consing of
> double-floats: Don't use double-floats, or try to restructure and add
> type-declarations to your program such that the compiler can manage to
> handle the double-floats without consing them. This latter option is
> somewhat implementation-specific and most likely difficult.
FWIW, I use a set of double float macros that can convince some
implementations not to box double floats and declares references to
float arrays as (simple-array yada-float (*)) . I have them for single
floats as well, but they're less necessary in 64-bit implementations
these are often immediate anyway.
If the OP rewrites his code to use df+, df*, dfaref, etc. he may find
that it conses less.
------------ begin aref-macros.lisp ------------------------
(eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro define-df-macro (function-name)
`(let* ((fsym ',function-name))
(defmacro ,(intern (string-upcase
(concatenate 'string "df"
(symbol-name function-name))))
(arg1 arg2)
`(the double-float (,fsym (the double-float ,arg1)
(the double-float ,arg2)))))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro define-df-boolean-macro (function-name)
`(let* ((fsym ',function-name))
(defmacro ,(intern (string-upcase
(concatenate 'string "df"
(symbol-name function-name))))
(arg1 arg2)
`(the boolean (,fsym (the double-float ,arg1)
(the double-float ,arg2)))))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro define-df-macros (&rest names)
`(progn
,@(mapcar (lambda (name) `(define-df-macro ,name))
names)))
(defmacro define-df-boolean-macros (&rest names)
`(progn
,@(mapcar (lambda (name) `(define-df-boolean-macro ,name))
names))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(define-df-macros + - * / max min)
(define-df-boolean-macros < <= > >= =)
(defmacro dfaref (array index)
`(the double-float (aref (the (simple-array double-float (*)) ,array)
(the fixnum ,index))))
(defmacro dfif (condition true-branch false-branch)
`(the double-float (if ,condition (the double-float ,true-branch)
(the double-float ,false-branch))))
(defmacro dfsetf (place new-value)
`(the double-float (setf (the double-float ,place)
(the double-float ,new-value)))))
(provide 'df-macros)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro define-sf-macro (function-name)
`(let* ((fsym ',function-name))
(defmacro ,(intern (string-upcase
(concatenate 'string "sf"
(symbol-name function-name))))
(arg1 arg2)
`(the single-float (,fsym (the single-float ,arg1)
(the single-float ,arg2)))))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro define-sf-boolean-macro (function-name)
`(let* ((fsym ',function-name))
(defmacro ,(intern (string-upcase
(concatenate 'string "sf"
(symbol-name function-name))))
(arg1 arg2)
`(the boolean (,fsym (the single-float ,arg1)
(the single-float ,arg2)))))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro define-sf-macros (&rest names)
`(progn
,@(mapcar (lambda (name) `(define-sf-macro ,name))
names)))
(defmacro define-sf-boolean-macros (&rest names)
`(progn
,@(mapcar (lambda (name) `(define-sf-boolean-macro ,name))
names))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(define-sf-macros + - * / max min)
(define-sf-boolean-macros < <= > >= =)
(defmacro sfaref (array index)
`(the single-float (aref (the (simple-array single-float (*)) ,array)
(the fixnum ,index))))
(defmacro sfif (condition true-branch false-branch)
`(the single-float (if ,condition (the single-float ,true-branch)
(the single-float ,false-branch))))
(defmacro sfsetf (place new-value)
`(the single-float (setf (the single-float ,place)
(the single-float ,new-value)))))
(provide 'sf-macros)
(defmacro fxaref (array index)
`(the fixnum (aref (the (simple-array fixnum (*)) ,array)
(the fixnum ,index))))
(defmacro fxsetf (place new-value)
`(the fixnum (setf (the fixnum ,place)
(the fixnum ,new-value))))
(provide 'fx-macros)
(provide 'aref-macros)
----------- end aref-macros.lisp -------------------------
--
Raffael Cavallaro