Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1546,10 +1546,16 @@ eval_frame_handle_pending(PyThreadState *tstate)
}

#define ADAPTIVE_COUNTER_IS_ZERO(cache) \
(cache)->counter < (1<<ADAPTIVE_BACKOFF_BITS)
((cache)->counter < (1<<ADAPTIVE_BACKOFF_BITS))

#define DECREMENT_ADAPTIVE_COUNTER(cache) \
(cache)->counter -= (1<<ADAPTIVE_BACKOFF_BITS)
((cache)->counter -= (1<<ADAPTIVE_BACKOFF_BITS))

#define ADAPTIVE_COUNTER_CODE_IS_ZERO(codeunit) \
(*(codeunit) < (1<<ADAPTIVE_BACKOFF_BITS))

#define DECREMENT_ADAPTIVE_COUNTER_CODE(codeunit) \
(*(codeunit) -= (1<<ADAPTIVE_BACKOFF_BITS))

static int
trace_function_entry(PyThreadState *tstate, _PyInterpreterFrame *frame)
Expand Down Expand Up @@ -5609,8 +5615,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
STAT_INC(opcode, miss);
/* The counter is always the first cache entry: */
_Py_CODEUNIT *counter = (_Py_CODEUNIT *)next_instr;
*counter -= 1;
if (*counter == 0) {
DECREMENT_ADAPTIVE_COUNTER_CODE(counter);
if (ADAPTIVE_COUNTER_CODE_IS_ZERO(counter)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the adaptive counter. It is the miss counter. It's not the same thing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh thanks. I shouldn't code while sleep deprived 🤦 . Sorry.

int adaptive_opcode = _PyOpcode_Adaptive[opcode];
assert(adaptive_opcode);
_Py_SET_OPCODE(next_instr[-1], adaptive_opcode);
Expand Down