8000 gh-111786: Use separate opcode vars for Tier 1 and Tier 2 · python/cpython@27a5654 · GitHub
[go: up one dir, main page]

Skip to content

Commit 27a5654

Browse files
committed
gh-111786: Use separate opcode vars for Tier 1 and Tier 2
Suggested by @neonene: #111786 (comment) This makes Windows about 3% faster on pyperformance benchmarks.
1 parent 6c57d9b commit 27a5654

File tree

1 8000 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

Python/ceval.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
680680
#ifdef Py_STATS
681681
int lastopcode = 0;
682682
#endif
683-
uint16_t opcode; /* Current opcode */
683+
uint8_t opcode; /* Current opcode */
684684
int oparg; /* Current opcode argument, if any */
685685
#ifdef LLTRACE
686686
int lltrace = 0;
@@ -767,9 +767,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
767767
/* Start instructions */
768768
#if !USE_COMPUTED_GOTOS
769769
dispatch_opcode:
770-
// Cast to an 8-bit value to improve the code generated by MSVC
771-
// (in combination with the EXTRA_CASES macro).
772-
switch ((uint8_t)opcode)
770+
switch (opcode)
773771
#endif
774772
{
775773

@@ -985,28 +983,29 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
985983

986984
OPT_STAT_INC(traces_executed);
987985
_PyUOpInstruction *next_uop = current_executor->trace;
986+
uint16_t uopcode;
988987
#ifdef Py_STATS
989988
uint64_t trace_uop_execution_counter = 0;
990989
#endif
991990

992991
for (;;) {
993-
opcode = next_uop->opcode;
992+
uopcode = next_uop->opcode;
994993
DPRINTF(3,
995994
"%4d: uop %s, oparg %d, operand %" PRIu64 ", target %d, stack_level %d\n",
996995
(int)(next_uop - current_executor->trace),
997-
_PyUopName(opcode),
996+
_PyUopName(uopcode),
998997
next_uop->oparg,
999998
next_uop->operand,
1000999
next_uop->target,
10011000
(int)(stack_pointer - _PyFrame_Stackbase(frame)));
10021001
next_uop++;
10031002
OPT_STAT_INC(uops_executed);
1004-
UOP_STAT_INC(opcode, execution_count);
1003+
UOP_STAT_INC(uopcode, execution_count);
10051004
#ifdef Py_STATS
10061005
trace_uop_execution_counter++;
10071006
#endif
10081007

1009-
switch (opcode) {
1008+
switch (uopcode) {
10101009

10111010
#include "executor_cases.c.h"
10121011

@@ -1044,7 +1043,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10441043
STACK_SHRINK(1);
10451044
error_tier_two:
10461045
DPRINTF(2, "Error: [Uop %d (%s), oparg %d, operand %" PRIu64 ", target %d @ %d]\n",
1047-
opcode, _PyUopName(opcode), next_uop[-1].oparg, next_uop[-1].operand, next_uop[-1].target,
1046+
uopcode, _PyUopName(uopcode), next_uop[-1].oparg, next_uop[-1].operand, next_uop[-1].target,
10481047
(int)(next_uop - current_executor->trace - 1));
10491048
OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
10501049
frame->return_offset = 0; // Don't leave this random
@@ -1057,10 +1056,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10571056
// On DEOPT_IF we just repeat the last instruction.
10581057
// This presumes nothing was popped from the stack (nor pushed).
10591058
DPRINTF(2, "DEOPT: [Uop %d (%s), oparg %d, operand %" PRIu64 ", target %d @ %d]\n",
1060-
opcode, _PyUopName(opcode), next_uop[-1].oparg, next_uop[-1].operand, next_uop[-1].target,
1059+
uopcode, _PyUopName(uopcode), next_uop[-1].oparg, next_uop[-1].operand, next_uop[-1].target,
10611060
(int)(next_uop - current_executor->trace - 1));
10621061
OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
1063-
UOP_STAT_INC(opcode, miss);
1062+
UOP_STAT_INC(uopcode, miss);
10641063
frame->return_offset = 0; // Dispatch to frame->instr_ptr
10651064
_PyFrame_SetStackPointer(frame, stack_pointer);
10661065
frame->instr_ptr = next_uop[-1].target + _PyCode_CODE(_PyFrame_GetCode(frame));

0 commit comments

Comments
 (0)
0