Skip to content

Commit

Permalink
Support JUMP_BACKWARD
Browse files Browse the repository at this point in the history
This is not very useful right now.
It would need either FOR_ITER[_RANGE, etc.] or POP_JUMP_IF_XXX.
  • Loading branch information
gvanrossum committed Jul 8, 2023
1 parent 6e6a4cd commit d5a482d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
7 changes: 7 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,13 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
#define ENABLE_SPECIALIZATION 0
#include "executor_cases.c.h"

case JUMP_TO_TOP:
{
pc = 0;
CHECK_EVAL_BREAKER();
break;
}

case SAVE_IP:
{
frame->prev_instr = ip_offset + oparg;
Expand Down
50 changes: 26 additions & 24 deletions Python/opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,18 @@ translate_bytecode_to_trace(
oparg = (oparg & 0xffffff00) | executor->vm_data.oparg;
}
switch (opcode) {
case JUMP_BACKWARD:
{
if (instr + 2 - oparg == initial_instr
&& trace_length + 3 <= max_length)
{
ADD_TO_TRACE(JUMP_TO_TOP, 0);
}
else {
DPRINTF(2, "JUMP_BACKWARD not to top ends trace\n");
}
goto done;
}
default:
{
const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode];
Expand Down
1 change: 1 addition & 0 deletions Tools/cases_generator/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ def add(name: str) -> None:
counter += 1
add("EXIT_TRACE")
add("SAVE_IP")
add("JUMP_TO_TOP")
for instr in self.instrs.values():
if instr.kind == "op" and instr.is_viable_uop():
add(instr.name)
Expand Down

0 comments on commit d5a482d

Please sign in to comment.