From 66a80444ae0aac41007e626ecb1801200be50fe5 Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 20 Jun 2024 15:55:38 -0700 Subject: [PATCH 1/4] Make _JUMP_TO_TOP a general absolute jump --- Python/bytecodes.c | 4 +--- Python/executor_cases.c.h | 4 +--- Python/optimizer.c | 3 ++- Tools/jit/template.c | 3 --- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 50444bcc0d200c..f53c82664c336a 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -4149,9 +4149,7 @@ dummy_func( } op(_JUMP_TO_TOP, (--)) { -#ifndef _Py_JIT - next_uop = ¤t_executor->trace[1]; -#endif + JUMP_TO_JUMP_TARGET(); } tier2 op(_SET_IP, (instr_ptr/4 --)) { diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index b4e5261f57ab8b..3ba54f860f6e26 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -4302,9 +4302,7 @@ } case _JUMP_TO_TOP: { - #ifndef _Py_JIT - next_uop = ¤t_executor->trace[1]; - #endif + JUMP_TO_JUMP_TARGET(); break; } diff --git a/Python/optimizer.c b/Python/optimizer.c index c9b187d2e108dd..b8f8572829460f 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -717,7 +717,8 @@ translate_bytecode_to_trace( if (target == initial_instr) { /* We have looped round to the start */ RESERVE(1); - ADD_TO_TRACE(_JUMP_TO_TOP, 0, 0, 0); + // 0th instruction is _START_EXECUTOR, so jump to the 1st: + ADD_TO_TRACE(_JUMP_TO_TOP, 0, 0, 1); } else { OPT_STAT_INC(inner_loop); diff --git a/Tools/jit/template.c b/Tools/jit/template.c index a81e866e9da4b3..813e586bd3c03d 100644 --- a/Tools/jit/template.c +++ b/Tools/jit/template.c @@ -105,9 +105,6 @@ _JIT_ENTRY(_PyInterpreterFrame *frame, PyObject **stack_pointer, PyThreadState * UOP_STAT_INC(uopcode, execution_count); // The actual instruction definitions (only one will be used): - if (uopcode == _JUMP_TO_TOP) { - PATCH_JUMP(_JIT_TOP); - } switch (uopcode) { #include "executor_cases.c.h" default: From 2644079643c151906671b50dc80f470d0e5f9885 Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 20 Jun 2024 16:05:08 -0700 Subject: [PATCH 2/4] Fix debug interpreter builds --- Python/optimizer.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Python/optimizer.c b/Python/optimizer.c index b8f8572829460f..036a6de4cc7ca1 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -717,8 +717,7 @@ translate_bytecode_to_trace( if (target == initial_instr) { /* We have looped round to the start */ RESERVE(1); - // 0th instruction is _START_EXECUTOR, so jump to the 1st: - ADD_TO_TRACE(_JUMP_TO_TOP, 0, 0, 1); + ADD_TO_TRACE(_JUMP_TO_TOP, 0, 0, 0); } else { OPT_STAT_INC(inner_loop); @@ -1060,6 +1059,11 @@ prepare_for_execution(_PyUOpInstruction *buffer, int length) buffer[i].jump_target = 0; } } + if (opcode == _JUMP_TO_TOP) { + // 0th instruction is _START_EXECUTOR, so jump to the 1st: + buffer[i].format = UOP_FORMAT_JUMP; + buffer[i].jump_target = 1; + } } return next_spare; } From 7bff5127f62a32df2ccdbf813f13cfdbf40de6dd Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 20 Jun 2024 16:10:40 -0700 Subject: [PATCH 3/4] Remove unneeded code for _JIT_TOP patching --- Tools/jit/_stencils.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Tools/jit/_stencils.py b/Tools/jit/_stencils.py index 6e046df3026ae9..00c4efde4124db 100644 --- a/Tools/jit/_stencils.py +++ b/Tools/jit/_stencils.py @@ -42,8 +42,6 @@ class HoleValue(enum.Enum): ERROR_TARGET = enum.auto() # The index of the exit to be jumped through (exposed as _JIT_EXIT_INDEX): EXIT_INDEX = enum.auto() - # The base address of the machine code for the first uop (exposed as _JIT_TOP): - TOP = enum.auto() # A hardcoded value of zero (used for symbol lookups): ZERO = enum.auto() @@ -110,7 +108,6 @@ class HoleValue(enum.Enum): HoleValue.JUMP_TARGET: "instruction_starts[instruction->jump_target]", HoleValue.ERROR_TARGET: "instruction_starts[instruction->error_target]", HoleValue.EXIT_INDEX: "instruction->exit_index", - HoleValue.TOP: "instruction_starts[1]", HoleValue.ZERO: "", } From 5d382dcd9c168a37c70b0a00afa20cf4fa05054d Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Fri, 21 Jun 2024 12:01:13 -0700 Subject: [PATCH 4/4] Turn comment into an assertion --- Python/optimizer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/optimizer.c b/Python/optimizer.c index 036a6de4cc7ca1..0d7118cd9e3363 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -1060,7 +1060,7 @@ prepare_for_execution(_PyUOpInstruction *buffer, int length) } } if (opcode == _JUMP_TO_TOP) { - // 0th instruction is _START_EXECUTOR, so jump to the 1st: + assert(buffer[0].opcode == _START_EXECUTOR); buffer[i].format = UOP_FORMAT_JUMP; buffer[i].jump_target = 1; }