X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-rotate-byte%2Frotate-byte-tests.lisp;h=11f9b63d0037779b45baf58dc8a5724cc0d5ef65;hb=82f9c527cb607ccd19e5b24261dfe9af7b1ba72e;hp=bf463ad399177d8b1d4915681f6f1ce06cf50214;hpb=cec71f1e4e1ead387f2ea642f760e553b6053f2b;p=sbcl.git diff --git a/contrib/sb-rotate-byte/rotate-byte-tests.lisp b/contrib/sb-rotate-byte/rotate-byte-tests.lisp index bf463ad..11f9b63 100644 --- a/contrib/sb-rotate-byte/rotate-byte-tests.lisp +++ b/contrib/sb-rotate-byte/rotate-byte-tests.lisp @@ -1,5 +1,8 @@ (in-package "SB-ROTATE-BYTE") +;;; Ensure we don't bug out with an identity rotation. +(assert (= (rotate-byte 0 (byte 32 0) 3) 3)) + (assert (= (rotate-byte 3 (byte 32 0) 3) 24)) (assert (= (rotate-byte 3 (byte 16 0) 3) 24)) (assert (= (rotate-byte 3 (byte 2 0) 3) 3)) @@ -25,7 +28,7 @@ (defun pfixnum (count integer) (declare (type (unsigned-byte 29) integer) - (type (integer -31 31) count)) + (type (integer -31 31) count)) (rotate-byte count (byte 32 0) integer)) (assert (= (pfixnum 5 5) 160)) @@ -44,10 +47,43 @@ (defun ub32 (count integer) (declare (type (unsigned-byte 32) integer) - (type (integer -31 31) count)) + (type (integer -31 31) count)) (rotate-byte count (byte 32 0) integer)) (assert (= (ub32 5 5) 160)) (assert (= (ub32 5 1) 32)) (assert (= (ub32 5 (ash 1 26)) (ash 1 31))) (assert (= (ub32 5 (ash 1 27)) 1)) + +;;; test with (contrived) register pressure on the x86 to ensure that the +;;; rotatee doesn't get clobbered by the count. + +(defun ub32-reg-pressure (count integer) + (declare (type (unsigned-byte 32) integer) + (type (integer -31 31) count)) + (rotate-byte count (byte 32 0) (ldb (byte 32 0) (+ (* 67 count) + integer)))) + +(assert (= (ub32-reg-pressure 1 5) 144)) +(assert (= (ub32-reg-pressure 5 5) 10880)) +(assert (= (ub32-reg-pressure 5 (ash 1 26)) 2147494368)) +(assert (= (ub32-reg-pressure 5 (ash 1 27)) 10721)) + +(defun ub64/c (integer) + (declare (type (unsigned-byte 64) integer)) + (rotate-byte 6 (byte 64 0) integer)) + +(assert (= (ub64/c 5) 320)) +(assert (= (ub64/c 1) 64)) +(assert (= (ub64/c (ash 1 57)) (ash 1 63))) +(assert (= (ub64/c (ash 1 58)) 1)) + +(defun ub64 (count integer) + (declare (type (unsigned-byte 64) integer) + (type (integer -63 63) count)) + (rotate-byte count (byte 64 0) integer)) + +(assert (= (ub64 6 5) 320)) +(assert (= (ub64 6 1) 64)) +(assert (= (ub64 6 (ash 1 57)) (ash 1 63))) +(assert (= (ub64 6 (ash 1 58)) 1))