X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fsparc%2Farith.lisp;h=7acaa6b547ba928591dade5fa0596446e6571448;hb=cd875f8c1fb306067521330fbf84411713b7c20d;hp=18870902f14baaf3f7a719743c8d296d4af67290;hpb=dd357f3be290498fb7ef172696d986337f517a93;p=sbcl.git diff --git a/src/compiler/sparc/arith.lisp b/src/compiler/sparc/arith.lisp index 1887090..7acaa6b 100644 --- a/src/compiler/sparc/arith.lisp +++ b/src/compiler/sparc/arith.lisp @@ -387,7 +387,7 @@ (define-vop (fast-ash/signed=>signed) (:note "inline ASH") (:args (number :scs (signed-reg) :to :save) - (amount :scs (signed-reg immediate) :to :save)) + (amount :scs (signed-reg) :to :save)) (:arg-types signed-num signed-num) (:results (result :scs (signed-reg))) (:result-types signed-num) @@ -395,32 +395,43 @@ (:policy :fast-safe) (:temporary (:sc non-descriptor-reg) ndesc) (:generator 5 - (sc-case amount - (signed-reg - (let ((done (gen-label))) - (inst cmp amount) - (inst b :ge done) - ;; The result-type assures us that this shift will not - ;; overflow. - (inst sll result number amount) - (inst neg ndesc amount) - (inst cmp ndesc 31) - (if (member :sparc-v9 *backend-subfeatures*) - (progn - (inst cmove :ge ndesc 31) - (inst sra result number ndesc)) - (progn - (inst b :le done) - (inst sra result number ndesc) - (inst sra result number 31))) - (emit-label done))) - (immediate - (bug "IMMEDIATE case in ASH VOP; should have been transformed"))))) + (let ((done (gen-label))) + (inst cmp amount) + (inst b :ge done) + ;; The result-type assures us that this shift will not + ;; overflow. + (inst sll result number amount) + (inst neg ndesc amount) + (inst cmp ndesc 31) + (if (member :sparc-v9 *backend-subfeatures*) + (progn + (inst cmove :ge ndesc 31) + (inst sra result number ndesc)) + (progn + (inst b :le done) + (inst sra result number ndesc) + (inst sra result number 31))) + (emit-label done)))) + +(define-vop (fast-ash-c/signed=>signed) + (:note "inline constant ASH") + (:args (number :scs (signed-reg))) + (:info count) + (:arg-types signed-num (:constant integer)) + (:results (result :scs (signed-reg))) + (:result-types signed-num) + (:translate ash) + (:policy :fast-safe) + (:generator 4 + (cond + ((< count 0) (inst sra result number (min (- count) 31))) + ((> count 0) (inst sll result number (min count 31))) + (t (bug "identity ASH not transformed away"))))) (define-vop (fast-ash/unsigned=>unsigned) (:note "inline ASH") (:args (number :scs (unsigned-reg) :to :save) - (amount :scs (signed-reg immediate) :to :save)) + (amount :scs (signed-reg) :to :save)) (:arg-types unsigned-num signed-num) (:results (result :scs (unsigned-reg))) (:result-types unsigned-num) @@ -428,27 +439,39 @@ (:policy :fast-safe) (:temporary (:sc non-descriptor-reg) ndesc) (:generator 5 - (sc-case amount - (signed-reg - (let ((done (gen-label))) - (inst cmp amount) - (inst b :ge done) - ;; The result-type assures us that this shift will not - ;; overflow. - (inst sll result number amount) - (inst neg ndesc amount) - (inst cmp ndesc 32) - (if (member :sparc-v9 *backend-subfeatures*) - (progn - (inst srl result number ndesc) - (inst cmove :ge result zero-tn)) - (progn - (inst b :lt done) - (inst srl result number ndesc) - (move result zero-tn))) - (emit-label done))) - (immediate - (bug "IMMEDIATE case in ASH VOP; should have been transformed"))))) + (let ((done (gen-label))) + (inst cmp amount) + (inst b :ge done) + ;; The result-type assures us that this shift will not + ;; overflow. + (inst sll result number amount) + (inst neg ndesc amount) + (inst cmp ndesc 32) + (if (member :sparc-v9 *backend-subfeatures*) + (progn + (inst srl result number ndesc) + (inst cmove :ge result zero-tn)) + (progn + (inst b :lt done) + (inst srl result number ndesc) + (move result zero-tn))) + (emit-label done)))) + +(define-vop (fast-ash-c/unsigned=>unsigned) + (:note "inline constant ASH") + (:args (number :scs (unsigned-reg))) + (:info count) + (:arg-types unsigned-num (:constant integer)) + (:results (result :scs (unsigned-reg))) + (:result-types unsigned-num) + (:translate ash) + (:policy :fast-safe) + (:generator 4 + (cond + ((< count -31) (move result zero-tn)) + ((< count 0) (inst srl result number (min (- count) 31))) + ((> count 0) (inst sll result number (min count 31))) + (t (bug "identity ASH not transformed away"))))) ;; Some special cases where we know we want a left shift. Just do the ;; shift, instead of checking for the sign of the shift. @@ -472,70 +495,12 @@ (inst sll result number amount)) (immediate (let ((amount (tn-value amount))) - (assert (>= amount 0)) + (aver (>= amount 0)) (inst sll result number amount)))))))) (frob fast-ash-left/signed=>signed signed-reg signed-num signed-reg 3) (frob fast-ash-left/fixnum=>fixnum any-reg tagged-num any-reg 2) (frob fast-ash-left/unsigned=>unsigned unsigned-reg unsigned-num unsigned-reg 3)) -(defknown ash-right-signed ((signed-byte #.sb!vm:n-word-bits) - (and fixnum unsigned-byte)) - (signed-byte #.sb!vm:n-word-bits) - (movable foldable flushable)) - -(defknown ash-right-unsigned ((unsigned-byte #.sb!vm:n-word-bits) - (and fixnum unsigned-byte)) - (unsigned-byte #.sb!vm:n-word-bits) - (movable foldable flushable)) - -;; Some special cases where we want a right shift. Just do the shift. -;; (Needs appropriate deftransforms to call these, though.) - -(macrolet - ((frob (trans name sc-type type shift-inst cost) - `(define-vop (,name) - (:note "inline right ASH") - (:translate ,trans) - (:args (number :scs (,sc-type)) - (amount :scs (signed-reg unsigned-reg immediate))) - (:arg-types ,type positive-fixnum) - (:results (result :scs (,sc-type))) - (:result-types ,type) - (:policy :fast-safe) - (:generator ,cost - (sc-case amount - ((signed-reg unsigned-reg) - (inst ,shift-inst result number amount)) - (immediate - (let ((amt (tn-value amount))) - (inst ,shift-inst result number amt)))))))) - (frob ash-right-signed fast-ash-right/signed=>signed - signed-reg signed-num sra 3) - (frob ash-right-unsigned fast-ash-right/unsigned=>unsigned - unsigned-reg unsigned-num srl 3)) - -(define-vop (fast-ash-right/fixnum=>fixnum) - (:note "inline right ASH") - (:translate ash-right-signed) - (:args (number :scs (any-reg)) - (amount :scs (signed-reg unsigned-reg immediate))) - (:arg-types tagged-num positive-fixnum) - (:results (result :scs (any-reg))) - (:result-types tagged-num) - (:temporary (:sc non-descriptor-reg :target result) temp) - (:policy :fast-safe) - (:generator 2 - ;; Shift the fixnum right by the desired amount. Then zap out the - ;; 2 LSBs to make it a fixnum again. (Those bits are junk.) - (sc-case amount - ((signed-reg unsigned-reg) - (inst sra temp number amount)) - (immediate - (inst sra temp number (tn-value amount)))) - (inst andn result temp fixnum-tag-mask))) - - - (define-vop (signed-byte-32-len) (:translate integer-length) @@ -691,7 +656,7 @@ ((define-modular-backend (fun &optional constantp) (let ((mfun-name (symbolicate fun '-mod32)) (modvop (symbolicate 'fast- fun '-mod32/unsigned=>unsigned)) - (modcvop (symbolicate 'fast- fun 'mod32-c/unsigned=>unsigned)) + (modcvop (symbolicate 'fast- fun '-mod32-c/unsigned=>unsigned)) (vop (symbolicate 'fast- fun '/unsigned=>unsigned)) (cvop (symbolicate 'fast- fun '-c/unsigned=>unsigned))) `(progn @@ -702,6 +667,7 @@ `((define-vop (,modcvop ,cvop) (:translate ,mfun-name)))))))) (define-modular-backend + t) + (define-modular-backend - t) (define-modular-backend logxor t) (define-modular-backend logeqv t) (define-modular-backend logandc1) @@ -713,6 +679,10 @@ `(lognot (logand ,x ,y))) (define-source-transform lognor (x y) `(lognot (logior ,x ,y))) + +(define-vop (fast-ash-left-mod32-c/unsigned=>unsigned + fast-ash-c/unsigned=>unsigned) + (:translate ash-left-mod32)) ;;;; Binary conditional VOPs: @@ -827,7 +797,6 @@ ;;;; 32-bit logical operations - (define-vop (merge-bits) (:translate merge-bits) (:args (shift :scs (signed-reg unsigned-reg)) @@ -904,24 +873,23 @@ (inst srl r num amount))) ;;;; 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-vop (bignum-ref word-index-ref) (:variant bignum-digits-offset other-pointer-lowtag) - (:translate sb!bignum::%bignum-ref) + (:translate sb!bignum:%bignum-ref) (:results (value :scs (unsigned-reg))) (:result-types unsigned-num)) (define-vop (bignum-set word-index-set) (:variant bignum-digits-offset other-pointer-lowtag) - (:translate sb!bignum::%bignum-set) + (:translate sb!bignum:%bignum-set) (:args (object :scs (descriptor-reg)) (index :scs (any-reg immediate zero)) (value :scs (unsigned-reg))) @@ -930,7 +898,7 @@ (:result-types unsigned-num)) (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) @@ -945,7 +913,7 @@ (emit-label done)))) (define-vop (v9-digit-0-or-plus-cmove) - (: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) @@ -959,7 +927,7 @@ ;; This doesn't work? #+nil (define-vop (v9-digit-0-or-plus-movr) - (: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) @@ -971,9 +939,8 @@ (inst movr result null-tn digit :lz) (inst movr result temp digit :gez))) - (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)) @@ -988,7 +955,7 @@ (inst addx carry zero-tn zero-tn))) (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)) @@ -1056,7 +1023,7 @@ (inst rdy result-low))))) (define-vop (bignum-mult-and-add-3-arg) - (:translate sb!bignum::%multiply-and-add) + (:translate sb!bignum:%multiply-and-add) (:policy :fast-safe) (:args (x :scs (unsigned-reg) :to (:eval 1)) (y :scs (unsigned-reg) :to (:eval 1)) @@ -1071,7 +1038,7 @@ (inst addx hi zero-tn))) (define-vop (bignum-mult-and-add-4-arg) - (:translate sb!bignum::%multiply-and-add) + (:translate sb!bignum:%multiply-and-add) (:policy :fast-safe) (:args (x :scs (unsigned-reg) :to (:eval 1)) (y :scs (unsigned-reg) :to (:eval 1)) @@ -1089,7 +1056,7 @@ (inst addx hi zero-tn))) (define-vop (bignum-mult) - (:translate sb!bignum::%multiply) + (:translate sb!bignum:%multiply) (:policy :fast-safe) (:args (x :scs (unsigned-reg) :to (:result 1)) (y :scs (unsigned-reg) :to (:result 1))) @@ -1101,10 +1068,10 @@ (emit-multiply x y hi lo))) (define-vop (bignum-lognot lognot-mod32/unsigned=>unsigned) - (:translate sb!bignum::%lognot)) + (:translate sb!bignum:%lognot)) (define-vop (fixnum-to-digit) - (:translate sb!bignum::%fixnum-to-digit) + (:translate sb!bignum:%fixnum-to-digit) (:policy :fast-safe) (:args (fixnum :scs (any-reg))) (:arg-types tagged-num) @@ -1114,7 +1081,7 @@ (inst sra digit fixnum n-fixnum-tag-bits))) (define-vop (bignum-floor) - (:translate sb!bignum::%floor) + (:translate sb!bignum:%floor) (:policy :fast-safe) (:args (div-high :scs (unsigned-reg) :target rem) (div-low :scs (unsigned-reg) :target quo) @@ -1138,7 +1105,7 @@ (inst not quo))) (define-vop (bignum-floor-v8) - (:translate sb!bignum::%floor) + (:translate sb!bignum:%floor) (:policy :fast-safe) (:args (div-high :scs (unsigned-reg) :target rem) (div-low :scs (unsigned-reg) :target quo) @@ -1167,7 +1134,7 @@ (move quo q)))) (define-vop (bignum-floor-v9) - (:translate sb!bignum::%floor) + (:translate sb!bignum:%floor) (:policy :fast-safe) (:args (div-high :scs (unsigned-reg)) (div-low :scs (unsigned-reg)) @@ -1189,7 +1156,7 @@ (inst sub rem dividend 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) @@ -1202,9 +1169,8 @@ (signed-reg (move res digit))))) - (define-vop (digit-ashr) - (:translate sb!bignum::%ashr) + (:translate sb!bignum:%ashr) (:policy :fast-safe) (:args (digit :scs (unsigned-reg)) (count :scs (unsigned-reg))) @@ -1215,12 +1181,12 @@ (inst sra result digit count))) (define-vop (digit-lshr digit-ashr) - (:translate sb!bignum::%digit-logical-shift-right) + (:translate sb!bignum:%digit-logical-shift-right) (:generator 1 (inst srl result digit count))) (define-vop (digit-ashl digit-ashr) - (:translate sb!bignum::%ashl) + (:translate sb!bignum:%ashl) (:generator 1 (inst sll result digit count))) @@ -1250,17 +1216,6 @@ (define-static-fun two-arg-eqv (x y) :translate logeqv) -;; Need these so constant folding works with the deftransform. - -;; FIXME KLUDGE ew yuk. -#-sb-xc-host -(progn - (defun ash-right-signed (num shift) - (ash-right-signed num shift)) - - (defun ash-right-unsigned (num shuft) - (ash-right-unsigned num shift))) - (in-package "SB!C") (deftransform * ((x y) @@ -1281,36 +1236,3 @@ (when (> (+ adds shifts) 9) (give-up-ir1-transform)))) (or result 0)))) - -;; If we can prove that we have a right shift, just do the right shift -;; instead of calling the inline ASH which has to check for the -;; direction of the shift at run-time. -(deftransform ash ((num shift) (integer integer)) - (let ((num-type (lvar-type num)) - (shift-type (lvar-type shift))) - ;; Can only handle right shifts - (unless (csubtypep shift-type (specifier-type '(integer * 0))) - (give-up-ir1-transform)) - - ;; If we can prove the shift is so large that all bits are shifted - ;; out, return the appropriate constant. If the shift is small - ;; enough, call the VOP. Otherwise, check for the shift size and - ;; do the appropriate thing. (Hmm, could we just leave the IF - ;; s-expr and depend on other parts of the compiler to delete the - ;; unreachable parts, if any?) - (cond ((csubtypep num-type (specifier-type '(signed-byte #.sb!vm:n-word-bits))) - ;; A right shift by 31 is the same as a right shift by - ;; larger amount. We get just the sign. - (if (csubtypep shift-type (specifier-type '(integer #.(- 1 sb!vm:n-word-bits) 0))) - ;; FIXME: ash-right-{un,}signed package problems - `(sb!vm::ash-right-signed num (- shift)) - `(sb!vm::ash-right-signed num (min (- shift) #.(1- sb!vm:n-word-bits))))) - ((csubtypep num-type (specifier-type '(unsigned-byte #.sb!vm:n-word-bits))) - (if (csubtypep shift-type (specifier-type '(integer #.(- 1 sb!vm:n-word-bits) 0))) - `(sb!vm::ash-right-unsigned num (- shift)) - `(if (<= shift #.(- sb!vm:n-word-bits)) - 0 - (sb!vm::ash-right-unsigned num (- shift))))) - (t - (give-up-ir1-transform))))) -