mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-106529: Generate uops for POP_JUMP_IF_[NOT_]NONE (#106796)
These aren't automatically translated because (ironically) they are macros deferring to POP_JUMP_IF_{TRUE,FALSE}, which are not viable uops (being manually translated). The hack is that we emit IS_NONE and then set opcode and jump to the POP_JUMP_IF_{TRUE,FALSE} translation code.
This commit is contained in:
parent
ad95c7253a
commit
b2b261ab2a
2 changed files with 47 additions and 0 deletions
|
@ -2532,6 +2532,36 @@ class TestUops(unittest.TestCase):
|
|||
uops = {opname for opname, _ in ex}
|
||||
self.assertIn("_POP_JUMP_IF_FALSE", uops)
|
||||
|
||||
def test_pop_jump_if_none(self):
|
||||
def testfunc(a):
|
||||
for x in a:
|
||||
if x is None:
|
||||
x = 0
|
||||
|
||||
opt = _testinternalcapi.get_uop_optimizer()
|
||||
with temporary_optimizer(opt):
|
||||
testfunc([1, 2, 3])
|
||||
|
||||
ex = get_first_executor(testfunc)
|
||||
self.assertIsNotNone(ex)
|
||||
uops = {opname for opname, _ in ex}
|
||||
self.assertIn("_POP_JUMP_IF_TRUE", uops)
|
||||
|
||||
def test_pop_jump_if_not_none(self):
|
||||
def testfunc(a):
|
||||
for x in a:
|
||||
if x is not None:
|
||||
x = 0
|
||||
|
||||
opt = _testinternalcapi.get_uop_optimizer()
|
||||
with temporary_optimizer(opt):
|
||||
testfunc([1, 2, 3])
|
||||
|
||||
ex = get_first_executor(testfunc)
|
||||
self.assertIsNotNone(ex)
|
||||
uops = {opname for opname, _ in ex}
|
||||
self.assertIn("_POP_JUMP_IF_FALSE", uops)
|
||||
|
||||
def test_pop_jump_if_true(self):
|
||||
def testfunc(n):
|
||||
i = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue