Skip to content

Commit 6810928

Browse files
authored
GH-118093: Don't lose confidence when tracing through 100% biased branches (GH-124813)
1 parent b85923a commit 6810928

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improve the experimental JIT compiler's ability to stay "on trace" when
2+
encountering highly-biased branches.

Python/optimizer.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,14 +643,12 @@ translate_bytecode_to_trace(
643643
int bitcount = _Py_popcount32(counter);
644644
int jump_likely = bitcount > 8;
645645
/* If bitcount is 8 (half the jumps were taken), adjust confidence by 50%.
646-
If it's 16 or 0 (all or none were taken), adjust by 10%
647-
(since the future is still somewhat uncertain).
648646
For values in between, adjust proportionally. */
649647
if (jump_likely) {
650-
confidence = confidence * (bitcount + 2) / 20;
648+
confidence = confidence * bitcount / 16;
651649
}
652650
else {
653-
confidence = confidence * (18 - bitcount) / 20;
651+
confidence = confidence * (16 - bitcount) / 16;
654652
}
655653
uint32_t uopcode = BRANCH_TO_GUARD[opcode - POP_JUMP_IF_FALSE][jump_likely];
656654
DPRINTF(2, "%d: %s(%d): counter=%04x, bitcount=%d, likely=%d, confidence=%d, uopcode=%s\n",

0 commit comments

Comments
 (0)