Skip to content

Commit aa2b0df

Browse files
committed
Make jump targets local instead of extern
1 parent 0240ef4 commit aa2b0df

File tree

5 files changed

+11
-22
lines changed

5 files changed

+11
-22
lines changed

Tools/jit/_optimizers.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,3 @@ class OptimizerX86(Optimizer): # pylint: disable = too-few-public-methods
302302
_re_jump = re.compile(r"\s*jmp\s+(?P<target>[\w.]+)")
303303
# https://www.felixcloutier.com/x86/ret
304304
_re_return = re.compile(r"\s*ret\b")
305-
306-
307-
class OptimizerX8664Windows(OptimizerX86): # pylint: disable = too-few-public-methods
308-
"""x86_64-pc-windows-msvc"""
309-
310-
def _preprocess(self, text: str) -> str:
311-
text = super()._preprocess(text)
312-
# Before:
313-
# rex64 jmpq *__imp__JIT_CONTINUE(%rip)
314-
# After:
315-
# jmp _JIT_CONTINUE
316-
far_indirect_jump = (
317-
rf"rex64\s+jmpq\s+\*__imp_(?P<target>{self.prefix}_JIT_\w+)\(%rip\)"
318-
)
319-
return re.sub(far_indirect_jump, r"jmp\t\g<target>", text)

Tools/jit/_targets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
555555
elif re.fullmatch(r"x86_64-pc-windows-msvc", host):
556556
args = ["-fms-runtime-lib=dll"]
557557
condition = "defined(_M_X64)"
558-
optimizer = _optimizers.OptimizerX8664Windows
558+
optimizer = _optimizers.OptimizerX86
559559
target = _COFF(host, condition, args=args, optimizer=optimizer)
560560
elif re.fullmatch(r"x86_64-.*-linux-gnu", host):
561561
args = ["-fno-pic", "-mcmodel=medium", "-mlarge-data-threshold=0"]

Tools/jit/jit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ typedef jit_func __attribute__((preserve_none)) jit_func_preserve_none;
66
#define PATCH_VALUE(TYPE, NAME, ALIAS) \
77
PyAPI_DATA(void) ALIAS; \
88
TYPE NAME = (TYPE)(uintptr_t)&ALIAS;
9+
10+
#define DECLARE_TARGET(NAME) \
11+
_Py_CODEUNIT *__attribute__((preserve_none)) \
12+
NAME(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate);

Tools/jit/shim.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ _Py_CODEUNIT *
1010
_JIT_ENTRY(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate)
1111
{
1212
// Note that this is *not* a tail call:
13-
PATCH_VALUE(jit_func_preserve_none, call, _JIT_CONTINUE);
14-
return call(frame, stack_pointer, tstate);
13+
DECLARE_TARGET(_JIT_CONTINUE);
14+
return _JIT_CONTINUE(frame, stack_pointer, tstate);
1515
}

Tools/jit/template.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ do { \
7474
do { \
7575
} while (0)
7676

77-
#define PATCH_JUMP(ALIAS) \
78-
do { \
79-
PATCH_VALUE(jit_func_preserve_none, jump, ALIAS); \
80-
__attribute__((musttail)) return jump(frame, stack_pointer, tstate); \
77+
#define PATCH_JUMP(ALIAS) \
78+
do { \
79+
DECLARE_TARGET(ALIAS); \
80+
__attribute__((musttail)) return ALIAS(frame, stack_pointer, tstate); \
8181
} while (0)
8282

8383
#undef JUMP_TO_JUMP_TARGET

0 commit comments

Comments
 (0)