1.0.28.5: delete MERGE-BITS
[sbcl.git] / src / compiler / ppc / arith.lisp
index 5a20c34..4cbfbb0 100644 (file)
 
 (define-vop (fast-lognot/fixnum fixnum-unop)
   (:translate lognot)
-  (:generator 2
-    (inst xori res x (fixnumize -1))))
+  (:generator 1
+    (inst subfic res x (fixnumize -1))))
 
 (define-vop (fast-lognot/signed signed-unop)
   (:translate lognot)
-  (:generator 1
+  (:generator 2
     (inst not res x)))
 \f
 ;;;; Binary fixnum operations.
       (emit-label done))))
 
 \f
+;;;; %LDB
+
+(defknown %%ldb (integer unsigned-byte unsigned-byte) unsigned-byte
+  (movable foldable flushable always-translatable))
+
+;;; only for constant folding within the compiler
+(defun %%ldb (integer size posn)
+  (sb!kernel::%ldb size posn integer))
+
+(define-vop (ldb-c/fixnum)
+  (:translate %%ldb)
+  (:args (x :scs (any-reg)))
+  (:arg-types tagged-num (:constant (integer 1 29)) (:constant (integer 0 29)))
+  (:info size posn)
+  (:results (res :scs (any-reg)))
+  (:result-types tagged-num)
+  (:policy :fast-safe)
+  (:generator 2
+    (inst rlwinm res x
+          (mod (- 32 posn) 32)          ; effectively rotate right
+          (- 32 size n-fixnum-tag-bits)
+          (- 31 n-fixnum-tag-bits))))
+
+(define-vop (ldb-c/signed)
+  (:translate %%ldb)
+  (:args (x :scs (signed-reg)))
+  (:arg-types signed-num (:constant (integer 1 29)) (:constant (integer 0 29)))
+  (:info size posn)
+  (:results (res :scs (any-reg)))
+  (:result-types tagged-num)
+  (:policy :fast-safe)
+  (:generator 3
+    (inst rlwinm res x
+          (mod (- (+ 32 n-fixnum-tag-bits) posn) 32)
+          (- 32 size n-fixnum-tag-bits)
+          (- 31 n-fixnum-tag-bits))))
+
+(define-vop (ldb-c/unsigned)
+  (:translate %%ldb)
+  (:args (x :scs (unsigned-reg)))
+  (:arg-types unsigned-num (:constant (integer 1 29)) (:constant (integer 0 29)))
+  (:info size posn)
+  (:results (res :scs (any-reg)))
+  (:result-types tagged-num)
+  (:policy :fast-safe)
+  (:generator 3
+    (inst rlwinm res x
+          (mod (- (+ 32 n-fixnum-tag-bits) posn) 32)
+          (- 32 size n-fixnum-tag-bits)
+          (- 31 n-fixnum-tag-bits))))
+
+\f
 ;;;; Modular functions:
-(define-modular-fun lognot-mod32 (x) lognot :unsigned 32)
+(define-modular-fun lognot-mod32 (x) lognot :untagged nil 32)
 (define-vop (lognot-mod32/unsigned=>unsigned)
   (:translate lognot-mod32)
   (:args (x :scs (unsigned-reg)))
              (vop (symbolicate 'fast- fun '/unsigned=>unsigned))
              (cvop (symbolicate 'fast- fun '-c/unsigned=>unsigned)))
          `(progn
-            (define-modular-fun ,mfun-name (x y) ,fun :unsigned 32)
+            (define-modular-fun ,mfun-name (x y) ,fun :untagged nil 32)
             (define-vop (,modvop ,vop)
               (:translate ,mfun-name))
             ,@(when constantp
   (define-modular-backend + t)
   (define-modular-backend - t)
   (define-modular-backend * t)
-  (define-modular-backend logxor t)
   (define-modular-backend logeqv)
   (define-modular-backend lognand)
   (define-modular-backend lognor)
   (:arg-types unsigned-num (:constant (unsigned-byte 16)))
   (:info target not-p y))
 
+(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)))
+
 (define-vop (fast-if-</fixnum fast-conditional/fixnum)
   (:translate <)
   (:generator 4
 \f
 ;;;; 32-bit logical operations
 
-(define-vop (merge-bits)
-  (:translate merge-bits)
-  (:args (shift :scs (signed-reg unsigned-reg))
-         (prev :scs (unsigned-reg))
-         (next :scs (unsigned-reg)))
-  (:arg-types tagged-num unsigned-num unsigned-num)
-  (:temporary (:scs (unsigned-reg) :to (:result 0)) temp)
-  (:temporary (:scs (unsigned-reg) :to (:result 0) :target result) res)
-  (:results (result :scs (unsigned-reg)))
-  (:result-types unsigned-num)
-  (:policy :fast-safe)
-  (:generator 4
-    (let ((done (gen-label)))
-      (inst cmpwi shift 0)
-      (inst beq done)
-      (inst srw res next shift)
-      (inst sub temp zero-tn shift)
-      (inst slw temp prev temp)
-      (inst or res res temp)
-      (emit-label done)
-      (move result res))))
-
 (define-vop (shift-towards-someplace)
   (:policy :fast-safe)
   (:args (num :scs (unsigned-reg))