Skip to content

bpo-45923: Add RESUME_QUICK #31244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 10 additions & 9 deletions Include/opcode.h

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

1 change: 1 addition & 0 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ def jabs_op(name, op):
"LOAD_METHOD_CLASS",
"LOAD_METHOD_MODULE",
"LOAD_METHOD_NO_DICT",
"RESUME_QUICK",
"STORE_ATTR_ADAPTIVE",
"STORE_ATTR_INSTANCE_VALUE",
"STORE_ATTR_SLOT",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a quickened form of :opcode:`RESUME` that skips quickening checks.
16 changes: 9 additions & 7 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1732,9 +1732,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
}

TARGET(RESUME) {
assert(tstate->cframe == &cframe);
assert(frame == cframe.current_frame);

int err = _Py_IncrementCountAndMaybeQuicken(frame->f_code);
if (err) {
if (err < 0) {
Expand All @@ -1745,6 +1742,13 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
first_instr = frame->f_code->co_firstinstr;
next_instr = first_instr + nexti;
}
JUMP_TO_INSTRUCTION(RESUME_QUICK);
}

TARGET(RESUME_QUICK) {
PREDICTED(RESUME_QUICK);
assert(tstate->cframe == &cframe);
assert(frame == cframe.current_frame);
frame->f_state = FRAME_EXECUTING;
if (_Py_atomic_load_relaxed(eval_breaker) && oparg < 2) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specializer should handle the oparg < 2.

goto handle_eval_breaker;
Expand Down Expand Up @@ -4002,7 +4006,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr

TARGET(JUMP_ABSOLUTE) {
PREDICTED(JUMP_ABSOLUTE);
assert(oparg < INSTR_OFFSET());
int err = _Py_IncrementCountAndMaybeQuicken(frame->f_code);
if (err) {
if (err < 0) {
Expand All @@ -4013,9 +4016,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
first_instr = frame->f_code->co_firstinstr;
next_instr = first_instr + nexti;
}
JUMPTO(oparg);
CHECK_EVAL_BREAKER();
DISPATCH();
JUMP_TO_INSTRUCTION(JUMP_ABSOLUTE_QUICK);
}

TARGET(JUMP_NO_INTERRUPT) {
Expand All @@ -4030,6 +4031,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
}

TARGET(JUMP_ABSOLUTE_QUICK) {
PREDICTED(JUMP_ABSOLUTE_QUICK);
assert(oparg < INSTR_OFFSET());
JUMPTO(oparg);
CHECK_EVAL_BREAKER();
Expand Down
12 changes: 6 additions & 6 deletions Python/opcode_targets.h

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

3 changes: 3 additions & 0 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ optimize(SpecializedCacheOrInstruction *quickened, int len)
case JUMP_ABSOLUTE:
instructions[i] = _Py_MAKECODEUNIT(JUMP_ABSOLUTE_QUICK, oparg);
break;
case RESUME:
instructions[i] = _Py_MAKECODEUNIT(RESUME_QUICK, oparg);
break;
case LOAD_FAST:
switch(previous_opcode) {
case LOAD_FAST:
Expand Down