1 ;;;; bit-vector hacking utilities, potentially implementation-dependent
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
16 (declaim (inline clear-bit-vector set-bit-vector bit-vector-replace
19 ;;; Clear a SIMPLE-BIT-VECTOR to zeros.
20 (defun clear-bit-vector (vec)
21 (declare (type simple-bit-vector vec))
24 ;;; The old (pre-1999) code had a more-efficient-looking, but also
25 ;;; less-portable implementation of CLEAR-BIT-VECTOR:
26 ;;; (do ((i sb!vm:vector-data-offset (1+ i))
27 ;;; (end (+ sb!vm:vector-data-offset
28 ;;; (ash (+ (length vec) (1- sb!vm:word-bits))
29 ;;; (- (1- (integer-length sb!vm:word-bits)))))))
31 ;;; (setf (sb!kernel:%raw-bits vec i) 0)))
32 ;;; We could use this in the target SBCL if the new version turns out to be a
33 ;;; bottleneck. I (WHN 19990321) will stick to the portable version for now.
34 ;;; And by the way, if we do revisit this file with efficiency on our mind, it
35 ;;; might be good to check whether it's really that helpful to implement
36 ;;; all these functions as INLINE. (How expensive can it be to call a
37 ;;; 1-argument function? How expensive is it to fill up our cache with
38 ;;; a bunch of redundant loop expansions?)
40 ;;; FIXME: Perhaps do simple benchmarks against CMU CL to check this.
42 ;;; Fill a bit vector with ones.
43 (defun set-bit-vector (vec)
44 (declare (type simple-bit-vector vec))
47 ;;; Replace the bits in To with the bits in From.
48 (defun bit-vector-replace (to from)
49 (declare (type simple-bit-vector to from))
50 (bit-ior from from to))
52 ;;; Copy a bit-vector.
53 (defun bit-vector-copy (vec)
54 (declare (type simple-bit-vector vec))
55 (bit-ior vec vec (make-array (length vec) :element-type 'bit)))