Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Here's what it would look like with _POP_JUMP_IF_XXX uops
  • Loading branch information
gvanrossum committed Jul 9, 2023
commit bf19586ec555209e309b0375d8b81ab4f87d9578
2 changes: 1 addition & 1 deletion Lib/test/test_capi/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2541,7 +2541,7 @@ def testfunc(n):
ex = get_first_executor(testfunc.__code__)
self.assertIsNotNone(ex)
uops = {opname for opname, _ in ex}
self.assertIn("JUMP_IF_FALSE", uops)
self.assertIn("_POP_JUMP_IF_FALSE", uops)


if __name__ == "__main__":
Expand Down
17 changes: 13 additions & 4 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2768,35 +2768,44 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
#define ENABLE_SPECIALIZATION 0
#include "executor_cases.c.h"

case JUMP_IF_FALSE:
// NOTE: These pop-jumps move the uop pc, not the bytecode ip
case _POP_JUMP_IF_FALSE:
{
if (Py_IsFalse(stack_pointer[-1])) {
pc = oparg;
}
stack_pointer--;
break;
}

case JUMP_IF_TRUE:
case _POP_JUMP_IF_TRUE:
{
if (Py_IsTrue(stack_pointer[-1])) {
pc = oparg;
}
stack_pointer--;
break;
}

case JUMP_IF_NONE:
case _POP_JUMP_IF_NONE:
{
if (Py_IsNone(stack_pointer[-1])) {
pc = oparg;
}
else {
Py_DECREF(stack_pointer[-1]);
}
stack_pointer--;
break;
}

case JUMP_IF_NOT_NONE:
case _POP_JUMP_IF_NOT_NONE:
{
if (!Py_IsNone(stack_pointer[-1])) {
pc = oparg;
Py_DECREF(stack_pointer[-1]);
}
stack_pointer--;
break;
}

Expand Down
16 changes: 8 additions & 8 deletions Python/opcode_metadata.h

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

14 changes: 6 additions & 8 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,18 +438,16 @@ translate_bytecode_to_trace(
case POP_JUMP_IF_FALSE:
{
// Assume jump unlikely (TODO: handle jump likely case)
// Reserve 7 entries (2 here, 3 stub, plus SAVE_IP + EXIT_TRACE)
if (trace_length + 7 > max_length) {
// Reserve 5 entries (1 here, 2 stub, plus SAVE_IP + EXIT_TRACE)
if (trace_length + 5 > max_length) {
DPRINTF(1, "Ran out of space for POP_JUMP_IF_FALSE\n");
goto done;
}
_Py_CODEUNIT *target_instr = instr + 1 + _PyOpcode_Caches[_PyOpcode_Deopt[opcode]] + oparg;
max_length -= 3; // Really the start of the stubs
ADD_TO_TRACE(JUMP_IF_FALSE, max_length);
ADD_TO_TRACE(POP_TOP, 0);
ADD_TO_STUB(max_length, POP_TOP, 0);
ADD_TO_STUB(max_length + 1, SAVE_IP, target_instr - (_Py_CODEUNIT *)code->co_code_adaptive);
ADD_TO_STUB(max_length + 2, EXIT_TRACE, 0);
max_length -= 2; // Really the start of the stubs
ADD_TO_TRACE(_POP_JUMP_IF_FALSE, max_length);
ADD_TO_STUB(max_length, SAVE_IP, target_instr - (_Py_CODEUNIT *)code->co_code_adaptive);
ADD_TO_STUB(max_length + 1, EXIT_TRACE, 0);
break;
}

Expand Down
8 changes: 4 additions & 4 deletions Tools/cases_generator/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,10 +1346,10 @@ def add(name: str) -> None:

add("EXIT_TRACE")
add("SAVE_IP")
add("JUMP_IF_FALSE")
add("JUMP_IF_TRUE")
add("JUMP_IF_NONE")
add("JUMP_IF_NOT_NONE")
add("_POP_JUMP_IF_FALSE")
add("_POP_JUMP_IF_TRUE")
add("_POP_JUMP_IF_NONE")
add("_POP_JUMP_IF_NOT_NONE")

for instr in self.instrs.values():
if instr.kind == "op" and instr.is_viable_uop():
Expand Down