Better support for NetBSD/current
[sbcl.git] / src / compiler / ppc / arith.lisp
index 448d018..5f4bfe1 100644 (file)
   (: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))))
+    (let ((phantom-bits (- (+ size posn) 30)))
+      (cond
+        ((plusp phantom-bits)
+         ;; The byte to be loaded into RES includes sign bits which are not
+         ;; present in the input X physically.  RLWINM as used below would
+         ;; mask these out with 0 even for negative inputs.
+         (inst srawi res x phantom-bits)
+         (inst rlwinm res x
+               (mod (- 32 posn (- phantom-bits)) 32)
+               (- 32 size n-fixnum-tag-bits)
+               (- 31 n-fixnum-tag-bits)))
+        (t
+         (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)))
+  (:arg-types signed-num (:constant (integer 1 29)) (:constant (integer 0 31)))
   (:info size posn)
   (:results (res :scs (any-reg)))
   (:result-types tagged-num)
 (define-vop (ldb-c/unsigned)
   (:translate %%ldb)
   (:args (x :scs (unsigned-reg)))
-  (:arg-types unsigned-num (:constant (integer 1 29)) (:constant (integer 0 29)))
+  (:arg-types unsigned-num (:constant (integer 1 29)) (:constant (integer 0 31)))
   (:info size posn)
   (:results (res :scs (any-reg)))
   (:result-types tagged-num)
           (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 :untagged nil 32)
     (inst mullw lo x y)
     (inst mulhwu hi x y)))
 
+#!+multiply-high-vops
+(define-vop (mulhi)
+  (:translate sb!kernel:%multiply-high)
+  (:policy :fast-safe)
+  (:args (x :scs (unsigned-reg))
+         (y :scs (unsigned-reg)))
+  (:arg-types unsigned-num unsigned-num)
+  (:results (hi :scs (unsigned-reg)))
+  (:result-types unsigned-num)
+  (:generator 20
+    (inst mulhwu hi x y)))
+
+#!+multiply-high-vops
+(define-vop (mulhi/fx)
+  (:translate sb!kernel:%multiply-high)
+  (:policy :fast-safe)
+  (:args (x :scs (any-reg))
+         (y :scs (unsigned-reg)))
+  (:arg-types positive-fixnum unsigned-num)
+  (:temporary (:sc non-descriptor-reg :from :eval :to :result) temp)
+  (:temporary (:sc non-descriptor-reg :from :eval :to :result) mask)
+  (:results (hi :scs (any-reg)))
+  (:result-types positive-fixnum)
+  (:generator 15
+    (inst mulhwu temp x y)
+    (inst lr mask fixnum-tag-mask)
+    (inst andc hi temp mask)))
+
 (define-vop (bignum-lognot lognot-mod32/unsigned=>unsigned)
   (:translate sb!bignum:%lognot))