[Python-checkins] bpo-45923: Add `RESUME_QUICK` (GH-31244)
markshannon
webhook-mailer at python.org
Thu Feb 10 12:50:24 EST 2022
https://github.com/python/cpython/commit/d7a5aca982def155a9255893cefcc1493c127c9c
commit: d7a5aca982def155a9255893cefcc1493c127c9c
branch: main
author: Brandt Bucher <brandtbucher at microsoft.com>
committer: markshannon <mark at hotpy.org>
date: 2022-02-10T17:50:02Z
summary:
bpo-45923: Add `RESUME_QUICK` (GH-31244)
files:
A Misc/NEWS.d/next/Core and Builtins/2022-02-09-20-21-43.bpo-45923.tJ4gDX.rst
M Include/opcode.h
M Lib/opcode.py
M Python/ceval.c
M Python/opcode_targets.h
M Python/specialize.c
diff --git a/Include/opcode.h b/Include/opcode.h
index bce7010ab186b..58fc62808937f 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -164,15 +164,16 @@ extern "C" {
#define LOAD_METHOD_CLASS 76
#define LOAD_METHOD_MODULE 77
#define LOAD_METHOD_NO_DICT 78
-#define STORE_ATTR_ADAPTIVE 79
-#define STORE_ATTR_INSTANCE_VALUE 80
-#define STORE_ATTR_SLOT 81
-#define STORE_ATTR_WITH_HINT 131
-#define LOAD_FAST__LOAD_FAST 140
-#define STORE_FAST__LOAD_FAST 141
-#define LOAD_FAST__LOAD_CONST 143
-#define LOAD_CONST__LOAD_FAST 150
-#define STORE_FAST__STORE_FAST 153
+#define RESUME_QUICK 79
+#define STORE_ATTR_ADAPTIVE 80
+#define STORE_ATTR_INSTANCE_VALUE 81
+#define STORE_ATTR_SLOT 131
+#define STORE_ATTR_WITH_HINT 140
+#define LOAD_FAST__LOAD_FAST 141
+#define STORE_FAST__LOAD_FAST 143
+#define LOAD_FAST__LOAD_CONST 150
+#define LOAD_CONST__LOAD_FAST 153
+#define STORE_FAST__STORE_FAST 154
#define DO_TRACING 255
#ifdef NEED_OPCODE_JUMP_TABLES
static uint32_t _PyOpcode_RelativeJump[8] = {
diff --git a/Lib/opcode.py b/Lib/opcode.py
index c672aa59f8ec3..a1f0c6e4326d1 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -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",
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-09-20-21-43.bpo-45923.tJ4gDX.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-09-20-21-43.bpo-45923.tJ4gDX.rst
new file mode 100644
index 0000000000000..5ab5d59e50f00
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-09-20-21-43.bpo-45923.tJ4gDX.rst
@@ -0,0 +1 @@
+Add a quickened form of :opcode:`RESUME` that skips quickening checks.
diff --git a/Python/ceval.c b/Python/ceval.c
index ffce6b735c1c2..5eb91502c3010 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1734,9 +1734,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) {
@@ -1747,6 +1744,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) {
goto handle_eval_breaker;
@@ -4004,7 +4008,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) {
@@ -4015,9 +4018,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) {
@@ -4032,6 +4033,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();
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index 1a809ed409d58..f47da2bbb1ef0 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -78,9 +78,9 @@ static void *opcode_targets[256] = {
&&TARGET_LOAD_METHOD_CLASS,
&&TARGET_LOAD_METHOD_MODULE,
&&TARGET_LOAD_METHOD_NO_DICT,
+ &&TARGET_RESUME_QUICK,
&&TARGET_STORE_ATTR_ADAPTIVE,
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
- &&TARGET_STORE_ATTR_SLOT,
&&TARGET_LIST_TO_TUPLE,
&&TARGET_RETURN_VALUE,
&&TARGET_IMPORT_STAR,
@@ -130,7 +130,7 @@ static void *opcode_targets[256] = {
&&TARGET_POP_JUMP_IF_NOT_NONE,
&&TARGET_POP_JUMP_IF_NONE,
&&TARGET_RAISE_VARARGS,
- &&TARGET_STORE_ATTR_WITH_HINT,
+ &&TARGET_STORE_ATTR_SLOT,
&&TARGET_MAKE_FUNCTION,
&&TARGET_BUILD_SLICE,
&&TARGET_JUMP_NO_INTERRUPT,
@@ -139,21 +139,21 @@ static void *opcode_targets[256] = {
&&TARGET_LOAD_DEREF,
&&TARGET_STORE_DEREF,
&&TARGET_DELETE_DEREF,
+ &&TARGET_STORE_ATTR_WITH_HINT,
&&TARGET_LOAD_FAST__LOAD_FAST,
- &&TARGET_STORE_FAST__LOAD_FAST,
&&TARGET_CALL_FUNCTION_EX,
- &&TARGET_LOAD_FAST__LOAD_CONST,
+ &&TARGET_STORE_FAST__LOAD_FAST,
&&TARGET_EXTENDED_ARG,
&&TARGET_LIST_APPEND,
&&TARGET_SET_ADD,
&&TARGET_MAP_ADD,
&&TARGET_LOAD_CLASSDEREF,
&&TARGET_COPY_FREE_VARS,
- &&TARGET_LOAD_CONST__LOAD_FAST,
+ &&TARGET_LOAD_FAST__LOAD_CONST,
&&TARGET_RESUME,
&&TARGET_MATCH_CLASS,
+ &&TARGET_LOAD_CONST__LOAD_FAST,
&&TARGET_STORE_FAST__STORE_FAST,
- &&_unknown_opcode,
&&TARGET_FORMAT_VALUE,
&&TARGET_BUILD_CONST_KEY_MAP,
&&TARGET_BUILD_STRING,
diff --git a/Python/specialize.c b/Python/specialize.c
index b051f45157ad3..e610a2d85fe58 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -407,6 +407,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:
More information about the Python-checkins
mailing list