X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fassembly%2Fx86%2Farith.lisp;h=ea10b508a400d165ace349455ced6d15b27bb185;hb=5728601f88c400d2992b6b8c70d8971d07de9029;hp=535e023758e8319fe2fd2fc7e83ea5248fc6b144;hpb=2cd35e262d4be338e419114137ebf75e36e950f9;p=sbcl.git diff --git a/src/assembly/x86/arith.lisp b/src/assembly/x86/arith.lisp index 535e023..ea10b50 100644 --- a/src/assembly/x86/arith.lisp +++ b/src/assembly/x86/arith.lisp @@ -21,9 +21,7 @@ (:policy :safe) (:save-p t)) ((:arg x (descriptor-reg any-reg) edx-offset) - (:arg y (descriptor-reg any-reg) - ;; this seems wrong esi-offset -- FIXME: What's it mean? - edi-offset) + (:arg y (descriptor-reg any-reg) edi-offset) (:res res (descriptor-reg any-reg) edx-offset) @@ -40,13 +38,12 @@ (inst ret) DO-STATIC-FUN - (inst pop eax) + ;; Same as: (inst enter (fixnumize 1)) (inst push ebp-tn) - (inst lea - ebp-tn - (make-ea :dword :base esp-tn :disp n-word-bytes)) - (inst sub esp-tn (fixnumize 2)) - (inst push eax) ; callers return addr + (inst mov ebp-tn esp-tn) + (inst sub esp-tn (fixnumize 1)) + (inst push (make-ea :dword :base ebp-tn + :disp (frame-byte-offset return-pc-save-offset))) (inst mov ecx (fixnumize 2)) ; arg count (inst jmp (make-ea :dword @@ -86,7 +83,7 @@ (move eax x) ; must use eax for 64-bit result (inst sar eax n-fixnum-tag-bits) ; remove *4 fixnum bias (inst imul y) ; result in edx:eax - (inst jmp :no okay) ; still fixnum + (inst jmp :no OKAY) ; still fixnum ;; zzz jrd changed edx to ebx in here, as edx isn't listed as a temp, above ;; pfw says that loses big -- edx is target for arg x and result res @@ -130,11 +127,11 @@ (inst test x fixnum-tag-mask) (inst jmp :z FIXNUM) - (inst pop eax) (inst push ebp-tn) - (inst lea ebp-tn (make-ea :dword :base esp-tn :disp n-word-bytes)) - (inst sub esp-tn (fixnumize 2)) - (inst push eax) + (inst mov ebp-tn esp-tn) + (inst sub esp-tn (fixnumize 1)) + (inst push (make-ea :dword :base ebp-tn + :disp (frame-byte-offset return-pc-save-offset))) (inst mov ecx (fixnumize 1)) ; arg count (inst jmp (make-ea :dword :disp (+ nil-value (static-fun-offset '%negate)))) @@ -154,18 +151,12 @@ ;;;; comparison (macrolet ((define-cond-assem-rtn (name translate static-fn test) + #+sb-assembling `(define-assembly-routine (,name - (:cost 10) - (:return-style :full-call) - (:policy :safe) - (:translate ,translate) - (:save-p t)) + (:return-style :none)) ((:arg x (descriptor-reg any-reg) edx-offset) (:arg y (descriptor-reg any-reg) edi-offset) - (:res res descriptor-reg edx-offset) - - (:temp eax unsigned-reg eax-offset) (:temp ecx unsigned-reg ecx-offset)) (inst mov ecx x) @@ -174,120 +165,183 @@ (inst jmp :nz DO-STATIC-FUN) ; are both fixnums? (inst cmp x y) - (cond ((member :cmov *backend-subfeatures*) - (load-symbol res t) - (inst mov eax nil-value) - (inst cmov ,test res eax)) - (t - (inst mov res nil-value) - (inst jmp ,test RETURN) - (load-symbol res t))) - RETURN - (inst clc) ; single-value return (inst ret) DO-STATIC-FUN - (inst pop eax) (inst push ebp-tn) - (inst lea ebp-tn (make-ea :dword - :base esp-tn - :disp n-word-bytes)) - (inst sub esp-tn (fixnumize 2)) ; FIXME: Push 2 words on stack, - ; weirdly? - (inst push eax) - (inst mov ecx (fixnumize 2)) ; FIXME: FIXNUMIZE and - ; SINGLE-FLOAT-BITS are parallel, - ; should be named parallelly. - (inst jmp (make-ea :dword - :disp (+ nil-value - (static-fun-offset ',static-fn))))))) - - (define-cond-assem-rtn generic-< < two-arg-< :ge) - (define-cond-assem-rtn generic-> > two-arg-> :le)) - + (inst mov ebp-tn esp-tn) + (inst sub esp-tn (fixnumize 3)) + (inst mov (make-ea :dword :base esp-tn + :disp (frame-byte-offset + (+ sp->fp-offset + -3 + ocfp-save-offset))) + ebp-tn) + (inst lea ebp-tn (make-ea :dword :base esp-tn + :disp (frame-byte-offset + (+ sp->fp-offset + -3 + ocfp-save-offset)))) + (inst mov ecx (fixnumize 2)) + (inst call (make-ea :dword + :disp (+ nil-value + (static-fun-offset ',static-fn)))) + ;; HACK: We depend on NIL having the lowest address of all + ;; static symbols (including T) + ,@(ecase test + (:l `((inst mov y (1+ nil-value)) + (inst cmp y x))) + (:g `((inst cmp x (1+ nil-value))))) + (inst pop ebp-tn) + (inst ret)) + #-sb-assembling + `(define-vop (,name) + (:translate ,translate) + (:policy :safe) + (:save-p t) + (:args (x :scs (descriptor-reg any-reg) :target edx) + (y :scs (descriptor-reg any-reg) :target edi)) + + (:temporary (:sc unsigned-reg :offset edx-offset + :from (:argument 0)) + edx) + (:temporary (:sc unsigned-reg :offset edi-offset + :from (:argument 1)) + edi) + (:conditional ,test) + (:generator 10 + (move edx x) + (move edi y) + (inst call (make-fixup ',name :assembly-routine)))))) + + (define-cond-assem-rtn generic-< < two-arg-< :l) + (define-cond-assem-rtn generic-> > two-arg-> :g)) + +#+sb-assembling (define-assembly-routine (generic-eql - (:cost 10) - (:return-style :full-call) - (:policy :safe) - (:translate eql) - (:save-p t)) + (:return-style :none)) ((:arg x (descriptor-reg any-reg) edx-offset) (:arg y (descriptor-reg any-reg) edi-offset) - (:res res descriptor-reg edx-offset) - - (:temp eax unsigned-reg eax-offset) (:temp ecx unsigned-reg ecx-offset)) (inst mov ecx x) (inst and ecx y) - (inst test ecx fixnum-tag-mask) - (inst jmp :nz DO-STATIC-FUN) + (inst and ecx lowtag-mask) + (inst cmp ecx other-pointer-lowtag) + (inst jmp :e DO-STATIC-FUN) ;; At least one fixnum (inst cmp x y) - (load-symbol res t) - (cond ((member :cmov *backend-subfeatures*) - (inst mov eax nil-value) - (inst cmov :ne res eax)) - (t - (inst jmp :e RETURN) - (inst mov res nil-value))) - RETURN - (inst clc) + RET (inst ret) - ;; FIXME: We could handle all non-numbers here easily enough: go to - ;; TWO-ARG-EQL only if lowtags and widetags match, lowtag is - ;; other-pointer-lowtag and widetag is < code-header-widetag. DO-STATIC-FUN - (inst pop eax) + ;; Might as well fast path that... + (inst cmp x y) + (inst jmp :e RET) + (inst push ebp-tn) - (inst lea ebp-tn (make-ea :dword :base esp-tn :disp n-word-bytes)) - (inst sub esp-tn (fixnumize 2)) - (inst push eax) + (inst mov ebp-tn esp-tn) + (inst sub esp-tn (fixnumize 3)) + (inst mov (make-ea :dword :base esp-tn + :disp (frame-byte-offset + (+ sp->fp-offset + -3 + ocfp-save-offset))) + ebp-tn) + (inst lea ebp-tn (make-ea :dword :base esp-tn + :disp (frame-byte-offset + (+ sp->fp-offset + -3 + ocfp-save-offset)))) (inst mov ecx (fixnumize 2)) - (inst jmp (make-ea :dword - :disp (+ nil-value (static-fun-offset 'eql))))) + (inst call (make-ea :dword + :disp (+ nil-value (static-fun-offset 'eql)))) + (load-symbol y t) + (inst cmp x y) + (inst pop ebp-tn) + (inst ret)) +#-sb-assembling +(define-vop (generic-eql) + (:translate eql) + (:policy :safe) + (:save-p t) + (:args (x :scs (descriptor-reg any-reg) :target edx) + (y :scs (descriptor-reg any-reg) :target edi)) + + (:temporary (:sc unsigned-reg :offset edx-offset + :from (:argument 0)) + edx) + (:temporary (:sc unsigned-reg :offset edi-offset + :from (:argument 1)) + edi) + + (:conditional :e) + (:generator 10 + (move edx x) + (move edi y) + (inst call (make-fixup 'generic-eql :assembly-routine)))) + +#+sb-assembling (define-assembly-routine (generic-= - (:cost 10) - (:return-style :full-call) - (:policy :safe) - (:translate =) - (:save-p t)) + (:return-style :none)) ((:arg x (descriptor-reg any-reg) edx-offset) (:arg y (descriptor-reg any-reg) edi-offset) - (:res res descriptor-reg edx-offset) - - (:temp eax unsigned-reg eax-offset) (:temp ecx unsigned-reg ecx-offset)) (inst mov ecx x) (inst or ecx y) - (inst test ecx fixnum-tag-mask) ; both fixnums? + (inst test ecx fixnum-tag-mask) (inst jmp :nz DO-STATIC-FUN) + ;; Both fixnums (inst cmp x y) - (load-symbol res t) - (cond ((member :cmov *backend-subfeatures*) - (inst mov eax nil-value) - (inst cmov :ne res eax)) - (t - (inst jmp :e RETURN) - (inst mov res nil-value))) - RETURN - (inst clc) (inst ret) DO-STATIC-FUN - (inst pop eax) (inst push ebp-tn) - (inst lea ebp-tn (make-ea :dword :base esp-tn :disp n-word-bytes)) - (inst sub esp-tn (fixnumize 2)) - (inst push eax) + (inst mov ebp-tn esp-tn) + (inst sub esp-tn (fixnumize 3)) + (inst mov (make-ea :dword :base esp-tn + :disp (frame-byte-offset + (+ sp->fp-offset + -3 + ocfp-save-offset))) + ebp-tn) + (inst lea ebp-tn (make-ea :dword :base esp-tn + :disp (frame-byte-offset + (+ sp->fp-offset + -3 + ocfp-save-offset)))) (inst mov ecx (fixnumize 2)) - (inst jmp (make-ea :dword - :disp (+ nil-value (static-fun-offset 'two-arg-=))))) + (inst call (make-ea :dword + :disp (+ nil-value (static-fun-offset 'two-arg-=)))) + (load-symbol y t) + (inst cmp x y) + (inst pop ebp-tn) + (inst ret)) + +#-sb-assembling +(define-vop (generic-=) + (:translate =) + (:policy :safe) + (:save-p t) + (:args (x :scs (descriptor-reg any-reg) :target edx) + (y :scs (descriptor-reg any-reg) :target edi)) + + (:temporary (:sc unsigned-reg :offset edx-offset + :from (:argument 0)) + edx) + (:temporary (:sc unsigned-reg :offset edi-offset + :from (:argument 1)) + edi) + + (:conditional :e) + (:generator 10 + (move edx x) + (move edi y) + (inst call (make-fixup 'generic-= :assembly-routine)))) ;;; Support for the Mersenne Twister, MT19937, random number generator