-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-43684: Add ADD_INT opcode #25090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
bab6b8e
Add INT_ADD opcode
gvanrossum 8b7e016
Move the code that reaches into longs representation out of ceval.c
gvanrossum 6041514
Make it compile on Mac
gvanrossum 09407e8
Bump magic number
gvanrossum c918e60
Regenerated Python/importlib_external.h
gvanrossum f5e1f75
Don't optimize across lines
gvanrossum a95a0cb
Rename INT_ADD to ADD_INT
gvanrossum c3276da
Use Mark's suggestion in _PyLong_AddInt, it is more correct
gvanrossum 195e532
Fix test_dis.py
gvanrossum 362d805
Add blurb
gvanrossum 01af55b
Add script to count static occurrences of ADD_INT
gvanrossum 6807bb2
Delete Victor's comment for BINARY_ADD
gvanrossum 1199dac
Update blurb
gvanrossum 8778f68
Remove redundant text from blurb
gvanrossum a55bf88
Tweak comment
gvanrossum 23aae2d
Move _PyLong_AddInt() to pycore_long.h
gvanrossum 3136591
Merge remote-tracking branch 'origin/master' into int-add
gvanrossum 2612164
Improve count_opcodes.py script slightly
gvanrossum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Core and Builtins/2021-03-31-17-47-25.bpo-43684.hHmyyt.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add an ``INT_ADD`` opcode. This combines ``LOAD_CONST`` for a small integer | ||
constant and ``BINARY_ADD`` into a single opcode. Combining this popular pair of opcodes into one saves a modest amount of bytecode size and dispatch time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import opcode | ||
import sys | ||
|
||
|
||
ADD_INT = opcode.opmap['ADD_INT'] | ||
|
||
|
||
def all_code_objects(code): | ||
yield code | ||
for x in code.co_consts: | ||
if hasattr(x, 'co_code'): | ||
yield x | ||
|
||
|
||
def report(code, filename): | ||
add_int_count = total_count = 0 | ||
for co in all_code_objects(code): | ||
co_code = co.co_code | ||
for i in range(0, len(co_code), 2): | ||
op = co_code[i] | ||
if op == ADD_INT: | ||
add_int_count += 1 | ||
else: | ||
total_count += 1 | ||
if add_int_count: | ||
print(filename + ":", add_int_count, "/", total_count, | ||
f"{add_int_count/total_count*100:.2f}%") | ||
return add_int_count, total_count | ||
|
||
|
||
def main(dirname): | ||
import os | ||
add_int_count = total_count = 0 | ||
for root, dirs, files in os.walk(dirname): | ||
for file in files: | ||
if file.endswith(".py"): | ||
full = os.path.join(root, file) | ||
try: | ||
with open(full, "r") as f: | ||
source = f.read() | ||
code = compile(source, full, "exec") | ||
except Exception as err: | ||
print(full + ":", err) | ||
continue | ||
a, b = report(code, filename=full) | ||
add_int_count += a | ||
total_count += b | ||
print("TOTAL", add_int_count, "/", total_count, | ||
f"{add_int_count/total_count*100:.2f}%") | ||
|
||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.