aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/generated_cases.c.h
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-02-13 14:16:37 +0000
committerGitHub <noreply@github.com>2024-02-13 14:16:37 +0000
commitf9f6156c5affc039d4ee6b6f4999daf0d5896428 (patch)
tree063a0d3da50ec32d1bdd265d0b305f9365ced7da /Python/generated_cases.c.h
parent7cce8576226249461baa91c4a89770a1823b44a4 (diff)
downloadcpython-f9f6156c5affc039d4ee6b6f4999daf0d5896428.tar.gz
cpython-f9f6156c5affc039d4ee6b6f4999daf0d5896428.zip
GH-113710: Backedge counter improvements. (GH-115166)
Diffstat (limited to 'Python/generated_cases.c.h')
-rw-r--r--Python/generated_cases.c.h29
1 files changed, 16 insertions, 13 deletions
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index afb6650e592..a49223e4db5 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -3263,13 +3263,16 @@
assert(oparg <= INSTR_OFFSET());
JUMPBY(-oparg);
#if ENABLE_SPECIALIZATION
- this_instr[1].cache += (1 << OPTIMIZER_BITS_IN_COUNTER);
+ uint16_t counter = this_instr[1].cache;
+ this_instr[1].cache = counter + (1 << OPTIMIZER_BITS_IN_COUNTER);
/* We are using unsigned values, but we really want signed values, so
- * do the 2s complement comparison manually */
- uint16_t ucounter = this_instr[1].cache + (1 << 15);
- uint16_t threshold = tstate->interp->optimizer_backedge_threshold + (1 << 15);
+ * do the 2s complement adjustment manually */
+ uint32_t offset_counter = counter ^ (1 << 15);
+ uint32_t threshold = tstate->interp->optimizer_backedge_threshold;
+ assert((threshold & OPTIMIZER_BITS_MASK) == 0);
+ // Use '>=' not '>' so that the optimizer/backoff bits do not effect the result.
// Double-check that the opcode isn't instrumented or something:
- if (ucounter > threshold && this_instr->op.code == JUMP_BACKWARD) {
+ if (offset_counter >= threshold && this_instr->op.code == JUMP_BACKWARD) {
OPT_STAT_INC(attempts);
_Py_CODEUNIT *start = this_instr;
/* Back up over EXTENDED_ARGs so optimizer sees the whole instruction */
@@ -3283,18 +3286,18 @@
// Rewind and enter the executor:
assert(start->op.code == ENTER_EXECUTOR);
next_instr = start;
- this_instr[1].cache &= ((1 << OPTIMIZER_BITS_IN_COUNTER) - 1);
+ this_instr[1].cache &= OPTIMIZER_BITS_MASK;
}
else {
- int backoff = this_instr[1].cache & ((1 << OPTIMIZER_BITS_IN_COUNTER) - 1);
- if (backoff < MINIMUM_TIER2_BACKOFF) {
- backoff = MINIMUM_TIER2_BACKOFF;
+ int backoff = this_instr[1].cache & OPTIMIZER_BITS_MASK;
+ backoff++;
+ if (backoff < MIN_TIER2_BACKOFF) {
+ backoff = MIN_TIER2_BACKOFF;
}
- else if (backoff < 15 - OPTIMIZER_BITS_IN_COUNTER) {
- backoff++;
+ else if (backoff > MAX_TIER2_BACKOFF) {
+ backoff = MAX_TIER2_BACKOFF;
}
- assert(backoff <= 15 - OPTIMIZER_BITS_IN_COUNTER);
- this_instr[1].cache = ((1 << 16) - ((1 << OPTIMIZER_BITS_IN_COUNTER) << backoff)) | backoff;
+ this_instr[1].cache = ((UINT16_MAX << OPTIMIZER_BITS_IN_COUNTER) << backoff) | backoff;
}
}
#endif /* ENABLE_SPECIALIZATION */