+(macrolet ((define-logtest-vops ()
+ `(progn
+ ,@(loop for suffix in '(/fixnum -c/fixnum
+ /signed -c/signed
+ /unsigned -c/unsigned)
+ for sc in '(any-reg any-reg
+ signed-reg signed-reg
+ unsigned-reg unsigned-reg)
+ for cost in '(4 3 6 5 6 5)
+ collect
+ `(define-vop (,(symbolicate "FAST-LOGTEST" suffix)
+ ,(symbolicate "FAST-CONDITIONAL" suffix))
+ (:translate logtest)
+ (:temporary (:scs (,sc) :to (:result 0)) test)
+ (:generator ,cost
+ ;; We could be a lot more sophisticated here and
+ ;; check for possibilities with ANDIS..
+ ,(if (string= "-C" suffix :end2 2)
+ `(inst andi. test x ,(if (eq suffix '-c/fixnum)
+ '(fixnumize y)
+ 'y))
+ `(inst and. test x y))
+ (inst b? (if not-p :eq :ne) target)))))))
+ (define-logtest-vops))
+
+(defknown %logbitp (integer unsigned-byte) boolean
+ (movable foldable flushable always-translatable))
+
+;;; only for constant folding within the compiler
+(defun %logbitp (integer index)
+ (logbitp index integer))
+
+;;; We only handle the constant cases because those are the only ones
+;;; guaranteed to make it past COMBINATION-IMPLEMENTATION-STYLE.
+;;; --njf, 06-02-2006
+(define-vop (fast-logbitp-c/fixnum fast-conditional-c/fixnum)
+ (:translate %logbitp)
+ (:arg-types tagged-num (:constant (integer 0 29)))
+ (:temporary (:scs (any-reg) :to (:result 0)) test)
+ (:generator 4
+ (if (< y 14)
+ (inst andi. test x (ash 1 (+ y n-fixnum-tag-bits)))
+ (inst andis. test x (ash 1 (- y 14))))
+ (inst b? (if not-p :eq :ne) target)))
+
+(define-vop (fast-logbitp-c/signed fast-conditional-c/signed)
+ (:translate %logbitp)
+ (:arg-types signed-num (:constant (integer 0 31)))
+ (:temporary (:scs (signed-reg) :to (:result 0)) test)
+ (:generator 4
+ (if (< y 16)
+ (inst andi. test x (ash 1 y))
+ (inst andis. test x (ash 1 (- y 16))))
+ (inst b? (if not-p :eq :ne) target)))
+
+(define-vop (fast-logbitp-c/unsigned fast-conditional-c/unsigned)
+ (:translate %logbitp)
+ (:arg-types unsigned-num (:constant (integer 0 31)))
+ (:temporary (:scs (unsigned-reg) :to (:result 0)) test)
+ (:generator 4
+ (if (< y 16)
+ (inst andi. test x (ash 1 y))
+ (inst andis. test x (ash 1 (- y 16))))
+ (inst b? (if not-p :eq :ne) target)))