Skip to content

Commit 65c41cb

Browse files
committed
Use separate 'counters' and 'executors' arrays
(The latter as yet unused.)
1 parent f4027de commit 65c41cb

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

Include/internal/pycore_uops.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ typedef struct {
2121

2222
typedef struct {
2323
_PyExecutorObject base;
24-
uintptr_t *extra; // An array of uintptr_t of size base.ob_base.ob_size
24+
// Auxiliary arrays, allocated after trace[base.ob_size]
25+
uint16_t *counters; // An array of counters
26+
_PyExecutorObject **executors; // An array of executors
2527
_PyUOpInstruction trace[1];
2628
} _PyUOpExecutorObject;
2729

Python/ceval.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
11081108
_PyFrame_SetStackPointer(frame, stack_pointer);
11091109
// Increment side exit counter for this uop
11101110
int pc = next_uop - 1 - current_executor->trace;
1111-
uintptr_t *pcounter = current_executor->extra + pc;
1111+
uint16_t *pcounter = current_executor->counters + pc;
11121112
*pcounter += 1;
11131113
if (*pcounter == 16 && // TODO: use resume_threshold
11141114
tstate->interp->optimizer != &_PyOptimizer_Default &&
@@ -1120,7 +1120,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
11201120
DPRINTF(2, "--> %s @ %d in %p has %d side exits\n",
11211121
_PyUOpName(uopcode), pc, current_executor, (int)(*pcounter));
11221122
DPRINTF(2, " T1: %s\n", _PyOpcode_OpName[opcode]);
1123-
// The counter will cycle around in 2**64 executions :-)
1123+
// The counter will cycle around once the 16 bits overflow
11241124
int optimized = _PyOptimizer_Anywhere(frame, src, dest, stack_pointer);
11251125
if (optimized < 0) {
11261126
goto error_tier_two;

Python/optimizer.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ PyTypeObject _PyUOpExecutor_Type = {
403403
PyVarObject_HEAD_INIT(&PyType_Type, 0)
404404
.tp_name = "uop_executor",
405405
.tp_basicsize = sizeof(_PyUOpExecutorObject) - sizeof(_PyUOpInstruction),
406-
.tp_itemsize = sizeof(_PyUOpInstruction) + sizeof(uintptr_t),
406+
.tp_itemsize = sizeof(_PyUOpInstruction) + sizeof(uint16_t) + sizeof(_PyExecutorObject *),
407407
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
408408
.tp_dealloc = (destructor)uop_dealloc,
409409
.tp_as_sequence = &uop_as_sequence,
@@ -835,8 +835,10 @@ make_executor_from_uops(_PyUOpInstruction *buffer, _PyBloomFilter *dependencies)
835835
if (executor == NULL) {
836836
return NULL;
837837
}
838-
executor->extra = (uintptr_t *)(executor->trace + length);
839-
memset(executor->extra, 0, sizeof(uintptr_t) * length);
838+
executor->counters = (uint16_t *)(&executor->trace[length]);
839+
memset(executor->counters, 0, sizeof(uint16_t) * length);
840+
executor->executors = (_PyExecutorObject **)(&executor->counters[length]);
841+
memset(executor->executors, 0, sizeof(_PyExecutorObject *) * length);
840842
int dest = length - 1;
841843
/* Scan backwards, so that we see the destinations of jumps before the jumps themselves. */
842844
for (int i = _Py_UOP_MAX_TRACE_LENGTH-1; i >= 0; i--) {

0 commit comments

Comments
 (0)