Skip to content

Commit

Permalink
Use separate 'counters' and 'executors' arrays
Browse files Browse the repository at this point in the history
(The latter as yet unused.)
  • Loading branch information
gvanrossum committed Dec 12, 2023
1 parent f4027de commit 65c41cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Include/internal/pycore_uops.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ typedef struct {

typedef struct {
_PyExecutorObject base;
uintptr_t *extra; // An array of uintptr_t of size base.ob_base.ob_size
// Auxiliary arrays, allocated after trace[base.ob_size]
uint16_t *counters; // An array of counters
_PyExecutorObject **executors; // An array of executors
_PyUOpInstruction trace[1];
} _PyUOpExecutorObject;

Expand Down
4 changes: 2 additions & 2 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
_PyFrame_SetStackPointer(frame, stack_pointer);
// Increment side exit counter for this uop
int pc = next_uop - 1 - current_executor->trace;

Check warning on line 1110 in Python/ceval.c

View workflow job for this annotation

GitHub Actions / Windows (free-threaded) / build and test (x64)

'initializing': conversion from '__int64' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1110 in Python/ceval.c

View workflow job for this annotation

GitHub Actions / Windows (free-threaded) / build and test (x64)

'initializing': conversion from '__int64' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1110 in Python/ceval.c

View workflow job for this annotation

GitHub Actions / Windows (free-threaded) / build (arm64)

'initializing': conversion from '__int64' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1110 in Python/ceval.c

View workflow job for this annotation

GitHub Actions / Windows (free-threaded) / build (arm64)

'initializing': conversion from '__int64' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1110 in Python/ceval.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'initializing': conversion from '__int64' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1110 in Python/ceval.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'initializing': conversion from '__int64' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1110 in Python/ceval.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'initializing': conversion from '__int64' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1110 in Python/ceval.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'initializing': conversion from '__int64' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]
uintptr_t *pcounter = current_executor->extra + pc;
uint16_t *pcounter = current_executor->counters + pc;
*pcounter += 1;
if (*pcounter == 16 && // TODO: use resume_threshold
tstate->interp->optimizer != &_PyOptimizer_Default &&
Expand All @@ -1120,7 +1120,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
DPRINTF(2, "--> %s @ %d in %p has %d side exits\n",
_PyUOpName(uopcode), pc, current_executor, (int)(*pcounter));
DPRINTF(2, " T1: %s\n", _PyOpcode_OpName[opcode]);
// The counter will cycle around in 2**64 executions :-)
// The counter will cycle around once the 16 bits overflow
int optimized = _PyOptimizer_Anywhere(frame, src, dest, stack_pointer);
if (optimized < 0) {
goto error_tier_two;
Expand Down
8 changes: 5 additions & 3 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ PyTypeObject _PyUOpExecutor_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
.tp_name = "uop_executor",
.tp_basicsize = sizeof(_PyUOpExecutorObject) - sizeof(_PyUOpInstruction),
.tp_itemsize = sizeof(_PyUOpInstruction) + sizeof(uintptr_t),
.tp_itemsize = sizeof(_PyUOpInstruction) + sizeof(uint16_t) + sizeof(_PyExecutorObject *),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
.tp_dealloc = (destructor)uop_dealloc,
.tp_as_sequence = &uop_as_sequence,
Expand Down Expand Up @@ -835,8 +835,10 @@ make_executor_from_uops(_PyUOpInstruction *buffer, _PyBloomFilter *dependencies)
if (executor == NULL) {
return NULL;
}
executor->extra = (uintptr_t *)(executor->trace + length);
memset(executor->extra, 0, sizeof(uintptr_t) * length);
executor->counters = (uint16_t *)(&executor->trace[length]);
memset(executor->counters, 0, sizeof(uint16_t) * length);
executor->executors = (_PyExecutorObject **)(&executor->counters[length]);
memset(executor->executors, 0, sizeof(_PyExecutorObject *) * length);
int dest = length - 1;
/* Scan backwards, so that we see the destinations of jumps before the jumps themselves. */
for (int i = _Py_UOP_MAX_TRACE_LENGTH-1; i >= 0; i--) {
Expand Down

0 comments on commit 65c41cb

Please sign in to comment.