From 079025559d7880311562f5af05b41b4591b0b749 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Tue, 13 Dec 2011 15:13:32 -0800 Subject: [PATCH] simplify function prologs --- basis/cpu/x86/32/32.factor | 5 ----- basis/cpu/x86/32/bootstrap.factor | 9 --------- basis/cpu/x86/64/64.factor | 6 ------ basis/cpu/x86/64/bootstrap.factor | 19 +------------------ basis/cpu/x86/64/unix/bootstrap.factor | 4 ++-- basis/cpu/x86/64/windows/bootstrap.factor | 4 ++-- basis/cpu/x86/bootstrap.factor | 4 ++++ basis/cpu/x86/x86.factor | 2 ++ vm/os-linux-x86.64.hpp | 4 ++-- vm/os-macosx-x86.64.hpp | 4 ++-- vm/os-windows.64.hpp | 4 ++-- 11 files changed, 17 insertions(+), 48 deletions(-) diff --git a/basis/cpu/x86/32/32.factor b/basis/cpu/x86/32/32.factor index 54a25310d6..c15e43c848 100755 --- a/basis/cpu/x86/32/32.factor +++ b/basis/cpu/x86/32/32.factor @@ -89,11 +89,6 @@ M: x86.32 return-regs { float-regs { ST0 } } } ; -M: x86.32 %prologue ( n -- ) - dup PUSH - 0 PUSH rc-absolute-cell rel-this - 3 cells - decr-stack-reg ; - M: x86.32 %prepare-jump pic-tail-reg 0 MOV xt-tail-pic-offset rc-absolute-cell rel-here ; diff --git a/basis/cpu/x86/32/bootstrap.factor b/basis/cpu/x86/32/bootstrap.factor index 03a39715d4..1f78c47740 100755 --- a/basis/cpu/x86/32/bootstrap.factor +++ b/basis/cpu/x86/32/bootstrap.factor @@ -37,15 +37,6 @@ IN: bootstrap.x86 : jit-call ( name -- ) 0 CALL f rc-relative rel-dlsym ; -[ - ! alignment - ESP stack-frame-size bootstrap-cell - SUB - ! store entry point - ESP stack-frame-size 3 bootstrap-cells - [+] 0 MOV rc-absolute-cell rel-this - ! store stack frame size - ESP stack-frame-size 2 bootstrap-cells - [+] stack-frame-size MOV -] jit-prolog jit-define - [ pic-tail-reg 0 MOV 0 rc-absolute-cell rel-here 0 JMP f rc-relative rel-word-pic-tail diff --git a/basis/cpu/x86/64/64.factor b/basis/cpu/x86/64/64.factor index 6c2acac628..1934b0ebb6 100644 --- a/basis/cpu/x86/64/64.factor +++ b/basis/cpu/x86/64/64.factor @@ -59,12 +59,6 @@ M: x86.64 %set-vm-field ( src offset -- ) M: x86.64 %vm-field-ptr ( dst offset -- ) [ vm-reg ] dip [+] LEA ; -M: x86.64 %prologue ( n -- ) - RAX 0 MOV rc-absolute-cell rel-this - stack-reg over cell - SUB - stack-reg over 3 cells - [+] RAX MOV - stack-reg over 2 cells - [+] swap MOV ; - M: x86.64 %prepare-jump pic-tail-reg xt-tail-pic-offset [RIP+] LEA ; diff --git a/basis/cpu/x86/64/bootstrap.factor b/basis/cpu/x86/64/bootstrap.factor index 047d15654b..b5de844f47 100755 --- a/basis/cpu/x86/64/bootstrap.factor +++ b/basis/cpu/x86/64/bootstrap.factor @@ -33,17 +33,6 @@ IN: bootstrap.x86 RAX 0 MOV f rc-absolute-cell rel-dlsym RAX CALL ; -[ - ! load entry point - RAX 0 MOV rc-absolute-cell rel-this - ! alignment - RSP stack-frame-size bootstrap-cell - SUB - ! store entry point - RSP stack-frame-size 3 bootstrap-cells - [+] RAX MOV - ! store stack frame size - RSP stack-frame-size 2 bootstrap-cells - [+] stack-frame-size MOV -] jit-prolog jit-define - [ pic-tail-reg 5 [RIP+] LEA 0 JMP f rc-relative rel-word-pic-tail @@ -96,18 +85,12 @@ IN: bootstrap.x86 :: jit-signal-handler-prolog ( -- frame-size ) signal-handler-save-regs :> save-regs - save-regs length 1 + bootstrap-cells 16 align stack-frame-size + :> frame-size - frame-size signal-handler-stack-frame-size = - [ "unexpected signal handler frame size" throw ] unless + signal-handler-stack-frame-size :> frame-size ! minus a cell each for flags, return address ! use LEA so we don't dirty flags RSP RSP frame-size 2 bootstrap-cells - neg [+] LEA save-regs [| r i | RSP i bootstrap-cells [+] r MOV ] each-index PUSHF - ! Now that the registers are saved, we can make the stack frame - RAX 0 MOV rc-absolute-cell rel-this - RSP frame-size 3 bootstrap-cells - [+] RAX MOV - RSP frame-size 2 bootstrap-cells - [+] frame-size MOV frame-size ; :: jit-signal-handler-epilog ( frame-size -- ) diff --git a/basis/cpu/x86/64/unix/bootstrap.factor b/basis/cpu/x86/64/unix/bootstrap.factor index f5265dc020..cf9415441a 100644 --- a/basis/cpu/x86/64/unix/bootstrap.factor +++ b/basis/cpu/x86/64/unix/bootstrap.factor @@ -5,8 +5,8 @@ cpu.x86.assembler.operands kernel layouts namespaces parser sequences system vocabs ; IN: bootstrap.x86 -: leaf-stack-frame-size ( -- n ) 4 bootstrap-cells ; -: signal-handler-stack-frame-size ( -- n ) 20 bootstrap-cells ; +: leaf-stack-frame-size ( -- n ) 2 bootstrap-cells ; +: signal-handler-stack-frame-size ( -- n ) 18 bootstrap-cells ; : stack-frame-size ( -- n ) 4 bootstrap-cells ; : nv-regs ( -- seq ) { RBX R12 R13 R14 R15 } ; : volatile-regs ( -- seq ) { RAX RCX RDX RSI RDI R8 R9 R10 R11 } ; diff --git a/basis/cpu/x86/64/windows/bootstrap.factor b/basis/cpu/x86/64/windows/bootstrap.factor index 00f1cc1acb..a881225103 100644 --- a/basis/cpu/x86/64/windows/bootstrap.factor +++ b/basis/cpu/x86/64/windows/bootstrap.factor @@ -7,8 +7,8 @@ IN: bootstrap.x86 DEFER: stack-reg -: leaf-stack-frame-size ( -- n ) 4 bootstrap-cells ; -: signal-handler-stack-frame-size ( -- n ) 24 bootstrap-cells ; +: leaf-stack-frame-size ( -- n ) 2 bootstrap-cells ; +: signal-handler-stack-frame-size ( -- n ) 22 bootstrap-cells ; : stack-frame-size ( -- n ) 8 bootstrap-cells ; : nv-regs ( -- seq ) { RBX RSI RDI R12 R13 R14 R15 } ; : volatile-regs ( -- seq ) { RAX RCX RDX R8 R9 R10 R11 } ; diff --git a/basis/cpu/x86/bootstrap.factor b/basis/cpu/x86/bootstrap.factor index ee84ff2dbd..d09657f33c 100644 --- a/basis/cpu/x86/bootstrap.factor +++ b/basis/cpu/x86/bootstrap.factor @@ -223,6 +223,10 @@ big-endian off temp0 word-entry-point-offset [+] JMP ] jit-execute jit-define +[ + stack-reg stack-frame-size bootstrap-cell - SUB +] jit-prolog jit-define + [ stack-reg stack-frame-size bootstrap-cell - ADD ] jit-epilog jit-define diff --git a/basis/cpu/x86/x86.factor b/basis/cpu/x86/x86.factor index 832ee51bd5..8074021429 100644 --- a/basis/cpu/x86/x86.factor +++ b/basis/cpu/x86/x86.factor @@ -515,6 +515,8 @@ M: x86 %call-gc ( gc-map -- ) M: x86 %alien-global ( dst symbol library -- ) [ 0 MOV ] 2dip rc-absolute-cell rel-dlsym ; +M: x86 %prologue ( n -- ) cell - decr-stack-reg ; + M: x86 %epilogue ( n -- ) cell - incr-stack-reg ; :: (%boolean) ( dst temp insn -- ) diff --git a/vm/os-linux-x86.64.hpp b/vm/os-linux-x86.64.hpp index 366a135751..022636012b 100644 --- a/vm/os-linux-x86.64.hpp +++ b/vm/os-linux-x86.64.hpp @@ -30,8 +30,8 @@ inline static void uap_clear_fpu_status(void *uap) /* Must match the leaf-stack-frame-size, signal-handler-stack-frame-size, and stack-frame-size constants in basis/cpu/x86/64/unix/bootstrap.factor */ -static const unsigned LEAF_FRAME_SIZE = 32; -static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 160; +static const unsigned LEAF_FRAME_SIZE = 16; +static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 144; static const unsigned JIT_FRAME_SIZE = 32; } diff --git a/vm/os-macosx-x86.64.hpp b/vm/os-macosx-x86.64.hpp index 2b1c02beb0..023dfec867 100644 --- a/vm/os-macosx-x86.64.hpp +++ b/vm/os-macosx-x86.64.hpp @@ -75,8 +75,8 @@ inline static void uap_clear_fpu_status(void *uap) /* Must match the leaf-stack-frame-size, signal-handler-stack-frame-size, and stack-frame-size constants in basis/cpu/x86/64/unix/bootstrap.factor */ -static const unsigned LEAF_FRAME_SIZE = 32; -static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 160; +static const unsigned LEAF_FRAME_SIZE = 16; +static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 144; static const unsigned JIT_FRAME_SIZE = 32; } diff --git a/vm/os-windows.64.hpp b/vm/os-windows.64.hpp index 19b43a74f5..d5171b089e 100644 --- a/vm/os-windows.64.hpp +++ b/vm/os-windows.64.hpp @@ -11,7 +11,7 @@ namespace factor /* Must match the leaf-stack-frame-size, signal-handler-stack-frame-size, and stack-frame-size constants in basis/cpu/x86/64/windows/bootstrap.factor */ -static const unsigned LEAF_FRAME_SIZE = 32; -static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 192; +static const unsigned LEAF_FRAME_SIZE = 16; +static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 176; static const unsigned JIT_FRAME_SIZE = 64; }