Skip to content

Commit fbd322a

Browse files
committed
Initialize POP_JUMP_IF* counters to 0x5555
1 parent 73eb60f commit fbd322a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

Python/specialize.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,23 @@ _PyCode_Quicken(PyCodeObject *code)
338338
assert(opcode < MIN_INSTRUMENTED_OPCODE);
339339
int caches = _PyOpcode_Caches[opcode];
340340
if (caches) {
341-
// JUMP_BACKWARD counter counts up from 0 until it is > backedge_threshold
342-
instructions[i + 1].cache =
343-
opcode == JUMP_BACKWARD ? 0 : adaptive_counter_warmup();
341+
// The initial value depends on the opcode
342+
int initial_value;
343+
switch (opcode) {
344+
case JUMP_BACKWARD:
345+
initial_value = 0;
346+
break;
347+
case POP_JUMP_IF_FALSE:
348+
case POP_JUMP_IF_TRUE:
349+
case POP_JUMP_IF_NONE:
350+
case POP_JUMP_IF_NOT_NONE:
351+
initial_value = 0x5555; // Alternating 0, 1 bits
352+
break;
353+
default:
354+
initial_value = adaptive_counter_warmup();
355+
break;
356+
}
357+
instructions[i + 1].cache = initial_value;
344358
i += caches;
345359
}
346360
}

0 commit comments

Comments
 (0)