Avoid calling SUBTYPEP in ANSI-STREAM-{READ,WRITE}-SEQUENCE
[sbcl.git] / contrib / sb-rotate-byte / rotate-byte-tests.lisp
blob6e6b7f6059f816ae65885f3259ab0b6408967c87
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 (count integer)
49 (declare (type (unsigned-byte 32) integer)
50 (type (integer -31 31) count))
51 (rotate-byte count (byte 32 0) integer))
53 (assert (= (ub32 5 5) 160))
54 (assert (= (ub32 5 1) 32))
55 (assert (= (ub32 5 (ash 1 26)) (ash 1 31)))
56 (assert (= (ub32 5 (ash 1 27)) 1))
58 ;;; test with (contrived) register pressure on the x86 to ensure that the
59 ;;; rotatee doesn't get clobbered by the count.
61 (defun ub32-reg-pressure (count integer)
62 (declare (type (unsigned-byte 32) integer)
63 (type (integer -31 31) count))
64 (rotate-byte count (byte 32 0) (ldb (byte 32 0) (+ (* 67 count)
65 integer))))
67 (assert (= (ub32-reg-pressure 1 5) 144))
68 (assert (= (ub32-reg-pressure 5 5) 10880))
69 (assert (= (ub32-reg-pressure 5 (ash 1 26)) 2147494368))
70 (assert (= (ub32-reg-pressure 5 (ash 1 27)) 10721))
72 (defun ub64/c (integer)
73 (declare (type (unsigned-byte 64) integer))
74 (rotate-byte 6 (byte 64 0) integer))
76 (defun ub64/-c (integer)
77 (declare (type (unsigned-byte 64) integer))
78 (rotate-byte -6 (byte 64 0) integer))
80 (assert (= (ub64/-c 320) 5))
81 (assert (= (ub64/-c 64) 1))
82 (assert (= (ub64/-c (ash 1 63)) (ash 1 57)))
83 (assert (= (ub64/-c 1) (ash 1 58)))
85 (defun ub64 (count integer)
86 (declare (type (unsigned-byte 64) integer)
87 (type (integer -63 63) count))
88 (rotate-byte count (byte 64 0) integer))
90 (assert (= (ub64 6 5) 320))
91 (assert (= (ub64 6 1) 64))
92 (assert (= (ub64 6 (ash 1 57)) (ash 1 63)))
93 (assert (= (ub64 6 (ash 1 58)) 1))