I've looked into all rounding / truncating / flooring functions that I know, but all of them return multiple values, and, as an artefact, even if the second value isn't used, they create and immediately dispose of new conses. This later causes GC to kick in and can slow down the execution at random spots at seemingly random fashion.
So, is there a way to avoid doing (floor x y) w/o consing extra memory? Even if there's an SBCL-specific way, that's good too.
Code: Select all
(defun next-power-two-log (x)
(declare (optimize (debug 0) (safety 0) (space 0) (speed 3)))
(declare (type fixnum x))
(ash 1 (1+ (the signed-byte (floor (the single-float (log x 2)))))))
Here's an example of what I was trying to do, but it doesn't work because the type hint of signed-byte is ignored. But this is only to illustrate that even with speed 3, the second (and obviously redundant) value from floor is created and discarded.