Skip to content

Commit d7a5aca

Browse files
authored
bpo-45923: Add RESUME_QUICK (GH-31244)
1 parent 1a6411f commit d7a5aca

File tree

6 files changed

+30
-22
lines changed

6 files changed

+30
-22
lines changed

Include/opcode.h

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

Lib/opcode.py

+1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def jabs_op(name, op):
278278
"LOAD_METHOD_CLASS",
279279
"LOAD_METHOD_MODULE",
280280
"LOAD_METHOD_NO_DICT",
281+
"RESUME_QUICK",
281282
"STORE_ATTR_ADAPTIVE",
282283
"STORE_ATTR_INSTANCE_VALUE",
283284
"STORE_ATTR_SLOT",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a quickened form of :opcode:`RESUME` that skips quickening checks.

Python/ceval.c

+9-7
Original file line numberDiff line numberDiff line change
@@ -1734,9 +1734,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
17341734
}
17351735

17361736
TARGET(RESUME) {
1737-
assert(tstate->cframe == &cframe);
1738-
assert(frame == cframe.current_frame);
1739-
17401737
int err = _Py_IncrementCountAndMaybeQuicken(frame->f_code);
17411738
if (err) {
17421739
if (err < 0) {
@@ -1747,6 +1744,13 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
17471744
first_instr = frame->f_code->co_firstinstr;
17481745
next_instr = first_instr + nexti;
17491746
}
1747+
JUMP_TO_INSTRUCTION(RESUME_QUICK);
1748+
}
1749+
1750+
TARGET(RESUME_QUICK) {
1751+
PREDICTED(RESUME_QUICK);
1752+
assert(tstate->cframe == &cframe);
1753+
assert(frame == cframe.current_frame);
17501754
frame->f_state = FRAME_EXECUTING;
17511755
if (_Py_atomic_load_relaxed(eval_breaker) && oparg < 2) {
17521756
goto handle_eval_breaker;
@@ -4004,7 +4008,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
40044008

40054009
TARGET(JUMP_ABSOLUTE) {
40064010
PREDICTED(JUMP_ABSOLUTE);
4007-
assert(oparg < INSTR_OFFSET());
40084011
int err = _Py_IncrementCountAndMaybeQuicken(frame->f_code);
40094012
if (err) {
40104013
if (err < 0) {
@@ -4015,9 +4018,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
40154018
first_instr = frame->f_code->co_firstinstr;
40164019
next_instr = first_instr + nexti;
40174020
}
4018-
JUMPTO(oparg);
4019-
CHECK_EVAL_BREAKER();
4020-
DISPATCH();
4021+
JUMP_TO_INSTRUCTION(JUMP_ABSOLUTE_QUICK);
40214022
}
40224023

40234024
TARGET(JUMP_NO_INTERRUPT) {
@@ -4032,6 +4033,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
40324033
}
40334034

40344035
TARGET(JUMP_ABSOLUTE_QUICK) {
4036+
PREDICTED(JUMP_ABSOLUTE_QUICK);
40354037
assert(oparg < INSTR_OFFSET());
40364038
JUMPTO(oparg);
40374039
CHECK_EVAL_BREAKER();

Python/opcode_targets.h

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

Python/specialize.c

+3
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ optimize(SpecializedCacheOrInstruction *quickened, int len)
407407
case JUMP_ABSOLUTE:
408408
instructions[i] = _Py_MAKECODEUNIT(JUMP_ABSOLUTE_QUICK, oparg);
409409
break;
410+
case RESUME:
411+
instructions[i] = _Py_MAKECODEUNIT(RESUME_QUICK, oparg);
412+
break;
410413
case LOAD_FAST:
411414
switch(previous_opcode) {
412415
case LOAD_FAST:

0 commit comments

Comments
 (0)