mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-109039: Branch prediction for Tier 2 interpreter (#109038)
This adds a 16-bit inline cache entry to the conditional branch instructions POP_JUMP_IF_{FALSE,TRUE,NONE,NOT_NONE} and their instrumented variants, which is used to keep track of the branch direction. Each time we encounter these instructions we shift the cache entry left by one and set the bottom bit to whether we jumped. Then when it's time to translate such a branch to Tier 2 uops, we use the bit count from the cache entry to decided whether to continue translating the "didn't jump" branch or the "jumped" branch. The counter is initialized to a pattern of alternating ones and zeros to avoid bias. The .pyc file magic number is updated. There's a new test, some fixes for existing tests, and a few miscellaneous cleanups.
This commit is contained in:
parent
ecd21a629a
commit
bcce5e2718
15 changed files with 339 additions and 181 deletions
|
@ -456,6 +456,7 @@ _code_type = type(_write_atomic.__code__)
|
|||
# Python 3.13a1 3558 (Reorder the stack items for CALL)
|
||||
# Python 3.13a1 3559 (Generate opcode IDs from bytecodes.c)
|
||||
# Python 3.13a1 3560 (Add RESUME_CHECK instruction)
|
||||
# Python 3.13a1 3561 (Add cache entry to branch instructions)
|
||||
|
||||
# Python 3.14 will start with 3600
|
||||
|
||||
|
@ -472,7 +473,7 @@ _code_type = type(_write_atomic.__code__)
|
|||
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
|
||||
# in PC/launcher.c must also be updated.
|
||||
|
||||
MAGIC_NUMBER = (3560).to_bytes(2, 'little') + b'\r\n'
|
||||
MAGIC_NUMBER = (3561).to_bytes(2, 'little') + b'\r\n'
|
||||
|
||||
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue