From f6833ca9413f7c79d4f26f9821ccabed72611177 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Tue, 28 Jun 2022 15:23:44 +0900 Subject: [PATCH 1/9] Load opcode via next_instr --- Python/ceval.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Python/ceval.c b/Python/ceval.c index 946e997fc832df..86709478b3f203 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5705,6 +5705,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int _unknown_opcode: #else EXTRA_CASES // From opcode.h, a 'case' for each unused opcode + /* Load opcode for MSVC to optimize switch(opcode) separately */ + opcode = _Py_OPCODE(*next_instr); #endif fprintf(stderr, "XXX lineno: %d, opcode: %d\n", _PyInterpreterFrame_GetLine(frame), opcode); From 70a1a9f5eac97a7747053113f37ec43930fcb2fc Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Wed, 29 Jun 2022 06:50:20 +0900 Subject: [PATCH 2/9] Comment --- Python/ceval.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index 86709478b3f203..12d4f2f3ae146d 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5705,7 +5705,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int _unknown_opcode: #else EXTRA_CASES // From opcode.h, a 'case' for each unused opcode - /* Load opcode for MSVC to optimize switch(opcode) separately */ + /* Load opcode for MSVC to optimize switch(opcode) separately. + next_instr, which EXTRA_CASES do not increment, points + the current instruction here. */ opcode = _Py_OPCODE(*next_instr); #endif fprintf(stderr, "XXX lineno: %d, opcode: %d\n", From a4c9722e5365d8e109546aa230ace24e78e5e062 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 29 Jun 2022 10:03:40 -0700 Subject: [PATCH 3/9] Do the opcode reloading always, not just on Windows. --- Python/ceval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index 12d4f2f3ae146d..1d1fa91cc770bc 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5705,11 +5705,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int _unknown_opcode: #else EXTRA_CASES // From opcode.h, a 'case' for each unused opcode +#endif /* Load opcode for MSVC to optimize switch(opcode) separately. next_instr, which EXTRA_CASES do not increment, points the current instruction here. */ opcode = _Py_OPCODE(*next_instr); -#endif fprintf(stderr, "XXX lineno: %d, opcode: %d\n", _PyInterpreterFrame_GetLine(frame), opcode); _PyErr_SetString(tstate, PyExc_SystemError, "unknown opcode"); From ba84e684fca8babd98cddde0da11a83d525d5890 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 29 Jun 2022 22:18:37 +0000 Subject: [PATCH 4/9] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst b/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst new file mode 100644 index 00000000000000..92e8f38fbf071f --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst @@ -0,0 +1,2 @@ +The MSVC compiler is now expected to generate faster switch code in the +interpreter main loop, which reduces memory access in dispatching opcode. From fa090e52b46eb46bfa0902c02a43b20de7d89fa6 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Thu, 30 Jun 2022 07:23:44 +0900 Subject: [PATCH 5/9] fix NEWS --- .../2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst b/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst index 92e8f38fbf071f..a976ac013cf3b3 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst @@ -1,2 +1 @@ -The MSVC compiler is now expected to generate faster switch code in the -interpreter main loop, which reduces memory access in dispatching opcode. +The MSVC compiler is now expected to generate faster switch code in the interpreter main loop, which reduces memory access in dispatching an opcode. From 3ba3bf260ad01f14a48cf4290110871799431fbd Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Thu, 30 Jun 2022 15:30:24 +0900 Subject: [PATCH 6/9] update NEWS --- .../2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst b/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst index a976ac013cf3b3..cb7940c9b6509f 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst @@ -1 +1,2 @@ -The MSVC compiler is now expected to generate faster switch code in the interpreter main loop, which reduces memory access in dispatching an opcode. +The MSVC compiler is now expected to generate faster switch code to dispatch +an opcode in the interpreter main loop, reducing memory access instructions. From a341d5ed5beefd29de5a20b5e9d51c1a84cc0ce7 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Thu, 30 Jun 2022 15:52:22 +0900 Subject: [PATCH 7/9] update comment --- Python/ceval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index 1d1fa91cc770bc..b5682319ba1729 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5706,7 +5706,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int #else EXTRA_CASES // From opcode.h, a 'case' for each unused opcode #endif - /* Load opcode for MSVC to optimize switch(opcode) separately. + /* Reload opcode for MSVC to optimize switch(opcode) separately. next_instr, which EXTRA_CASES do not increment, points the current instruction here. */ opcode = _Py_OPCODE(*next_instr); From db0a6b3fa995ac838144d13920dcdf2753f8e1bf Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Thu, 30 Jun 2022 17:40:32 +0900 Subject: [PATCH 8/9] Change NEWS to mention non-MSVC --- .../2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst b/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst index cb7940c9b6509f..0d085e88778372 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst @@ -1,2 +1,2 @@ -The MSVC compiler is now expected to generate faster switch code to dispatch -an opcode in the interpreter main loop, reducing memory access instructions. +Reload ``opcode`` when raising ``unknown opcode error`` in the interpreter main loop, +for C compilers to generate dispatching code independently. From 0ce385969567243d0cb84863128f1766a56f85a2 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Thu, 30 Jun 2022 23:53:07 +0900 Subject: [PATCH 9/9] make comment generic --- Python/ceval.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index b5682319ba1729..4fcdf9b41dea92 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5706,9 +5706,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int #else EXTRA_CASES // From opcode.h, a 'case' for each unused opcode #endif - /* Reload opcode for MSVC to optimize switch(opcode) separately. - next_instr, which EXTRA_CASES do not increment, points - the current instruction here. */ + /* Tell C compilers not to hold the opcode variable in the loop. + next_instr points the current instruction without TARGET(). */ opcode = _Py_OPCODE(*next_instr); fprintf(stderr, "XXX lineno: %d, opcode: %d\n", _PyInterpreterFrame_GetLine(frame), opcode);