X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fx86%2Farith.lisp;h=4731c2653c1db8ee441442369ee788633bf806ae;hb=a6b91f356da1b5ae2987f79db9bd137970512959;hp=1b29e8d90b05c52bba988a5d1f7d204cfac02f92;hpb=fd63d6aad4a5a3b171eafb56b1b6bd502e501281;p=sbcl.git diff --git a/src/compiler/x86/arith.lisp b/src/compiler/x86/arith.lisp index 1b29e8d..4731c26 100644 --- a/src/compiler/x86/arith.lisp +++ b/src/compiler/x86/arith.lisp @@ -46,13 +46,13 @@ (define-vop (fast-lognot/fixnum fixnum-unop) (:translate lognot) - (:generator 2 + (:generator 1 (move res x) (inst xor res (fixnumize -1)))) (define-vop (fast-lognot/signed signed-unop) (:translate lognot) - (:generator 1 + (:generator 2 (move res x) (inst not res))) @@ -436,7 +436,7 @@ (:vop-var vop) (:save-p :compute-only) (:generator 31 - (let ((zero (generate-error-code vop division-by-zero-error x y))) + (let ((zero (generate-error-code vop 'division-by-zero-error x y))) (if (sc-is y any-reg) (inst test y y) ; smaller instruction (inst cmp y 0)) @@ -491,7 +491,7 @@ (:vop-var vop) (:save-p :compute-only) (:generator 33 - (let ((zero (generate-error-code vop division-by-zero-error x y))) + (let ((zero (generate-error-code vop 'division-by-zero-error x y))) (if (sc-is y unsigned-reg) (inst test y y) ; smaller instruction (inst cmp y 0)) @@ -542,7 +542,7 @@ (:vop-var vop) (:save-p :compute-only) (:generator 33 - (let ((zero (generate-error-code vop division-by-zero-error x y))) + (let ((zero (generate-error-code vop 'division-by-zero-error x y))) (if (sc-is y signed-reg) (inst test y y) ; smaller instruction (inst cmp y 0)) @@ -597,24 +597,27 @@ (:note "inline ASH") (:generator 2 (cond ((and (= amount 1) (not (location= number result))) - (inst lea result (make-ea :dword :index number :scale 2))) + (inst lea result (make-ea :dword :base number :index number))) ((and (= amount 2) (not (location= number result))) (inst lea result (make-ea :dword :index number :scale 4))) ((and (= amount 3) (not (location= number result))) (inst lea result (make-ea :dword :index number :scale 8))) (t (move result number) - (cond ((plusp amount) - ;; We don't have to worry about overflow because of the - ;; result type restriction. - (inst shl result amount)) - (t - ;; If the amount is greater than 31, only shift by 31. We - ;; have to do this because the shift instructions only look - ;; at the low five bits of the result. - (inst sar result (min 31 (- amount))) - ;; Fixnum correction. - (inst and result (lognot fixnum-tag-mask)))))))) + (cond ((< -32 amount 32) + ;; this code is used both in ASH and ASH-SMOD30, so + ;; be careful + (if (plusp amount) + (inst shl result amount) + (progn + (inst sar result (- amount)) + (inst and result (lognot fixnum-tag-mask))))) + ((plusp amount) + (if (sc-is result any-reg) + (inst xor result result) + (inst mov result 0))) + (t (inst sar result 31) + (inst and result (lognot fixnum-tag-mask)))))))) (define-vop (fast-ash-left/fixnum=>fixnum) (:translate ash) @@ -655,7 +658,7 @@ (:note "inline ASH") (:generator 3 (cond ((and (= amount 1) (not (location= number result))) - (inst lea result (make-ea :dword :index number :scale 2))) + (inst lea result (make-ea :dword :base number :index number))) ((and (= amount 2) (not (location= number result))) (inst lea result (make-ea :dword :index number :scale 4))) ((and (= amount 3) (not (location= number result))) @@ -682,7 +685,7 @@ (:note "inline ASH") (:generator 3 (cond ((and (= amount 1) (not (location= number result))) - (inst lea result (make-ea :dword :index number :scale 2))) + (inst lea result (make-ea :dword :base number :index number))) ((and (= amount 2) (not (location= number result))) (inst lea result (make-ea :dword :index number :scale 4))) ((and (= amount 3) (not (location= number result))) @@ -920,7 +923,9 @@ (:result-types unsigned-num) (:generator 28 (move res arg) - (inst cmp res 0) + (if (sc-is res unsigned-reg) + (inst test res res) + (inst cmp res 0)) (inst jmp :ge POS) (inst not res) POS @@ -1317,8 +1322,8 @@ (svop30f (intern (format nil "FAST-~S-SMOD30/FIXNUM=>FIXNUM" name))) (svop30cf (intern (format nil "FAST-~S-SMOD30-C/FIXNUM=>FIXNUM" name)))) `(progn - (define-modular-fun ,fun32 (x y) ,name :unsigned 32) - (define-modular-fun ,sfun30 (x y) ,name :signed 30) + (define-modular-fun ,fun32 (x y) ,name :untagged nil 32) + (define-modular-fun ,sfun30 (x y) ,name :tagged t 30) (define-mod-binop (,vop32u ,vopu) ,fun32) (define-vop (,vop32f ,vopf) (:translate ,fun32)) (define-vop (,svop30f ,vopf) (:translate ,sfun30)) @@ -1364,19 +1369,19 @@ (signed-byte 30) (foldable flushable movable)) -(define-modular-fun-optimizer %lea ((base index scale disp) :unsigned :width width) +(define-modular-fun-optimizer %lea ((base index scale disp) :untagged nil :width width) (when (and (<= width 32) (constant-lvar-p scale) (constant-lvar-p disp)) - (cut-to-width base :unsigned width) - (cut-to-width index :unsigned width) + (cut-to-width base :untagged width nil) + (cut-to-width index :untagged width nil) 'sb!vm::%lea-mod32)) -(define-modular-fun-optimizer %lea ((base index scale disp) :signed :width width) +(define-modular-fun-optimizer %lea ((base index scale disp) :tagged t :width width) (when (and (<= width 30) (constant-lvar-p scale) (constant-lvar-p disp)) - (cut-to-width base :signed width) - (cut-to-width index :signed width) + (cut-to-width base :tagged width t) + (cut-to-width index :tagged width t) 'sb!vm::%lea-smod30)) #+sb-xc-host @@ -1410,7 +1415,7 @@ (:translate %lea-smod30)) ;;; logical operations -(define-modular-fun lognot-mod32 (x) lognot :unsigned 32) +(define-modular-fun lognot-mod32 (x) lognot :untagged nil 32) (define-vop (lognot-mod32/word=>unsigned) (:translate lognot-mod32) (:args (x :scs (unsigned-reg signed-reg unsigned-stack signed-stack) :target r @@ -1433,20 +1438,6 @@ (move r x) (inst not r))) -(define-modular-fun logxor-mod32 (x y) logxor :unsigned 32) -(define-mod-binop (fast-logxor-mod32/word=>unsigned - fast-logxor/unsigned=>unsigned) - logxor-mod32) -(define-mod-binop-c (fast-logxor-mod32-c/word=>unsigned - fast-logxor-c/unsigned=>unsigned) - logxor-mod32) -(define-vop (fast-logxor-mod32/fixnum=>fixnum - fast-logxor/fixnum=>fixnum) - (:translate logxor-mod32)) -(define-vop (fast-logxor-mod32-c/fixnum=>fixnum - fast-logxor-c/fixnum=>fixnum) - (:translate logxor-mod32)) - (define-source-transform logeqv (&rest args) (if (oddp (length args)) `(logxor ,@args) @@ -1476,7 +1467,9 @@ (define-full-reffer bignum-ref * bignum-digits-offset other-pointer-lowtag (unsigned-reg) unsigned-num sb!bignum:%bignum-ref) - +(define-full-reffer+offset bignum-ref-with-offset * + bignum-digits-offset other-pointer-lowtag + (unsigned-reg) unsigned-num sb!bignum:%bignum-ref-with-offset) (define-full-setter bignum-set * bignum-digits-offset other-pointer-lowtag (unsigned-reg) unsigned-num sb!bignum:%bignum-set) @@ -1736,10 +1729,7 @@ (:results (y :scs (unsigned-reg) :from (:eval 0))) (:result-types unsigned-num) (:generator 50 - (inst mov k (make-ea :dword :base state - :disp (- (* (+ 2 vector-data-offset) - n-word-bytes) - other-pointer-lowtag))) + (loadw k state (+ 2 vector-data-offset) other-pointer-lowtag) (inst cmp k 624) (inst jmp :ne no-update) (inst mov tmp state) ; The state is passed in EAX. @@ -1748,25 +1738,15 @@ (inst xor k k) NO-UPDATE ;; y = ptgfsr[k++]; - (inst mov y (make-ea :dword :base state :index k :scale 4 - :disp (- (* (+ 3 vector-data-offset) - n-word-bytes) - other-pointer-lowtag))) + (inst mov y (make-ea-for-vector-data state :index k :offset 3)) ;; y ^= (y >> 11); (inst shr y 11) - (inst xor y (make-ea :dword :base state :index k :scale 4 - :disp (- (* (+ 3 vector-data-offset) - n-word-bytes) - other-pointer-lowtag))) + (inst xor y (make-ea-for-vector-data state :index k :offset 3)) ;; y ^= (y << 7) & #x9d2c5680 (inst mov tmp y) (inst inc k) (inst shl tmp 7) - (inst mov (make-ea :dword :base state - :disp (- (* (+ 2 vector-data-offset) - n-word-bytes) - other-pointer-lowtag)) - k) + (storew k state (+ 2 vector-data-offset) other-pointer-lowtag) (inst and tmp #x9d2c5680) (inst xor y tmp) ;; y ^= (y << 15) & #xefc60000