bootstrap.x86: new words jit-call-Xarg for calling vm functions with

arguments, simplifies some assembly code
db4
Björn Lindqvist 2015-05-18 15:58:07 +02:00 committed by Doug Coleman
parent 6ca83e7588
commit 528e9f61f3
2 changed files with 41 additions and 38 deletions

View File

@ -37,6 +37,21 @@ IN: bootstrap.x86
: jit-call ( name -- ) : jit-call ( name -- )
0 CALL f rc-relative rel-dlsym ; 0 CALL f rc-relative rel-dlsym ;
:: jit-call-1arg ( arg1s name -- )
ESP [] arg1s MOV
name jit-call ;
:: jit-call-2arg ( arg1s arg2s name -- )
ESP [] arg1s MOV
ESP 4 [+] arg2s MOV
name jit-call ;
:: jit-call-3arg ( arg1s arg2s arg3s name -- )
ESP [] arg1s MOV
ESP 4 [+] arg2s MOV
ESP 8 [+] arg3s MOV
name jit-call ;
[ [
pic-tail-reg 0 MOV 0 rc-absolute-cell rel-here pic-tail-reg 0 MOV 0 rc-absolute-cell rel-here
0 JMP f rc-relative rel-word-pic-tail 0 JMP f rc-relative rel-word-pic-tail
@ -79,16 +94,13 @@ IN: bootstrap.x86
[ [
jit-load-vm jit-load-vm
ESP [] vm-reg MOV
EAX EBP 8 [+] MOV EAX EBP 8 [+] MOV
ESP 4 [+] EAX MOV vm-reg EAX "begin_callback" jit-call-2arg
"begin_callback" jit-call
jit-call-quot jit-call-quot
jit-load-vm jit-load-vm
ESP [] vm-reg MOV vm-reg "end_callback" jit-call-1arg
"end_callback" jit-call
] \ c-to-factor define-sub-primitive ] \ c-to-factor define-sub-primitive
: signal-handler-save-regs ( -- regs ) : signal-handler-save-regs ( -- regs )
@ -169,12 +181,8 @@ IN: bootstrap.x86
jit-load-vm jit-load-vm
jit-save-context jit-save-context
! Store arguments ! Call VM, quotation reference is in EAX
ESP [] EAX MOV EAX vm-reg "lazy_jit_compile" jit-call-2arg
ESP 4 [+] vm-reg MOV
! Call VM
"lazy_jit_compile" jit-call
] ]
[ jit-call-quot ] [ jit-call-quot ]
[ jit-jump-quot ] [ jit-jump-quot ]
@ -245,11 +253,9 @@ IN: bootstrap.x86
[ JNO ] [ JNO ]
[ [
EBX tag-bits get SAR EBX tag-bits get SAR
ESP [] EBX MOV
ESP 4 [+] EBP MOV
jit-load-vm jit-load-vm
ESP 8 [+] vm-reg MOV
"overflow_fixnum_multiply" jit-call EBX EBP vm-reg "overflow_fixnum_multiply" jit-call-3arg
] ]
jit-conditional jit-conditional
] \ fixnum* define-sub-primitive ] \ fixnum* define-sub-primitive
@ -312,8 +318,7 @@ IN: bootstrap.x86
! Create the new context in return-reg ! Create the new context in return-reg
jit-load-vm jit-load-vm
jit-save-context jit-save-context
ESP [] vm-reg MOV vm-reg "new_context" jit-call-1arg
"new_context" jit-call
jit-save-quot-and-param jit-save-quot-and-param
@ -339,9 +344,7 @@ IN: bootstrap.x86
: jit-delete-current-context ( -- ) : jit-delete-current-context ( -- )
jit-load-vm jit-load-vm
jit-load-context jit-load-context
ESP [] vm-reg MOV vm-reg ctx-reg "delete_context" jit-call-2arg ;
ESP 4 [+] ctx-reg MOV
"delete_context" jit-call ;
[ [
jit-delete-current-context jit-delete-current-context
@ -351,9 +354,7 @@ IN: bootstrap.x86
: jit-start-context-and-delete ( -- ) : jit-start-context-and-delete ( -- )
jit-load-vm jit-load-vm
jit-load-context jit-load-context
ESP [] vm-reg MOV vm-reg ctx-reg "reset_context" jit-call-2arg
ESP 4 [+] ctx-reg MOV
"reset_context" jit-call
jit-save-quot-and-param jit-save-quot-and-param
ctx-reg jit-switch-context ctx-reg jit-switch-context

View File

@ -1,10 +1,10 @@
! Copyright (C) 2007, 2011 Slava Pestov. ! Copyright (C) 2007, 2011 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: bootstrap.image.private kernel kernel.private namespaces USING: bootstrap.image.private kernel kernel.private layouts locals namespaces
system layouts vocabs parser compiler.constants vocabs parser compiler.constants
compiler.codegen.relocation math math.private cpu.x86.assembler compiler.codegen.relocation math math.private cpu.x86.assembler
cpu.x86.assembler.operands sequences generic.single.private cpu.x86.assembler.operands sequences generic.single.private
threads.private locals ; threads.private ;
IN: bootstrap.x86 IN: bootstrap.x86
8 \ cell set 8 \ cell set
@ -33,6 +33,15 @@ IN: bootstrap.x86
RAX 0 MOV f rc-absolute-cell rel-dlsym RAX 0 MOV f rc-absolute-cell rel-dlsym
RAX CALL ; RAX CALL ;
:: jit-call-1arg ( arg1s name -- )
arg1 arg1s MOV
name jit-call ;
:: jit-call-2arg ( arg1s arg2s name -- )
arg1 arg1s MOV
arg2 arg2s MOV
name jit-call ;
[ [
pic-tail-reg 5 [RIP+] LEA pic-tail-reg 5 [RIP+] LEA
0 JMP f rc-relative rel-word-pic-tail 0 JMP f rc-relative rel-word-pic-tail
@ -74,15 +83,13 @@ IN: bootstrap.x86
[ [
arg2 arg1 MOV arg2 arg1 MOV
arg1 vm-reg MOV vm-reg "begin_callback" jit-call-1arg
"begin_callback" jit-call
! call the quotation ! call the quotation
arg1 return-reg MOV arg1 return-reg MOV
jit-call-quot jit-call-quot
arg1 vm-reg MOV vm-reg "end_callback" jit-call-1arg
"end_callback" jit-call
] \ c-to-factor define-sub-primitive ] \ c-to-factor define-sub-primitive
: signal-handler-save-regs ( -- regs ) : signal-handler-save-regs ( -- regs )
@ -280,8 +287,7 @@ IN: bootstrap.x86
! twice, first before calling new_context() which may GC, ! twice, first before calling new_context() which may GC,
! and again after popping the two parameters from the stack. ! and again after popping the two parameters from the stack.
jit-save-context jit-save-context
arg1 vm-reg MOV vm-reg "new_context" jit-call-1arg
"new_context" jit-call
jit-pop-quot-and-param jit-pop-quot-and-param
jit-save-context jit-save-context
@ -293,9 +299,7 @@ IN: bootstrap.x86
: jit-delete-current-context ( -- ) : jit-delete-current-context ( -- )
jit-load-context jit-load-context
arg1 vm-reg MOV vm-reg ctx-reg "delete_context" jit-call-2arg ;
arg2 ctx-reg MOV
"delete_context" jit-call ;
[ [
jit-delete-current-context jit-delete-current-context
@ -304,9 +308,7 @@ IN: bootstrap.x86
: jit-start-context-and-delete ( -- ) : jit-start-context-and-delete ( -- )
jit-load-context jit-load-context
arg1 vm-reg MOV vm-reg ctx-reg "reset_context" jit-call-2arg
arg2 ctx-reg MOV
"reset_context" jit-call
jit-pop-quot-and-param jit-pop-quot-and-param
ctx-reg jit-switch-context ctx-reg jit-switch-context