Skip to content

Commit

Permalink
Be less confident about jumps always/never taken
Browse files Browse the repository at this point in the history
  • Loading branch information
gvanrossum committed Feb 20, 2024
1 parent c1583b1 commit 2537f75
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,15 @@ translate_bytecode_to_trace(
int counter = instr[1].cache;
int bitcount = _Py_popcount32(counter);
int jump_likely = bitcount > 8;
/* If bitcount is 8 (half the jumps were taken), adjust confidence by 50%.
If it's 16 or 0 (all or none were taken), adjust by 10%
(since the future is still somewhat uncertain).
For values in between, adjust proportionally. */
if (jump_likely) {
confidence = confidence * bitcount / 16;
confidence = confidence * (bitcount + 2) / 20;
}
else {
confidence = confidence * (16 - bitcount) / 16;
confidence = confidence * (18 - bitcount) / 20;
}
uint32_t uopcode = BRANCH_TO_GUARD[opcode - POP_JUMP_IF_FALSE][jump_likely];
DPRINTF(2, "%s(%d): counter=%x, bitcount=%d, likely=%d, confidence=%d, uopcode=%s\n",
Expand Down

0 comments on commit 2537f75

Please sign in to comment.