From ce5b401312c478c84681d4f02f00df8d937c8f15 Mon Sep 17 00:00:00 2001 From: Douglas Katzman Date: Sat, 8 Oct 2016 21:04:15 -0400 Subject: [PATCH] Add thin wrapper for calling assem code on x86-64 --- src/assembly/x86-64/arith.lisp | 4 ++-- src/assembly/x86-64/support.lisp | 16 ++++++++++------ src/compiler/x86-64/call.lisp | 8 ++++---- src/compiler/x86-64/cell.lisp | 4 ++-- src/compiler/x86-64/move.lisp | 10 ++++------ src/compiler/x86-64/nlx.lisp | 4 ++-- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/assembly/x86-64/arith.lisp b/src/assembly/x86-64/arith.lisp index 6c456f6b9..8fb7222c0 100644 --- a/src/assembly/x86-64/arith.lisp +++ b/src/assembly/x86-64/arith.lisp @@ -380,6 +380,7 @@ ;; as this vop clobbers RCX in the call. If changed to "CALL [ADDR]" ;; be sure to update the subroutine to push and pop RCX. (:temporary (:sc unsigned-reg :offset rcx-offset) rcx) + (:vop-var vop) (:generator ,cost (progn ;; POPCNT = ECX bit 23 = bit 7 of byte index 2 @@ -401,8 +402,7 @@ (inst jmp done)) slow (move rdx arg) - (inst mov rcx (make-fixup 'logcount :assembly-routine)) - (inst call rcx) + (invoke-asm-routine 'call 'logcount vop rcx) (move result rdx) done)))) (def-it unsigned-byte-64-count 14 unsigned-reg unsigned-num) diff --git a/src/assembly/x86-64/support.lisp b/src/assembly/x86-64/support.lisp index 17fff15f9..77c741046 100644 --- a/src/assembly/x86-64/support.lisp +++ b/src/assembly/x86-64/support.lisp @@ -9,6 +9,13 @@ (in-package "SB!VM") +(defun invoke-asm-routine (inst routine vop temp-reg) + (declare (ignore vop)) + (inst mov temp-reg (make-fixup routine :assembly-routine)) + (ecase inst + (jmp (inst jmp temp-reg)) + (call (inst call temp-reg)))) + (defun generate-call-sequence (name style vop options) ;; It will be nice if we can eliminate the global assumption that ;; a certain register (TEMP-REG-TN - currently R11) is always available. @@ -17,21 +24,18 @@ (:raw (values `((note-this-location ,vop :call-site) - (inst mov ,call-tn (make-fixup ',name :assembly-routine)) - (inst call ,call-tn) + (invoke-asm-routine 'call ',name ,vop ,call-tn) (note-this-location ,vop :single-value-return)) nil)) (:full-call (values `((note-this-location ,vop :call-site) - (inst mov ,call-tn (make-fixup ',name :assembly-routine)) - (inst call ,call-tn) + (invoke-asm-routine 'call ',name ,vop ,call-tn) (note-this-location ,vop :single-value-return)) '((:save-p :compute-only)))) (:none (values - `((inst mov ,call-tn (make-fixup ',name :assembly-routine)) - (inst jmp ,call-tn)) + `((invoke-asm-routine 'jmp ',name ,vop ,call-tn)) nil))))) (defun generate-return-sequence (style) diff --git a/src/compiler/x86-64/call.lisp b/src/compiler/x86-64/call.lisp index d41caf2cb..f34fdb01d 100644 --- a/src/compiler/x86-64/call.lisp +++ b/src/compiler/x86-64/call.lisp @@ -884,14 +884,14 @@ (:temporary (:sc unsigned-reg :offset rsi-offset :from (:argument 0)) rsi) (:temporary (:sc unsigned-reg :offset rax-offset :from (:argument 1)) rax) (:temporary (:sc unsigned-reg) call-target) + (:vop-var vop) (:generator 75 (check-ocfp-and-return-pc old-fp return-pc) ;; Move these into the passing locations if they are not already there. (move rsi args) (move rax function) ;; And jump to the assembly routine. - (inst mov call-target (make-fixup 'tail-call-variable :assembly-routine)) - (inst jmp call-target))) + (invoke-asm-routine 'jmp 'tail-call-variable vop call-target))) ;;;; unknown values return @@ -1011,6 +1011,7 @@ (:temporary (:sc descriptor-reg :offset (first *register-arg-offsets*) :from (:eval 0)) a0) (:node-var node) + (:vop-var vop) (:generator 13 (check-ocfp-and-return-pc old-fp return-pc) (unless (policy node (> space speed)) @@ -1031,8 +1032,7 @@ (emit-label not-single))) (move rsi vals) (move rcx nvals) - (inst mov return-asm (make-fixup 'return-multiple :assembly-routine)) - (inst jmp return-asm))) + (invoke-asm-routine 'jmp 'return-multiple vop return-asm))) ;;;; XEP hackery diff --git a/src/compiler/x86-64/cell.lisp b/src/compiler/x86-64/cell.lisp index ae5195a93..ea50ad1e6 100644 --- a/src/compiler/x86-64/cell.lisp +++ b/src/compiler/x86-64/cell.lisp @@ -373,6 +373,7 @@ (symbol :scs (descriptor-reg))) (:temporary (:sc unsigned-reg :offset rax-offset) tls-index) (:temporary (:sc unsigned-reg) bsp tmp) + (:vop-var vop) (:generator 10 (load-binding-stack-pointer bsp) (inst mov (reg-in-size tls-index :dword) (tls-index-of symbol)) @@ -381,8 +382,7 @@ (inst test (reg-in-size tls-index :dword) (reg-in-size tls-index :dword)) (inst jmp :ne TLS-INDEX-VALID) (inst mov tls-index symbol) - (inst mov tmp (make-fixup 'alloc-tls-index :assembly-routine)) - (inst call tmp) + (invoke-asm-routine 'call 'alloc-tls-index vop tmp) TLS-INDEX-VALID (inst mov tmp (make-ea :qword :base thread-base-tn :index tls-index)) (storew tmp bsp (- binding-value-slot binding-size)) diff --git a/src/compiler/x86-64/move.lisp b/src/compiler/x86-64/move.lisp index aa9a5af7b..2bacac09d 100644 --- a/src/compiler/x86-64/move.lisp +++ b/src/compiler/x86-64/move.lisp @@ -259,6 +259,7 @@ (:results (y :scs (any-reg descriptor-reg) . #.(and (> n-fixnum-tag-bits 1) '(:from :argument)))) (:note "signed word to integer coercion") + (:vop-var vop) ;; Worst case cost to make sure people know they may be number consing. (:generator 20 (cond ((= 1 n-fixnum-tag-bits) @@ -273,9 +274,7 @@ (inst imul y x #.(ash 1 n-fixnum-tag-bits)) (inst jmp :no DONE) (inst mov y x))) - (inst mov temp-reg-tn - (make-fixup #.(bignum-from-reg 'y "SIGNED") :assembly-routine)) - (inst call temp-reg-tn) + (invoke-asm-routine 'call #.(bignum-from-reg 'y "SIGNED") vop temp-reg-tn) DONE)) (define-move-vop move-from-signed :move (signed-reg) (descriptor-reg)) @@ -287,6 +286,7 @@ (:args (x :scs (signed-reg unsigned-reg) :to :result)) (:results (y :scs (any-reg descriptor-reg) :from :argument)) (:note "unsigned word to integer coercion") + (:vop-var vop) ;; Worst case cost to make sure people know they may be number consing. (:generator 20 (aver (not (location= x y))) @@ -306,9 +306,7 @@ :scale (ash 1 n-fixnum-tag-bits)))) (inst jmp :z done) (inst mov y x) - (inst mov temp-reg-tn - (make-fixup #.(bignum-from-reg 'y "UNSIGNED") :assembly-routine)) - (inst call temp-reg-tn) + (invoke-asm-routine 'call #.(bignum-from-reg 'y "UNSIGNED") vop temp-reg-tn) DONE)) (define-move-vop move-from-unsigned :move (unsigned-reg) (descriptor-reg)) diff --git a/src/compiler/x86-64/nlx.lisp b/src/compiler/x86-64/nlx.lisp index 62e82590e..b94093c63 100644 --- a/src/compiler/x86-64/nlx.lisp +++ b/src/compiler/x86-64/nlx.lisp @@ -237,6 +237,7 @@ (:temporary (:sc sap-reg) temp) (:temporary (:sc descriptor-reg :offset rbx-offset) saved-function) (:temporary (:sc unsigned-reg :offset rax-offset) block) + (:vop-var vop) (:generator 22 ;; Store the function into a non-stack location, since we'll be ;; unwinding the stack and destroying register contents before we @@ -257,8 +258,7 @@ (storew temp-reg-tn block unwind-block-entry-pc-slot) ;; Run any required UWPs. - (inst mov temp-reg-tn (make-fixup 'unwind :assembly-routine)) - (inst jmp temp-reg-tn) + (invoke-asm-routine 'jmp 'unwind vop temp-reg-tn) ENTRY-LABEL ;; Move our saved function to where we want it now. -- 2.11.4.GIT