0.8.13.26:
[sbcl.git] / src / compiler / hppa / arith.lisp
index 1cc39d6..880be1f 100644 (file)
@@ -1,6 +1,15 @@
-(in-package "SB!VM")
+;;;; the VM definition arithmetic VOPs for HPPA
 
+;;;; This software is part of the SBCL system. See the README file for
+;;;; more information.
+;;;;
+;;;; This software is derived from the CMU CL system, which was
+;;;; written at Carnegie Mellon University and released into the
+;;;; public domain. The software is in the public domain and is
+;;;; provided with absolutely no warranty. See the COPYING and CREDITS
+;;;; files for more information.
 
+(in-package "SB!VM")
 \f
 ;;;; Unary operations.
 
@@ -42,8 +51,6 @@
   (:translate lognot)
   (:generator 1
     (inst uaddcm zero-tn x res)))
-
-
 \f
 ;;;; Binary fixnum operations.
 
@@ -82,7 +89,7 @@
   (:affected)
   (:policy :fast-safe))
 
-(defmacro define-binop (translate cost untagged-cost op)
+(defmacro define-binop (translate cost untagged-cost op &optional arg-swap)
   `(progn
      (define-vop (,(symbolicate "FAST-" translate "/FIXNUM=>FIXNUM")
                  fast-fixnum-binop)
              (y :target r :scs (any-reg)))
        (:translate ,translate)
        (:generator ,cost
-        (inst ,op x y r)))
+        ,(if arg-swap
+             `(inst ,op y x r)
+             `(inst ,op x y r))))
      (define-vop (,(symbolicate "FAST-" translate "/SIGNED=>SIGNED")
                  fast-signed-binop)
        (:args (x :target r :scs (signed-reg))
              (y :target r :scs (signed-reg)))
        (:translate ,translate)
        (:generator ,untagged-cost
-        (inst ,op x y r)))
+        ,(if arg-swap
+             `(inst ,op y x r)
+             `(inst ,op x y r))))
      (define-vop (,(symbolicate "FAST-" translate "/UNSIGNED=>UNSIGNED")
                  fast-unsigned-binop)
        (:args (x :target r :scs (unsigned-reg))
              (y :target r :scs (unsigned-reg)))
        (:translate ,translate)
        (:generator ,untagged-cost
-        (inst ,op x y r)))))
+        ,(if arg-swap
+             `(inst ,op y x r)
+             `(inst ,op x y r))))))
 
 (define-binop + 2 6 add)
 (define-binop - 2 6 sub)
 (define-binop logior 1 2 or)
 (define-binop logand 1 2 and)
+(define-binop logandc1 1 2 andcm t)
 (define-binop logandc2 1 2 andcm)
 (define-binop logxor 1 2 xor)
 
   (:variant-cost 6))
   
 \f
-;;;; 32-bit logical operations
-
-(define-vop (32bit-logical)
-  (:args (x :scs (unsigned-reg))
-        (y :scs (unsigned-reg)))
-  (:arg-types unsigned-num unsigned-num)
-  (:results (r :scs (unsigned-reg)))
-  (:result-types unsigned-num)
-  (:policy :fast-safe))
-
-(define-vop (32bit-logical-not 32bit-logical)
-  (:translate 32bit-logical-not)
+;;;; modular functions
+(define-modular-fun +-mod32 (x y) + 32)
+(define-vop (fast-+-mod32/unsigned=>unsigned fast-+/unsigned=>unsigned)
+  (:translate +-mod32))
+(define-vop (fast-+-mod32-c/unsigned=>unsigned fast-+-c/unsigned=>unsigned)
+  (:translate +-mod32))
+(define-modular-fun --mod32 (x y) - 32)
+(define-vop (fast---mod32/unsigned=>unsigned fast--/unsigned=>unsigned)
+  (:translate --mod32))
+(define-vop (fast---mod32-c/unsigned=>unsigned fast---c/unsigned=>unsigned)
+  (:translate --mod32))
+
+(define-vop (fast-ash-left-mod32-c/unsigned=>unsigned
+            fast-ash-c/unsigned=>unsigned)
+  (:translate ash-left-mod32))
+
+(define-modular-fun lognot-mod32 (x) lognot 32)
+(define-vop (lognot-mod32/unsigned=>unsigned)
+  (:translate lognot-mod32)
   (:args (x :scs (unsigned-reg)))
   (:arg-types unsigned-num)
+  (:results (res :scs (unsigned-reg)))
+  (:result-types unsigned-num)
+  (:policy :fast-safe)
   (:generator 1
-    (inst uaddcm zero-tn x r)))
+    (inst uaddcm zero-tn x res)))
 
-(define-vop (32bit-logical-and 32bit-logical)
-  (:translate 32bit-logical-and)
-  (:generator 1
-    (inst and x y r)))
+(macrolet
+    ((define-modular-backend (fun)
+       (let ((mfun-name (symbolicate fun '-mod32))
+            ;; FIXME: if anyone cares, add constant-arg vops.  --
+            ;; CSR, 2003-09-16
+            (modvop (symbolicate 'fast- fun '-mod32/unsigned=>unsigned))
+            (vop (symbolicate 'fast- fun '/unsigned=>unsigned)))
+        `(progn
+           (define-modular-fun ,mfun-name (x y) ,fun 32)
+           (define-vop (,modvop ,vop)
+             (:translate ,mfun-name))))))
+  (define-modular-backend logxor)
+  (define-modular-backend logandc1)
+  (define-modular-backend logandc2))
+
+(define-source-transform logeqv (&rest args)
+  (if (oddp (length args))
+      `(logxor ,@args)
+      `(lognot (logxor ,@args))))
+(define-source-transform logorc1 (x y)
+  `(logior (lognot ,x) ,y))
+(define-source-transform logorc2 (x y)
+  `(logior ,x (lognot ,y)))
+(define-source-transform lognand (x y)
+  `(lognot (logand ,x ,y)))
+(define-source-transform lognor (x y)
+  `(lognot (logior ,x y)))
+   
+;;;; 32-bit logical operations
 
-(deftransform 32bit-logical-nand ((x y) (* *))
-  '(32bit-logical-not (32bit-logical-and x y)))
+(define-source-transform word-logical-not (x)
+  `(logand (lognot (the (unsigned-byte 32) ,x)) #.(1- (ash 1 32))))
 
-(define-vop (32bit-logical-or 32bit-logical)
-  (:translate 32bit-logical-or)
-  (:generator 1
-    (inst or x y r)))
+(deftransform word-logical-and ((x y))
+  '(logand x y))
 
-(deftransform 32bit-logical-nor ((x y) (* *))
-  '(32bit-logical-not (32bit-logical-or x y)))
+(define-source-transform word-logical-nand (x y)
+  `(word-logical-not (word-logical-and ,x ,y)))
 
-(define-vop (32bit-logical-xor 32bit-logical)
-  (:translate 32bit-logical-xor)
-  (:generator 1
-    (inst xor x y r)))
+(deftransform word-logical-or ((x y))
+  '(logior x y))
 
-(deftransform 32bit-logical-eqv ((x y) (* *))
-  '(32bit-logical-not (32bit-logical-xor x y)))
+(define-source-transform word-logical-nor (x y)
+  `(logand (lognor (the (unsigned-byte 32) ,x) (the (unsigned-byte 32) ,y))
+           #.(1- (ash 1 32))))
 
-(deftransform 32bit-logical-andc1 ((x y) (* *))
-  '(32bit-logical-and (32bit-logical-not x) y))
+(deftransform word-logical-xor ((x y))
+  '(logxor x y))
 
-(define-vop (32bit-logical-andc2 32bit-logical)
-  (:translate 32bit-logical-andc2)
-  (:generator 1
-    (inst andcm x y r)))
+(define-source-transform word-logical-eqv (x y)
+  `(word-logical-not (word-logical-xor ,x ,y)))
+
+(define-source-transform word-logical-orc1 (x y)
+  `(word-logical-or (word-logical-not ,x) ,y))
 
-(deftransform 32bit-logical-orc1 ((x y) (* *))
-  '(32bit-logical-or (32bit-logical-not x) y))
+(define-source-transform word-logical-orc2 (x y)
+  `(word-logical-or ,x (word-logical-not ,y)))
 
-(deftransform 32bit-logical-orc2 ((x y) (* *))
-  '(32bit-logical-or x (32bit-logical-not y)))
+(deftransform word-logical-andc1 (x y)
+  '(logandc1 x y))
 
+(deftransform word-logical-andc2 (x y)
+  '(logandc2 x y))
 
 (define-vop (shift-towards-someplace)
   (:policy :fast-safe)
 ;;;; Bignum stuff.
 
 (define-vop (bignum-length get-header-data)
-  (:translate sb!bignum::%bignum-length)
+  (:translate sb!bignum:%bignum-length)
   (:policy :fast-safe))
 
 (define-vop (bignum-set-length set-header-data)
-  (:translate sb!bignum::%bignum-set-length)
+  (:translate sb!bignum:%bignum-set-length)
   (:policy :fast-safe))
 
 (define-full-reffer bignum-ref * bignum-digits-offset other-pointer-lowtag
-  (unsigned-reg) unsigned-num sb!bignum::%bignum-ref)
+  (unsigned-reg) unsigned-num sb!bignum:%bignum-ref)
 
 (define-full-setter bignum-set * bignum-digits-offset other-pointer-lowtag
-  (unsigned-reg) unsigned-num sb!bignum::%bignum-set)
+  (unsigned-reg) unsigned-num sb!bignum:%bignum-set)
 
 (define-vop (digit-0-or-plus)
-  (:translate sb!bignum::%digit-0-or-plusp)
+  (:translate sb!bignum:%digit-0-or-plusp)
   (:policy :fast-safe)
   (:args (digit :scs (unsigned-reg)))
   (:arg-types unsigned-num)
     (inst bc :>= not-p digit zero-tn target)))
 
 (define-vop (add-w/carry)
-  (:translate sb!bignum::%add-with-carry)
+  (:translate sb!bignum:%add-with-carry)
   (:policy :fast-safe)
   (:args (a :scs (unsigned-reg))
         (b :scs (unsigned-reg))
     (inst addc zero-tn zero-tn carry)))
 
 (define-vop (sub-w/borrow)
-  (:translate sb!bignum::%subtract-with-borrow)
+  (:translate sb!bignum:%subtract-with-borrow)
   (:policy :fast-safe)
   (:args (a :scs (unsigned-reg))
         (b :scs (unsigned-reg))
     (inst addc zero-tn zero-tn borrow)))
 
 (define-vop (bignum-mult)
-  (:translate sb!bignum::%multiply)
+  (:translate sb!bignum:%multiply)
   (:policy :fast-safe)
   (:args (x-arg :scs (unsigned-reg) :target x)
         (y-arg :scs (unsigned-reg) :target y))
 (define-source-transform sb!bignum:%multiply-and-add (x y carry &optional (extra 0))
   #+nil ;; This would be greate if it worked, but it doesn't.
   (if (eql extra 0)
-      `(multiple-value-call #'sb!bignum::%dual-word-add
+      `(multiple-value-call #'sb!bignum:%dual-word-add
         (sb!bignum:%multiply ,x ,y)
         (values ,carry))
-      `(multiple-value-call #'sb!bignum::%dual-word-add
-        (multiple-value-call #'sb!bignum::%dual-word-add
+      `(multiple-value-call #'sb!bignum:%dual-word-add
+        (multiple-value-call #'sb!bignum:%dual-word-add
           (sb!bignum:%multiply ,x ,y)
           (values ,carry))
         (values ,extra)))
-  (let ((hi (gensym "HI-"))
-       (lo (gensym "LO-")))
+  (with-unique-names (hi lo)
     (if (eql extra 0)
        `(multiple-value-bind (,hi ,lo) (sb!bignum:%multiply ,x ,y)
           (sb!bignum::%dual-word-add ,hi ,lo ,carry))
     (inst addc hi zero-tn hi-res)))
 
 (define-vop (bignum-lognot)
-  (:translate sb!bignum::%lognot)
+  (:translate sb!bignum:%lognot)
   (:policy :fast-safe)
   (:args (x :scs (unsigned-reg)))
   (:arg-types unsigned-num)
     (inst uaddcm zero-tn x r)))
 
 (define-vop (fixnum-to-digit)
-  (:translate sb!bignum::%fixnum-to-digit)
+  (:translate sb!bignum:%fixnum-to-digit)
   (:policy :fast-safe)
   (:args (fixnum :scs (signed-reg)))
   (:arg-types tagged-num)
     (move fixnum digit)))
 
 (define-vop (bignum-floor)
-  (:translate sb!bignum::%floor)
+  (:translate sb!bignum:%floor)
   (:policy :fast-safe)
   (:args (hi :scs (unsigned-reg) :to (:argument 1))
         (lo :scs (unsigned-reg) :to (:argument 0))
     (inst add divisor rem rem)))
 
 (define-vop (signify-digit)
-  (:translate sb!bignum::%fixnum-digit-with-correct-sign)
+  (:translate sb!bignum:%fixnum-digit-with-correct-sign)
   (:policy :fast-safe)
   (:args (digit :scs (unsigned-reg) :target res))
   (:arg-types unsigned-num)
     (move digit res)))
 
 (define-vop (digit-lshr)
-  (:translate sb!bignum::%digit-logical-shift-right)
+  (:translate sb!bignum:%digit-logical-shift-right)
   (:policy :fast-safe)
   (:args (digit :scs (unsigned-reg))
         (count :scs (unsigned-reg)))
     (inst shd zero-tn digit :variable result)))
 
 (define-vop (digit-ashr digit-lshr)
-  (:translate sb!bignum::%ashr)
+  (:translate sb!bignum:%ashr)
   (:temporary (:scs (unsigned-reg) :to (:result 0)) temp)
   (:generator 1
     (inst extrs digit 0 1 temp)
     (inst shd temp digit :variable result)))
 
 (define-vop (digit-ashl digit-ashr)
-  (:translate sb!bignum::%ashl)
+  (:translate sb!bignum:%ashl)
   (:generator 1
     (inst subi 31 count temp)
     (inst mtctl temp :sar)