diff options
author | Guido van Rossum <guido@python.org> | 2023-09-11 18:20:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-11 18:20:24 (GMT) |
commit | bcce5e271815c0bdbe894964e853210d2c75949b (patch) | |
tree | 52bb552678ee685e56900b3f85e20027fa8f3212 /Lib/importlib | |
parent | ecd21a629a2a30bcae89902f7cad5670e9441e2c (diff) | |
download | cpython-bcce5e271815c0bdbe894964e853210d2c75949b.zip cpython-bcce5e271815c0bdbe894964e853210d2c75949b.tar.gz cpython-bcce5e271815c0bdbe894964e853210d2c75949b.tar.bz2 |
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.
Diffstat (limited to 'Lib/importlib')
-rw-r--r-- | Lib/importlib/_bootstrap_external.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 7a83a58..843af30 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -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 |