0.8.18.14:
[sbcl.git] / tests / bit-vector.impure-cload.lisp
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
4 ;;;; While most of SBCL is derived from the CMU CL system, the test
5 ;;;; files (like this one) were written from scratch after the fork
6 ;;;; from CMU CL.
7 ;;;; 
8 ;;;; This software is in the public domain and is provided with
9 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
10 ;;;; more information.
11
12 ;;; the bitvector transforms were buggy prior to sbcl-0.7.3.4 under
13 ;;; speed-optimizing regimes; in particular, they would fail if the
14 ;;; vector length were near ARRAY-DIMENSION-LIMIT. Testing this takes
15 ;;; up a certain amount of time...
16
17 (declaim (optimize (speed 3) (safety 1) (space 0) (compilation-speed 0)))
18
19 (defun bit-vector-test ()
20   ;; deal with the potential length 0 special case
21   (let ((a (make-array 0 :element-type 'bit))
22         (b (make-array 0 :element-type 'bit)))
23     (assert (equal (bit-not a) #*))
24     (assert (equal (bit-xor a b a) #*))
25     (assert (equal (bit-and a a b) #*)))
26   ;; also test some return values for sanity
27   (let ((a (make-array 33 :element-type 'bit :initial-element 0))
28         (b (make-array 33 :element-type 'bit :initial-element 0)))
29     (assert (equal (bit-not a a) #*111111111111111111111111111111111))
30     (setf (aref a 0) 0) ; a = #*011..1
31     (setf (aref b 1) 1) ; b = #*010..0
32     (assert (equal (bit-xor a b) #*001111111111111111111111111111111))
33     (assert (equal (bit-and a b) #*010000000000000000000000000000000)))
34   ;; now test the biggy, mostly that it works...
35   #-x86-64 ; except on machines where addressable space is likely to be
36            ; much bigger than physical memory
37   (let ((a (make-array (1- array-dimension-limit) :element-type 'bit :initial-element 0))
38         (b (make-array (1- array-dimension-limit) :element-type 'bit :initial-element 0)))
39     (bit-not a a)
40     (assert (= (aref a 0) 1))
41     (assert (= (aref a (- array-dimension-limit 2)) 1))
42     (bit-and a b a)
43     (assert (= (aref a 0) 0))
44     (assert (= (aref a (- array-dimension-limit 2)) 0)))
45   ;; a special COUNT transform on bitvectors; triggers on (>= SPEED SPACE)
46   (locally
47    (declare (optimize (speed 3) (space 1)))
48    (let ((bv1 (make-array 5 :element-type 'bit))
49          (bv2 (make-array 0 :element-type 'bit))
50          (bv3 (make-array 68 :element-type 'bit)))
51      (declare (type simple-bit-vector bv1 bv2 bv3))
52      (setf (sbit bv3 42) 1)
53      ;; bitvector smaller than the word size
54      (assert (= 0 (count 1 bv1)))
55      (assert (= 5 (count 0 bv1)))
56      ;; special case of 0-length bitvectors
57      (assert (= 0 (count 1 bv2)))
58      (assert (= 0 (count 0 bv2)))
59      ;; bitvector larger than the word size
60      (assert (= 1 (count 1 bv3)))
61      (assert (= 67 (count 0 bv3))))))
62
63 (bit-vector-test)
64 \f
65 ;;; success
66 (sb-ext:quit :unix-status 104)