Skip to content

Commit d5a482d

Browse files
committed
Support JUMP_BACKWARD
This is not very useful right now. It would need either FOR_ITER[_RANGE, etc.] or POP_JUMP_IF_XXX.
1 parent 6e6a4cd commit d5a482d

File tree

4 files changed

+46
-24
lines changed

4 files changed

+46
-24
lines changed

Python/ceval.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,6 +2767,13 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
27672767
#define ENABLE_SPECIALIZATION 0
27682768
#include "executor_cases.c.h"
27692769

2770+
case JUMP_TO_TOP:
2771+
{
2772+
pc = 0;
2773+
CHECK_EVAL_BREAKER();
2774+
break;
2775+
}
2776+
27702777
case SAVE_IP:
27712778
{
27722779
frame->prev_instr = ip_offset + oparg;

Python/opcode_metadata.h

Lines changed: 26 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,18 @@ translate_bytecode_to_trace(
426426
oparg = (oparg & 0xffffff00) | executor->vm_data.oparg;
427427
}
428428
switch (opcode) {
429+
case JUMP_BACKWARD:
430+
{
431+
if (instr + 2 - oparg == initial_instr
432+
&& trace_length + 3 <= max_length)
433+
{
434+
ADD_TO_TRACE(JUMP_TO_TOP, 0);
435+
}
436+
else {
437+
DPRINTF(2, "JUMP_BACKWARD not to top ends trace\n");
438+
}
439+
goto done;
440+
}
429441
default:
430442
{
431443
const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode];

Tools/cases_generator/generate_cases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,7 @@ def add(name: str) -> None:
13441344
counter += 1
13451345
add("EXIT_TRACE")
13461346
add("SAVE_IP")
1347+
add("JUMP_TO_TOP")
13471348
for instr in self.instrs.values():
13481349
if instr.kind == "op" and instr.is_viable_uop():
13491350
add(instr.name)

0 commit comments

Comments
 (0)