Skip to content

Commit 1394759

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 1394759

File tree

4 files changed

+46
-26
lines changed

4 files changed

+46
-26
lines changed

Python/ceval.c

+7
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

+26-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,7 @@ translate_bytecode_to_trace(
374374
_PyUOpInstruction *trace,
375375
int max_length)
376376
{
377-
#ifdef Py_DEBUG
378377
_Py_CODEUNIT *initial_instr = instr;
379-
#endif
380378
int trace_length = 0;
381379

382380
#ifdef Py_DEBUG
@@ -426,6 +424,18 @@ translate_bytecode_to_trace(
426424
oparg = (oparg & 0xffffff00) | executor->vm_data.oparg;
427425
}
428426
switch (opcode) {
427+
case JUMP_BACKWARD:
428+
{
429+
if (instr + 2 - oparg == initial_instr
430+
&& trace_length + 3 <= max_length)
431+
{
432+
ADD_TO_TRACE(JUMP_TO_TOP, 0);
433+
}
434+
else {
435+
DPRINTF(2, "JUMP_BACKWARD not to top ends trace\n");
436+
}
437+
goto done;
438+
}
429439
default:
430440
{
431441
const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode];

Tools/cases_generator/generate_cases.py

+1
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)