From: Taylor R Campbell Date: Fri, 4 Jan 2019 04:58:51 +0000 (+0000) Subject: Use ret for returns from interface and from generic arithmetic hooks. X-Git-Tag: mit-scheme-pucked-10.1.20~11^2~80^2~8 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=31163e25df96787629821c16ce3548b7bd6f0047;p=mit-scheme.git Use ret for returns from interface and from generic arithmetic hooks. Let's take advantage of the return address stack branch target predictor rather than unceremoniously trash it, shall we? --- diff --git a/src/microcode/cmpauxmd/x86-64.m4 b/src/microcode/cmpauxmd/x86-64.m4 index 336b98291..2a241d511 100644 --- a/src/microcode/cmpauxmd/x86-64.m4 +++ b/src/microcode/cmpauxmd/x86-64.m4 @@ -507,8 +507,8 @@ define_debugging_label(scheme_to_interface_return) define_c_label(interface_to_scheme) # rax = interface_to_scheme - # rcx = compiled entry address, needed by compiled code; 0 if return - # rdx = compiled PC + # rcx = compiled entry/return address, needed by compiled code + # rdx = compiled PC, or interface_to_scheme_return ifdef(`WIN32', # Register block = %rsi ` OP(mov,q) TW(ABS(EVR(RegistersPtr)),regs)', ` OP(lea,q) TW(ABS(EVR(Registers)),regs)') @@ -525,7 +525,12 @@ ifdef(`WIN32', # Register block = %rsi OP(mov,q) TW(REG(rax),REG(r8)) # Preserve if used OP(and,q) TW(rmask,REG(r8)) # Restore potential dynamic link OP(mov,q) TW(REG(r8),QOF(REGBLOCK_DLINK(),regs)) - jmp IJMP(REG(rdx)) # Invoke + jmp IJMP(REG(rdx)) # Invoke entry or handler + +define_c_label(interface_to_scheme_return) + # rcx = compiled return address + OP(push,q) REG(rcx) + ret # Invoke return IF_WIN32(` use_external_code(EFR(WinntExceptionTransferHook)) @@ -770,9 +775,8 @@ define_debugging_label(set_interrupt_enables_no_stackoverflow) declare_alignment(2) asm_generic_return_rax: - OP(pop,q) REG(rcx) - OP(and,q) TW(rmask,REG(rcx)) - jmp IJMP(REG(rcx)) # Invoke return + OP(and,q) TW(rmask,IND(REG(rsp))) + ret # Invoke return declare_alignment(2) asm_generic_fixnum_result: diff --git a/src/microcode/cmpint.c b/src/microcode/cmpint.c index 78f69c739..3e5ef1995 100644 --- a/src/microcode/cmpint.c +++ b/src/microcode/cmpint.c @@ -210,6 +210,7 @@ static long make_apply_trampoline extern c_func_t ASM_ENTRY_POINT (interface_to_C); extern c_func_t ASM_ENTRY_POINT (interface_to_scheme); +extern c_func_t ASM_ENTRY_POINT (interface_to_scheme_return); #define ENTER_SCHEME_ENTRY(ep) do \ { \ diff --git a/src/microcode/cmpintmd/x86-64.h b/src/microcode/cmpintmd/x86-64.h index 1c89e6caf..78fa05be0 100644 --- a/src/microcode/cmpintmd/x86-64.h +++ b/src/microcode/cmpintmd/x86-64.h @@ -165,8 +165,8 @@ typedef uint8_t insn_t; #define CC_ENTRY_ADDRESS_PTR(e) (e) #define CC_ENTRY_ADDRESS_PC(e) ((e) + (((const int64_t *) (e))[-1])) -#define CC_RETURN_ADDRESS_PTR(r) 0 -#define CC_RETURN_ADDRESS_PC(r) (r) +#define CC_RETURN_ADDRESS_PTR(r) (r) +#define CC_RETURN_ADDRESS_PC(r) ((insn_t *) interface_to_scheme_return) insn_t * cc_return_address_to_entry_address (insn_t *);