Partially unrolled version of bits-between that collects the
bits from a 60-bit unsigned
(60bits-0-59 offset x acc) → *
In CCL, 60-bit unsigned numbers are fixnums and, according to the following loops, this is about 3.6x faster than bits-between.
(progn (gc$) ;; 21.540 seconds (time (loop for x fixnum from 1 to 30000000 do (bits-between 0 60 x))) ;; 6.013 seconds (gc$) (time (loop for x fixnum from 1 to 30000000 do (60bits-0-59 0 x nil))))
Function:
(defun 60bits-0-59 (offset x acc) (declare (type unsigned-byte offset) (type (unsigned-byte 60) x)) (let ((__function__ '60bits-0-59)) (declare (ignorable __function__)) (b* ((acc (60bits-0-3 (+ offset 56) (the (unsigned-byte 60) (ash x -56)) acc)) (acc (60bits-0-7 (+ offset 48) (the (unsigned-byte 60) (ash x -48)) acc)) (acc (60bits-0-7 (+ offset 40) (the (unsigned-byte 60) (ash x -40)) acc)) (acc (60bits-0-7 (+ offset 32) (the (unsigned-byte 60) (ash x -32)) acc)) (acc (60bits-0-7 (+ offset 24) (the (unsigned-byte 60) (ash x -24)) acc)) (acc (60bits-0-7 (+ offset 16) (the (unsigned-byte 60) (ash x -16)) acc)) (acc (60bits-0-7 (+ offset 8) (the (unsigned-byte 60) (ash x -8)) acc))) (60bits-0-7 offset x acc))))
Theorem:
(defthm 60bits-0-59-redef (implies (natp offset) (equal (60bits-0-59 offset x acc) (append (add-to-each offset (bits-between 0 60 x)) acc))))