Use ret for returns from interface and from generic arithmetic hooks.
authorTaylor R Campbell <campbell@mumble.net>
Fri, 4 Jan 2019 04:58:51 +0000 (04:58 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Tue, 13 Aug 2019 14:37:03 +0000 (14:37 +0000)
Let's take advantage of the return address stack branch target
predictor rather than unceremoniously trash it, shall we?

src/microcode/cmpauxmd/x86-64.m4
src/microcode/cmpint.c
src/microcode/cmpintmd/x86-64.h

index 336b98291a06c121b6e6be810e262a7fa1799b99..2a241d511f130ba381dab5e8251f09504f20bcdc 100644 (file)
@@ -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:
index 78f69c7391277500408dcd52e8959f2a5d080525..3e5ef199552b7418301602b36dd49b14c9338673 100644 (file)
@@ -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                                      \
 {                                                                      \
index 1c89e6caf83924755656fccf25cbd44b7e09baf7..78fa05be0f9fe36bdf0dada5a3e94c58900ea695 100644 (file)
@@ -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 *);