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/opcode.py | |
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/opcode.py')
-rw-r--r-- | Lib/opcode.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/opcode.py b/Lib/opcode.py index 386a2fb..88f4df7 100644 --- a/Lib/opcode.py +++ b/Lib/opcode.py @@ -93,6 +93,18 @@ _cache_format = { "counter": 1, "version": 2, }, + "POP_JUMP_IF_TRUE": { + "counter": 1, + }, + "POP_JUMP_IF_FALSE": { + "counter": 1, + }, + "POP_JUMP_IF_NONE": { + "counter": 1, + }, + "POP_JUMP_IF_NOT_NONE": { + "counter": 1, + }, } _inline_cache_entries = { |