0.7.12.36:
[sbcl.git] / contrib / sb-rotate-byte / rotate-byte.lisp
1 (in-package "SB-ROTATE-BYTE")
2
3 (defun rotate-byte (count byte integer)
4   #+sb-doc "FIXME: Write a docstring"
5   (rotate-byte count byte integer))
6
7 (defun %rotate-byte (count size pos integer)
8   (let ((count (nth-value 1 (round count size)))
9         (mask (1- (ash 1 size))))
10     (logior (logand integer (lognot (ash mask pos)))
11             (let ((field (logand (ash mask pos) integer)))
12               (logand (ash mask pos)
13                       (if (> count 0)
14                           (logior (ash field count)
15                                   (ash field (- count size)))
16                           (logior (ash field count)
17                                   (ash field (+ count size)))))))))
18
19 (defun %unsigned-32-rotate-byte (count integer)
20   ;; inhibit transforms
21   (declare (notinline %rotate-byte))
22   (%rotate-byte count 32 0 integer))