1 (in-package "SB-ROTATE-BYTE")
3 ;;; Ensure we don't bug out with an identity rotation.
4 (assert (= (rotate-byte 0 (byte 32 0) 3) 3))
6 (assert (= (rotate-byte 3 (byte 32 0) 3) 24))
7 (assert (= (rotate-byte 3 (byte 16 0) 3) 24))
8 (assert (= (rotate-byte 3 (byte 2 0) 3) 3))
9 (assert (= (rotate-byte 3 (byte 5 5) 3) 3))
10 (assert (= (rotate-byte 6 (byte 8 0) -
3) -
129))
12 (flet ((opaque-identity (x) x
))
13 (declare (notinline opaque-identity
))
14 (assert (= (rotate-byte 3 (opaque-identity (byte 32 0)) 3) 24))
15 (assert (= (rotate-byte 3 (opaque-identity (byte 16 0)) 3) 24))
16 (assert (= (rotate-byte 3 (opaque-identity (byte 2 0)) 3) 3))
17 (assert (= (rotate-byte 3 (opaque-identity (byte 5 5)) 3) 3))
18 (assert (= (rotate-byte 6 (opaque-identity (byte 8 0)) -
3) -
129)))
20 (defun pfixnum/c
(integer)
21 (declare (type (unsigned-byte 29) integer
))
22 (rotate-byte 5 (byte 32 0) integer
))
24 (assert (= (pfixnum/c
5) 160))
25 (assert (= (pfixnum/c
1) 32))
26 (assert (= (pfixnum/c
(ash 1 26)) (ash 1 31)))
27 (assert (= (pfixnum/c
(ash 1 27)) 1))
29 (defun pfixnum (count integer
)
30 (declare (type (unsigned-byte 29) integer
)
31 (type (integer -
31 31) count
))
32 (rotate-byte count
(byte 32 0) integer
))
34 (assert (= (pfixnum 5 5) 160))
35 (assert (= (pfixnum 5 1) 32))
36 (assert (= (pfixnum 5 (ash 1 26)) (ash 1 31)))
37 (assert (= (pfixnum 5 (ash 1 27)) 1))
39 (defun ub32/c
(integer)
40 (declare (type (unsigned-byte 32) integer
))
41 (rotate-byte 5 (byte 32 0) integer
))
43 (assert (= (ub32/c
5) 160))
44 (assert (= (ub32/c
1) 32))
45 (assert (= (ub32/c
(ash 1 26)) (ash 1 31)))
46 (assert (= (ub32/c
(ash 1 27)) 1))
48 (defun ub32/-c
(integer)
49 (declare (type (unsigned-byte 32) integer
))
50 (rotate-byte -
5 (byte 32 0) integer
))
52 (assert (= (ub32/-c
320) 10))
53 (assert (= (ub32/-c
64) 2))
54 (assert (= (ub32/-c
(ash 1 31)) (ash 1 26)))
55 (assert (= (ub32/-c
1) (ash 1 27)))
57 (defun ub32 (count integer
)
58 (declare (type (unsigned-byte 32) integer
)
59 (type (integer -
31 31) count
))
60 (rotate-byte count
(byte 32 0) integer
))
62 (assert (= (ub32 5 5) 160))
63 (assert (= (ub32 5 1) 32))
64 (assert (= (ub32 5 (ash 1 26)) (ash 1 31)))
65 (assert (= (ub32 5 (ash 1 27)) 1))
67 ;;; test with (contrived) register pressure on the x86 to ensure that the
68 ;;; rotatee doesn't get clobbered by the count.
70 (defun ub32-reg-pressure (count integer
)
71 (declare (type (unsigned-byte 32) integer
)
72 (type (integer -
31 31) count
))
73 (rotate-byte count
(byte 32 0) (ldb (byte 32 0) (+ (* 67 count
)
76 (assert (= (ub32-reg-pressure 1 5) 144))
77 (assert (= (ub32-reg-pressure 5 5) 10880))
78 (assert (= (ub32-reg-pressure 5 (ash 1 26)) 2147494368))
79 (assert (= (ub32-reg-pressure 5 (ash 1 27)) 10721))
81 (defun ub64/c
(integer)
82 (declare (type (unsigned-byte 64) integer
))
83 (rotate-byte 6 (byte 64 0) integer
))
85 (defun ub64/-c
(integer)
86 (declare (type (unsigned-byte 64) integer
))
87 (rotate-byte -
6 (byte 64 0) integer
))
89 (assert (= (ub64/-c
320) 5))
90 (assert (= (ub64/-c
64) 1))
91 (assert (= (ub64/-c
(ash 1 63)) (ash 1 57)))
92 (assert (= (ub64/-c
1) (ash 1 58)))
94 (defun ub64 (count integer
)
95 (declare (type (unsigned-byte 64) integer
)
96 (type (integer -
63 63) count
))
97 (rotate-byte count
(byte 64 0) integer
))
99 (assert (= (ub64 6 5) 320))
100 (assert (= (ub64 6 1) 64))
101 (assert (= (ub64 6 (ash 1 57)) (ash 1 63)))
102 (assert (= (ub64 6 (ash 1 58)) 1))