File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -2553,6 +2553,7 @@ def testfunc(n):
2553
2553
i = 0
2554
2554
while i < n :
2555
2555
i += 1
2556
+
2556
2557
opt = _testinternalcapi .get_uop_optimizer ()
2557
2558
with temporary_optimizer (opt ):
2558
2559
testfunc (10 )
@@ -2562,6 +2563,30 @@ def testfunc(n):
2562
2563
uops = {opname for opname , _ in ex }
2563
2564
self .assertIn ("JUMP_TO_TOP" , uops )
2564
2565
2566
+ def test_jump_forward (self ):
2567
+ def testfunc (n ):
2568
+ a = 0
2569
+ while a < n :
2570
+ if a < 0 :
2571
+ a = - a
2572
+ else :
2573
+ a = + a
2574
+ a += 1
2575
+ return a
2576
+
2577
+ opt = _testinternalcapi .get_uop_optimizer ()
2578
+ with temporary_optimizer (opt ):
2579
+ testfunc (10 )
2580
+
2581
+ ex = get_first_executor (testfunc )
2582
+ self .assertIsNotNone (ex )
2583
+ # for i, (opname, oparg) in enumerate(ex):
2584
+ # print(f"{i:4d}: {opname:<20s} {oparg:4d}")
2585
+ uops = {opname for opname , _ in ex }
2586
+ # Since there is no JUMP_FORWARD instruction,
2587
+ # look for indirect evidence: the += operator
2588
+ self .assertIn ("_BINARY_OP_ADD_INT" , uops )
2589
+
2565
2590
2566
2591
if __name__ == "__main__" :
2567
2592
unittest .main ()
Original file line number Diff line number Diff line change @@ -472,6 +472,13 @@ translate_bytecode_to_trace(
472
472
goto done ;
473
473
}
474
474
475
+ case JUMP_FORWARD :
476
+ {
477
+ // This will emit two SAVE_IP instructions; leave it to the optimizer
478
+ instr += oparg ;
479
+ break ;
480
+ }
481
+
475
482
default :
476
483
{
477
484
const struct opcode_macro_expansion * expansion = & _PyOpcode_macro_expansion [opcode ];
You can’t perform that action at this time.
0 commit comments