X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fbit-bash.lisp;h=30c3c5bcd3a9f38a6f71ef3cb80d721b9cf51ec2;hb=d720bc359f03734ccb9baf66cb45dc01d623f369;hp=909db1f656ab10e3f333d8842fdf74cb55d08f36;hpb=41cb424785ec6daf0263acb1a6a8af9d41708990;p=sbcl.git diff --git a/src/code/bit-bash.lisp b/src/code/bit-bash.lisp index 909db1f..30c3c5b 100644 --- a/src/code/bit-bash.lisp +++ b/src/code/bit-bash.lisp @@ -600,8 +600,8 @@ ;;;; ;;;; Similar search would work well for base-strings as well. ;;;; (Technically for all unboxed sequences of sub-word size elements, -;;;; but somehow I doubt other eg. octet vectors get POSIION or FIND -;;;; used as much on them.) +;;;; but somehow I doubt eg. octet vectors get POSITION or FIND used +;;;; as much on them.) (defconstant +bit-position-base-mask+ (1- n-word-bits)) (defconstant +bit-position-base-shift+ (integer-length +bit-position-base-mask+)) (macrolet ((def (name frob) @@ -638,55 +638,52 @@ (logior i (truly-the fixnum (ash word-offset +bit-position-base-shift+))))) - (get-word (sap offset) - (,@frob (sap-ref-word sap (* n-word-bytes offset))))) + (get-word (offset) + (,@frob (%vector-raw-bits vector offset)))) (declare (inline start-bit end-bit get-word)) - (with-pinned-objects (vector) - (if from-end - ;; Back to front - (let* ((sap (vector-sap vector)) - (word-offset last-word) - (word (logand end-mask (get-word sap word-offset)))) - (declare (word word) - (index word-offset)) + (if from-end + ;; Back to front + (let* ((word-offset last-word) + (word (logand end-mask (get-word word-offset)))) + (declare (word word) + (index word-offset)) + (unless (zerop word) + (when (= word-offset first-word) + (setf word (logand word start-mask))) + (unless (zerop word) + (found (end-bit word) word-offset))) + (decf word-offset) + (loop + (when (< word-offset first-word) + (return-from ,name nil)) + (setf word (get-word word-offset)) (unless (zerop word) (when (= word-offset first-word) (setf word (logand word start-mask))) (unless (zerop word) (found (end-bit word) word-offset))) - (decf word-offset) - (loop - (when (< word-offset first-word) - (return-from ,name nil)) - (setf word (get-word sap word-offset)) - (unless (zerop word) - (when (= word-offset first-word) - (setf word (logand word start-mask))) - (unless (zerop word) - (found (end-bit word) word-offset))) - (decf word-offset))) - ;; Front to back - (let* ((sap (vector-sap vector)) - (word-offset first-word) - (word (logand start-mask (get-word sap word-offset)))) - (declare (word word) - (index word-offset)) + (decf word-offset))) + ;; Front to back + (let* ((word-offset first-word) + (word (logand start-mask (get-word word-offset)))) + (declare (word word) + (index word-offset)) + (unless (zerop word) + (when (= word-offset last-word) + (setf word (logand word end-mask))) + (unless (zerop word) + (found (start-bit word) word-offset))) + (incf word-offset) + (loop + (when (> word-offset last-word) + (return-from ,name nil)) + (setf word (get-word word-offset)) (unless (zerop word) (when (= word-offset last-word) (setf word (logand word end-mask))) (unless (zerop word) (found (start-bit word) word-offset))) - (incf word-offset) - (loop - (when (> word-offset last-word) - (return-from ,name nil)) - (setf word (get-word sap word-offset)) - (unless (zerop word) - (when (= word-offset last-word) - (setf word (logand word end-mask))) - (unless (zerop word) - (found (start-bit word) word-offset))) - (incf word-offset))))))))))) + (incf word-offset)))))))))) (def %bit-position/0 (logandc2 #.(1- (expt 2 n-word-bits)))) (def %bit-position/1 (identity))) (defun %bit-position (bit vector from-end start end)