mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-106529: Split FOR_ITER_RANGE into uops (#106638)
For an example of what this does for Tier 1 and Tier 2, see https://github.com/python/cpython/issues/106529#issuecomment-1631649920
This commit is contained in:
parent
7f55f58b6c
commit
dd1884dc5d
6 changed files with 146 additions and 28 deletions
|
@ -2443,7 +2443,6 @@ class TestUops(unittest.TestCase):
|
|||
i += 1
|
||||
|
||||
opt = _testinternalcapi.get_uop_optimizer()
|
||||
|
||||
with temporary_optimizer(opt):
|
||||
testfunc(1000)
|
||||
|
||||
|
@ -2580,13 +2579,33 @@ class TestUops(unittest.TestCase):
|
|||
|
||||
ex = get_first_executor(testfunc)
|
||||
self.assertIsNotNone(ex)
|
||||
# for i, (opname, oparg) in enumerate(ex):
|
||||
# print(f"{i:4d}: {opname:<20s} {oparg:4d}")
|
||||
uops = {opname for opname, _ in ex}
|
||||
# Since there is no JUMP_FORWARD instruction,
|
||||
# look for indirect evidence: the += operator
|
||||
self.assertIn("_BINARY_OP_ADD_INT", uops)
|
||||
|
||||
def test_for_iter_range(self):
|
||||
def testfunc(n):
|
||||
total = 0
|
||||
for i in range(n):
|
||||
total += i
|
||||
return total
|
||||
# import dis; dis.dis(testfunc)
|
||||
|
||||
opt = _testinternalcapi.get_uop_optimizer()
|
||||
with temporary_optimizer(opt):
|
||||
total = testfunc(10)
|
||||
self.assertEqual(total, 45)
|
||||
|
||||
ex = get_first_executor(testfunc)
|
||||
self.assertIsNotNone(ex)
|
||||
# for i, (opname, oparg) in enumerate(ex):
|
||||
# print(f"{i:4d}: {opname:<20s} {oparg:3d}")
|
||||
uops = {opname for opname, _ in ex}
|
||||
self.assertIn("_ITER_EXHAUSTED_RANGE", uops)
|
||||
# Verification that the jump goes past END_FOR
|
||||
# is done by manual inspection of the output
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue