0.8.13.26:
[sbcl.git] / src / compiler / x86 / arith.lisp
index dedb74a..76d39af 100644 (file)
                  (:translate ,translate)
                  (:generator ,untagged-penalty
                  (move r x)
-                 (inst ,op r y))))))
-
-  ;;(define-binop + 4 add)
+                 ,(if (eq translate 'logand)
+                      ;; for the -C/UNSIGNED=>UNSIGNED VOP, this case
+                      ;; is optimized away as an identity somewhere
+                      ;; along the lines.  However, this VOP is used in
+                      ;; -C/SIGNED=>UNSIGNED, below, when the
+                      ;; higher-level lisp code can't optimize away the
+                      ;; non-trivial identity.
+                      `(unless (= y #.(1- (ash 1 n-word-bits)))
+                         (inst ,op r y))
+                      `(inst ,op r y)))))))
   (define-binop - 4 sub)
   (define-binop logand 2 and)
   (define-binop logior 2 or)
           (move r x)
           (inst add r y)))))
 
-
 ;;;; Special logand cases: (logand signed unsigned) => unsigned
 
 (define-vop (fast-logand/signed-unsigned=>unsigned
     (move result prev)
     (inst shrd result next :cl)))
 
-(define-source-transform 32bit-logical-not (x)
+(define-source-transform word-logical-not (x)
   `(logand (lognot (the (unsigned-byte 32) ,x)) #.(1- (ash 1 32))))
 
-(deftransform 32bit-logical-and ((x y))
+(deftransform word-logical-and ((x y))
   '(logand x y))
 
-(define-source-transform 32bit-logical-nand (x y)
-  `(32bit-logical-not (32bit-logical-and ,x ,y)))
+(define-source-transform word-logical-nand (x y)
+  `(word-logical-not (word-logical-and ,x ,y)))
 
-(deftransform 32bit-logical-or ((x y))
+(deftransform word-logical-or ((x y))
   '(logior x y))
 
-(define-source-transform 32bit-logical-nor (x y)
-  `(32bit-logical-not (32bit-logical-or ,x ,y)))
+(define-source-transform word-logical-nor (x y)
+  `(word-logical-not (word-logical-or ,x ,y)))
 
-(deftransform 32bit-logical-xor ((x y))
+(deftransform word-logical-xor ((x y))
   '(logxor x y))
 
-(define-source-transform 32bit-logical-eqv (x y)
-  `(32bit-logical-not (32bit-logical-xor ,x ,y)))
+(define-source-transform word-logical-eqv (x y)
+  `(word-logical-not (word-logical-xor ,x ,y)))
 
-(define-source-transform 32bit-logical-orc1 (x y)
-  `(32bit-logical-or (32bit-logical-not ,x) ,y))
+(define-source-transform word-logical-orc1 (x y)
+  `(word-logical-or (word-logical-not ,x) ,y))
 
-(define-source-transform 32bit-logical-orc2 (x y)
-  `(32bit-logical-or ,x (32bit-logical-not ,y)))
+(define-source-transform word-logical-orc2 (x y)
+  `(word-logical-or ,x (word-logical-not ,y)))
 
-(define-source-transform 32bit-logical-andc1 (x y)
-  `(32bit-logical-and (32bit-logical-not ,x) ,y))
+(define-source-transform word-logical-andc1 (x y)
+  `(word-logical-and (word-logical-not ,x) ,y))
 
-(define-source-transform 32bit-logical-andc2 (x y)
-  `(32bit-logical-and ,x (32bit-logical-not ,y)))
+(define-source-transform word-logical-andc2 (x y)
+  `(word-logical-and ,x (word-logical-not ,y)))
 
 ;;; Only the lower 5 bits of the shift amount are significant.
 (define-vop (shift-towards-someplace)
     (cut-to-width index width)
     'sb!vm::%lea-mod32))
 
+#+sb-xc-host
+(defun sb!vm::%lea-mod32 (base index scale disp)
+  (ldb (byte 32 0) (%lea base index scale disp)))
+#-sb-xc-host
+(defun sb!vm::%lea-mod32 (base index scale disp)
+  (let ((base (logand base #xffffffff))
+       (index (logand index #xffffffff)))
+    ;; can't use modular version of %LEA, as we only have VOPs for
+    ;; constant SCALE and DISP.
+    (ldb (byte 32 0) (+ base (* index scale) disp))))
+
 (in-package "SB!VM")
 
 (define-vop (%lea-mod32/unsigned=>unsigned