From b0920fabd2b526be40d4b129812bbed2ae022cd5 Mon Sep 17 00:00:00 2001 From: Paul Khuong Date: Fri, 21 Oct 2011 21:02:17 -0400 Subject: [PATCH] Fix another assumption w.r.t fixnum width and n-lowtag-bits This time in LOGBITP. Reported by Eric Marsden on sbcl-devel. --- src/code/numbers.lisp | 6 +++--- tests/arith.pure.lisp | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/code/numbers.lisp b/src/code/numbers.lisp index b6ba6a2..7bb61f9 100644 --- a/src/code/numbers.lisp +++ b/src/code/numbers.lisp @@ -1085,9 +1085,9 @@ the first." #!+sb-doc "Predicate returns T if bit index of integer is a 1." (number-dispatch ((index integer) (integer integer)) - ((fixnum fixnum) (if (> index #.(- sb!vm:n-word-bits sb!vm:n-lowtag-bits)) - (minusp integer) - (not (zerop (logand integer (ash 1 index)))))) + ((fixnum fixnum) (if (< index sb!vm:n-positive-fixnum-bits) + (not (zerop (logand integer (ash 1 index)))) + (minusp integer))) ((fixnum bignum) (bignum-logbitp index integer)) ((bignum (foreach fixnum bignum)) (minusp integer)))) diff --git a/tests/arith.pure.lisp b/tests/arith.pure.lisp index de2d600..9f04fcf 100644 --- a/tests/arith.pure.lisp +++ b/tests/arith.pure.lisp @@ -469,3 +469,9 @@ (error "bad results for ~s with dividend type ~s" (list fun dividend divisor) dividend-type)))))))))))) + +;; The fast path for logbitp underestimated sb!vm:n-positive-fixnum-bits +;; for > 61 bit fixnums. +(with-test (:name :logbitp-wide-fixnum) + (assert (not (logbitp (1- (integer-length most-positive-fixnum)) + most-negative-fixnum)))) -- 1.7.10.4