From: Taylor R Campbell Date: Thu, 27 Dec 2018 03:58:50 +0000 (+0000) Subject: Eliminate return/entry compiled invocation pun. X-Git-Tag: mit-scheme-pucked-10.1.20~11^2~80^2~26 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=a91ec28ab2a9097938d79699a37fa51f62234733;p=mit-scheme.git Eliminate return/entry compiled invocation pun. There is a small cost to this. My hope is that it will be offset by: 1. distinguishing compiled entries from compiled return addresses, in order to enable... 2. using indirection for compiled entries so closures don't need dynamically generated code, and finally... 3. using direct instruction addresses for compiled return addresses so we can exploit the return stack branch predictor, which all requires this change in order to function correctly. No change to compiled code interface intended. --- diff --git a/src/microcode/cmpint.c b/src/microcode/cmpint.c index c2865a8f0..e3a77c6e7 100644 --- a/src/microcode/cmpint.c +++ b/src/microcode/cmpint.c @@ -66,13 +66,18 @@ typedef struct unsigned long n_linked_entries; } link_cc_state_t; -/* Ways to bypass the interpreter */ +/* Ways to bypass the interpreter. Matches + code/special-compiled/... in runtime/conpar.scm. */ typedef enum { REFLECT_CODE_INTERNAL_APPLY, REFLECT_CODE_RESTORE_INTERRUPT_MASK, REFLECT_CODE_STACK_MARKER, - REFLECT_CODE_CC_BKPT + REFLECT_CODE_CC_BKPT, + REFLECT_CODE_UNUSED_4, /* Formerly used for v8 microcode. */ + REFLECT_CODE_UNUSED_5, + REFLECT_CODE_APPLY_COMPILED, + REFLECT_CODE_UNUSED_7, } reflect_code_t; #define PUSH_REFLECTION(code) do \ @@ -1528,9 +1533,8 @@ setup_compiled_invocation_from_primitive (SCHEME_OBJECT procedure, } PRIMITIVE_ABORT (code); } - /* Pun: procedure is being invoked as a return address. Assumes - that the primitive is being called from compiled code. */ STACK_PUSH (procedure); + PUSH_REFLECTION (REFLECT_CODE_APPLY_COMPILED); } /* Adjust the stack frame for applying a compiled procedure. Returns @@ -2081,6 +2085,12 @@ DEFINE_TRAMPOLINE (comutil_reflect_to_interface) switch (OBJECT_DATUM (code)) { + case REFLECT_CODE_APPLY_COMPILED: + { + SCHEME_OBJECT procedure = (STACK_POP ()); + RETURN_TO_SCHEME (CC_ENTRY_ADDRESS (procedure)); + } + case REFLECT_CODE_INTERNAL_APPLY: { unsigned long frame_size = (OBJECT_DATUM (STACK_POP ())); diff --git a/src/runtime/conpar.scm b/src/runtime/conpar.scm index 097401c11..83d3525e3 100644 --- a/src/runtime/conpar.scm +++ b/src/runtime/conpar.scm @@ -350,6 +350,8 @@ USA. (parser-state/next-control-point state) (parser-state/previous-type state)))) +;; reflect_to_interface codes. Matches enum reflect_code_t in +;; microcode/cmpint.c. (define-integrable code/special-compiled/internal-apply 0) (define-integrable code/special-compiled/restore-interrupt-mask 1) (define-integrable code/special-compiled/stack-marker 2)