X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-rotate-byte%2Frotate-byte.lisp;h=2861359f029ab4afce3d70e56c63f0d4720f1e55;hb=7f4bf063d5f4716b87d34cc706f05b27ad3906b1;hp=02342f82ad04ec27f380c5cf38d462e08c9f8e17;hpb=cec71f1e4e1ead387f2ea642f760e553b6053f2b;p=sbcl.git diff --git a/contrib/sb-rotate-byte/rotate-byte.lisp b/contrib/sb-rotate-byte/rotate-byte.lisp index 02342f8..2861359 100644 --- a/contrib/sb-rotate-byte/rotate-byte.lisp +++ b/contrib/sb-rotate-byte/rotate-byte.lisp @@ -1,20 +1,23 @@ (in-package "SB-ROTATE-BYTE") -(defun rotate-byte (count byte integer) - #+sb-doc "FIXME: Write a docstring" - (rotate-byte count byte integer)) +(defun rotate-byte (count bytespec integer) + "Rotates a field of bits within INTEGER; specifically, returns an +integer that contains the bits of INTEGER rotated COUNT times +leftwards within the byte specified by BYTESPEC, and elsewhere +contains the bits of INTEGER." + (rotate-byte count bytespec integer)) (defun %rotate-byte (count size pos integer) (let ((count (nth-value 1 (round count size))) - (mask (1- (ash 1 size)))) + (mask (1- (ash 1 size)))) (logior (logand integer (lognot (ash mask pos))) - (let ((field (logand (ash mask pos) integer))) - (logand (ash mask pos) - (if (> count 0) - (logior (ash field count) - (ash field (- count size))) - (logior (ash field count) - (ash field (+ count size))))))))) + (let ((field (logand (ash mask pos) integer))) + (logand (ash mask pos) + (if (> count 0) + (logior (ash field count) + (ash field (- count size))) + (logior (ash field count) + (ash field (+ count size))))))))) (defun %unsigned-32-rotate-byte (count integer) ;; inhibit transforms