X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fx86%2Fcall.lisp;h=e0609214baac7a2a1fe98d9c573dc00f207c8905;hb=a3d4610158f227d53cb5eac287dd2661e975fc70;hp=cd90c1f13f3886912a84559d96c15b82732bc6c1;hpb=997959cc458b00ff7faae526511533d24bdc0fde;p=sbcl.git diff --git a/src/compiler/x86/call.lisp b/src/compiler/x86/call.lisp index cd90c1f..e060921 100644 --- a/src/compiler/x86/call.lisp +++ b/src/compiler/x86/call.lisp @@ -15,7 +15,7 @@ ;;; Return a wired TN describing the N'th full call argument passing ;;; location. -(!def-vm-support-routine standard-arg-location (n) +(defun standard-arg-location (n) (declare (type unsigned-byte n)) (if (< n register-arg-count) (make-wired-tn *backend-t-primitive-type* descriptor-reg-sc-number @@ -26,7 +26,7 @@ ;;; ;;; Always wire the return PC location to the stack in its standard ;;; location. -(!def-vm-support-routine make-return-pc-passing-location (standard) +(defun make-return-pc-passing-location (standard) (declare (ignore standard)) (make-wired-tn (primitive-type-or-lose 'system-area-pointer) sap-stack-sc-number return-pc-save-offset)) @@ -38,7 +38,7 @@ ;;; because we want to be able to assume it's always there. Besides, ;;; the x86 doesn't have enough registers to really make it profitable ;;; to pass it in a register. -(!def-vm-support-routine make-old-fp-passing-location (standard) +(defun make-old-fp-passing-location (standard) (declare (ignore standard)) (make-wired-tn *fixnum-primitive-type* control-stack-sc-number ocfp-save-offset)) @@ -49,12 +49,12 @@ ;;; ;;; Without using a save-tn - which does not make much sense if it is ;;; wired to the stack? -(!def-vm-support-routine make-old-fp-save-location (physenv) +(defun make-old-fp-save-location (physenv) (physenv-debug-live-tn (make-wired-tn *fixnum-primitive-type* control-stack-sc-number ocfp-save-offset) physenv)) -(!def-vm-support-routine make-return-pc-save-location (physenv) +(defun make-return-pc-save-location (physenv) (physenv-debug-live-tn (make-wired-tn (primitive-type-or-lose 'system-area-pointer) sap-stack-sc-number return-pc-save-offset) @@ -63,23 +63,23 @@ ;;; Make a TN for the standard argument count passing location. We only ;;; need to make the standard location, since a count is never passed when we ;;; are using non-standard conventions. -(!def-vm-support-routine make-arg-count-location () +(defun make-arg-count-location () (make-wired-tn *fixnum-primitive-type* any-reg-sc-number ecx-offset)) ;;; Make a TN to hold the number-stack frame pointer. This is allocated ;;; once per component, and is component-live. -(!def-vm-support-routine make-nfp-tn () +(defun make-nfp-tn () (make-restricted-tn *fixnum-primitive-type* ignore-me-sc-number)) -(!def-vm-support-routine make-stack-pointer-tn () +(defun make-stack-pointer-tn () (make-normal-tn *fixnum-primitive-type*)) -(!def-vm-support-routine make-number-stack-pointer-tn () +(defun make-number-stack-pointer-tn () (make-restricted-tn *fixnum-primitive-type* ignore-me-sc-number)) ;;; Return a list of TNs that can be used to represent an unknown-values ;;; continuation within a function. -(!def-vm-support-routine make-unknown-values-locations () +(defun make-unknown-values-locations () (list (make-stack-pointer-tn) (make-normal-tn *fixnum-primitive-type*))) @@ -87,7 +87,7 @@ ;;; VM-dependent initialization of the IR2-COMPONENT structure. We ;;; push placeholder entries in the CONSTANTS to leave room for ;;; additional noise in the code object header. -(!def-vm-support-routine select-component-format (component) +(defun select-component-format (component) (declare (type component component)) ;; The 1+ here is because for the x86 the first constant is a ;; pointer to a list of fixups, or NIL if the code object has none. @@ -139,6 +139,137 @@ (storew value frame-pointer (frame-word-offset (tn-offset variable-home-tn))))) +(macrolet ((define-frame-op + (suffix sc stack-sc instruction + &optional (ea + `(make-ea :dword + :base frame-pointer + :disp (frame-byte-offset + (tn-offset variable-home-tn))))) + (let ((reffer (symbolicate 'ancestor-frame-ref '/ suffix)) + (setter (symbolicate 'ancestor-frame-set '/ suffix))) + `(progn + (define-vop (,reffer ancestor-frame-ref) + (:results (value :scs (,sc))) + (:generator 4 + (aver (sc-is variable-home-tn ,stack-sc)) + (inst ,instruction value + ,ea))) + (define-vop (,setter ancestor-frame-set) + (:args (frame-pointer :scs (descriptor-reg)) + (value :scs (,sc))) + (:generator 4 + (aver (sc-is variable-home-tn ,stack-sc)) + (inst ,instruction ,ea value)))))) + (define-x87-frame-op + (suffix sc stack-sc (load set) + &optional (ea + `(make-ea :dword + :base frame-pointer + :disp (frame-byte-offset + (tn-offset variable-home-tn))))) + (let ((reffer (symbolicate 'ancestor-frame-ref '/ suffix)) + (setter (symbolicate 'ancestor-frame-set '/ suffix))) + `(progn + (define-vop (,reffer ancestor-frame-ref) + (:results (value :scs (,sc))) + (:generator 4 + (aver (sc-is variable-home-tn ,stack-sc)) + ,(if (symbolp load) + `(with-empty-tn@fp-top (value) + (inst ,load ,ea)) + load))) + (define-vop (,setter ancestor-frame-set) + (:args (frame-pointer :scs (descriptor-reg)) + (value :scs (,sc))) + (:generator 4 + (aver (sc-is variable-home-tn ,stack-sc)) + ,(if (symbolp set) + `(with-tn@fp-top (value) + (inst ,set ,ea)) + set))))))) + (define-frame-op signed-byte-32 signed-reg signed-stack mov) + (define-frame-op unsigned-byte-32 unsigned-reg unsigned-stack mov) + (define-frame-op system-area-pointer sap-reg sap-stack mov) + + (define-x87-frame-op double-float double-reg double-stack + (fldd fstd) (make-ea :dword + :base frame-pointer + :disp (frame-byte-offset + (1+ (tn-offset variable-home-tn))))) + (define-x87-frame-op single-float single-reg single-stack + (fld fst)) + + (define-x87-frame-op complex-double-float complex-double-reg + complex-double-stack + ((let ((real (complex-double-reg-real-tn value)) + (imag (complex-double-reg-imag-tn value))) + (with-empty-tn@fp-top (real) + (inst fldd (ea-for-cdf-real-stack variable-home-tn frame-pointer))) + (with-empty-tn@fp-top (imag) + (inst fldd (ea-for-cdf-imag-stack variable-home-tn frame-pointer)))) + (let ((real (complex-double-reg-real-tn value)) + (imag (complex-double-reg-imag-tn value))) + (with-tn@fp-top (real) + (inst fstd (ea-for-cdf-real-stack variable-home-tn frame-pointer))) + (with-tn@fp-top (imag) + (inst fstd (ea-for-cdf-imag-stack variable-home-tn frame-pointer)))))) + (define-x87-frame-op complex-single-float complex-single-reg + complex-single-stack + ((let ((real (complex-single-reg-real-tn value)) + (imag (complex-single-reg-imag-tn value))) + (with-empty-tn@fp-top (real) + (inst fld (ea-for-csf-real-stack variable-home-tn frame-pointer))) + (with-empty-tn@fp-top (imag) + (inst fld (ea-for-csf-imag-stack variable-home-tn frame-pointer)))) + (let ((real (complex-single-reg-real-tn value)) + (imag (complex-single-reg-imag-tn value))) + (with-tn@fp-top (real) + (inst fst (ea-for-csf-real-stack variable-home-tn frame-pointer))) + (with-tn@fp-top (imag) + (inst fst (ea-for-csf-imag-stack variable-home-tn frame-pointer))))))) + +(defun primitive-type-indirect-cell-type (ptype) + (declare (type primitive-type ptype)) + (macrolet ((foo (&body data) + `(case (primitive-type-name ptype) + ,@(loop for (name stack-sc ref set) in data + collect + `(,name + (load-time-value + (list (primitive-type-or-lose ',name) + (sc-or-lose ',stack-sc) + (lambda (node block fp value res) + (sb!c::vop ,ref node block + fp value res)) + (lambda (node block fp new-val value) + (sb!c::vop ,set node block + fp new-val value))))))))) + (foo (double-float double-stack + ancestor-frame-ref/double-float + ancestor-frame-set/double-float) + (single-float single-stack + ancestor-frame-ref/single-float + ancestor-frame-set/single-float) + (complex-double-float complex-double-stack + ancestor-frame-ref/complex-double-float + ancestor-frame-set/complex-double-float) + (complex-single-float complex-single-stack + ancestor-frame-ref/complex-single-float + ancestor-frame-set/complex-single-float) + (signed-byte-32 signed-stack + ancestor-frame-ref/signed-byte-32 + ancestor-frame-set/signed-byte-32) + (unsigned-byte-32 unsigned-stack + ancestor-frame-ref/unsigned-byte-32 + ancestor-frame-set/unsigned-byte-32) + (unsigned-byte-31 unsigned-stack + ancestor-frame-ref/unsigned-byte-32 + ancestor-frame-set/unsigned-byte-32) + (system-area-pointer sap-stack + ancestor-frame-ref/system-area-pointer + ancestor-frame-set/system-area-pointer)))) + (define-vop (xep-allocate-frame) (:info start-lab copy-more-arg-follows) (:vop-var vop) @@ -490,16 +621,17 @@ (= (tn-offset return-pc) return-pc-save-offset)) (error "return-pc not on stack in standard save location?"))) -;;; Instead of JMPing to TARGET, CALL a trampoline that saves the -;;; return pc and jumps. Although this is an incredibly stupid trick -;;; the paired CALL/RET instructions are a big win. -(defun make-local-call (target) - (let ((tramp (gen-label))) - (inst call tramp) - (assemble (*elsewhere*) - (emit-label tramp) - (popw ebp-tn (frame-word-offset return-pc-save-offset)) - (inst jmp target)))) +;;; The local call convention doesn't fit that well with x86-style +;;; calls. Emit a header for local calls to pop the return address +;;; in the right place. +(defun emit-block-header (start-label trampoline-label fall-thru-p alignp) + (declare (ignore alignp)) + (when trampoline-label + (when fall-thru-p + (inst jmp start-label)) + (emit-label trampoline-label) + (popw ebp-tn (frame-word-offset return-pc-save-offset))) + (emit-label start-label)) ;;; Non-TR local call for a fixed number of values passed according to ;;; the unknown values convention. @@ -535,7 +667,7 @@ (trace-table-entry trace-table-call-site) (move ebp-tn fp) (note-this-location vop :call-site) - (make-local-call target) + (inst call target) (default-unknown-values vop values nvals node) (trace-table-entry trace-table-normal))) @@ -556,7 +688,7 @@ (trace-table-entry trace-table-call-site) (move ebp-tn fp) (note-this-location vop :call-site) - (make-local-call target) + (inst call target) (note-this-location vop :unknown-return) (receive-unknown-values values-start nvals start count node) (trace-table-entry trace-table-normal))) @@ -583,7 +715,7 @@ (trace-table-entry trace-table-call-site) (move ebp-tn fp) (note-this-location vop :call-site) - (make-local-call target) + (inst call target) (note-this-location vop :known-return) (trace-table-entry trace-table-normal))) @@ -1333,9 +1465,12 @@ ;; register on -SB-THREAD. #!+sb-thread (progn - (inst cmp (make-ea :dword - :disp (* thread-stepping-slot n-word-bytes)) - nil-value :fs)) + #!+win32 (inst push eax-tn) + (with-tls-ea (EA :base #!+win32 eax-tn #!-win32 :unused + :disp-type :constant + :disp (* thread-stepping-slot n-word-bytes)) + (inst cmp EA nil-value :maybe-fs)) + #!+win32 (inst pop eax-tn)) #!-sb-thread (inst cmp (make-ea-for-symbol-value sb!impl::*stepping*) nil-value))