diff options
author | Guido van Rossum <guido@python.org> | 2022-04-21 18:53:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-21 18:53:57 (GMT) |
commit | f8dc6186d1857a19edd182277a9d78e6d6cc3787 (patch) | |
tree | e85e859c1999d95ce7cc6402068f84efad807e1f /Python | |
parent | d44815cabc0a8d9932df2fa95cb374eadddb7c17 (diff) | |
download | cpython-f8dc6186d1857a19edd182277a9d78e6d6cc3787.zip cpython-f8dc6186d1857a19edd182277a9d78e6d6cc3787.tar.gz cpython-f8dc6186d1857a19edd182277a9d78e6d6cc3787.tar.bz2 |
GH-91719: Make MSVC generate somewhat faster switch code (#91718)
Apparently a switch on an 8-bit quantity where all cases are
present generates a more efficient jump (doing only one indexed
memory load instead of two).
So we make opcode and use_tracing uint8_t, and generate a macro
full of extra `case NNN:` lines for all unused opcodes.
See https://github.com/faster-cpython/ideas/issues/321#issuecomment-1103263673
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 12b0aef..a80583f 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1662,7 +1662,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int #ifdef Py_STATS int lastopcode = 0; #endif - int opcode; /* Current opcode */ + // opcode is an 8-bit value to improve the code generated by MSVC + // for the big switch below (in combination with the EXTRA_CASES macro). + uint8_t opcode; /* Current opcode */ int oparg; /* Current opcode argument, if any */ _Py_atomic_int * const eval_breaker = &tstate->interp->ceval.eval_breaker; @@ -5645,7 +5647,7 @@ handle_eval_breaker: #if USE_COMPUTED_GOTOS _unknown_opcode: #else - default: + EXTRA_CASES // From opcode.h, a 'case' for each unused opcode #endif fprintf(stderr, "XXX lineno: %d, opcode: %d\n", _PyInterpreterFrame_GetLine(frame), opcode); |