diff options
author | Sam Gross <colesbury@gmail.com> | 2025-01-23 09:26:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-23 09:26:25 (GMT) |
commit | a10f99375e7912df863cf101a38e9703cfcd72f1 (patch) | |
tree | 7909c7896fe256427c1149d2416fb7912ad3ba48 /Lib/test/test_generated_cases.py | |
parent | d7d066c3ab6842117f9e0fb1c9dde4bce00fa1e3 (diff) | |
download | cpython-a10f99375e7912df863cf101a38e9703cfcd72f1.zip cpython-a10f99375e7912df863cf101a38e9703cfcd72f1.tar.gz cpython-a10f99375e7912df863cf101a38e9703cfcd72f1.tar.bz2 |
Revert "GH-128914: Remove conditional stack effects from `bytecodes.c` and the code generators (GH-128918)" (GH-129202)
The commit introduced a ~2.5-3% regression in the free threading build.
This reverts commit ab61d3f4303d14a413bc9ae6557c730ffdf7579e.
Diffstat (limited to 'Lib/test/test_generated_cases.py')
-rw-r--r-- | Lib/test/test_generated_cases.py | 129 |
1 files changed, 123 insertions, 6 deletions
diff --git a/Lib/test/test_generated_cases.py b/Lib/test/test_generated_cases.py index c93d6fc..b5367a0 100644 --- a/Lib/test/test_generated_cases.py +++ b/Lib/test/test_generated_cases.py @@ -59,14 +59,14 @@ class TestEffects(unittest.TestCase): def test_effect_sizes(self): stack = Stack() inputs = [ - x := StackItem("x", None, "1"), - y := StackItem("y", None, "oparg"), - z := StackItem("z", None, "oparg*2"), + x := StackItem("x", None, "", "1"), + y := StackItem("y", None, "", "oparg"), + z := StackItem("z", None, "", "oparg*2"), ] outputs = [ - StackItem("x", None, "1"), - StackItem("b", None, "oparg*4"), - StackItem("c", None, "1"), + StackItem("x", None, "", "1"), + StackItem("b", None, "", "oparg*4"), + StackItem("c", None, "", "1"), ] stack.pop(z) stack.pop(y) @@ -104,6 +104,20 @@ class TestGenerateMaxStackEffect(unittest.TestCase): """ self.check(input, output) + def test_cond_push(self): + input = """ + inst(OP, (a -- b, c if (oparg))) { + SPAM(); + } + """ + output = """ + case OP: { + *effect = ((oparg) ? 1 : 0); + return 0; + } + """ + self.check(input, output) + def test_ops_pass_two(self): input = """ op(A, (-- val1)) { @@ -124,6 +138,25 @@ class TestGenerateMaxStackEffect(unittest.TestCase): """ self.check(input, output) + def test_ops_pass_two_cond_push(self): + input = """ + op(A, (-- val1, val2)) { + val1 = 0; + val2 = 1; + } + op(B, (val1, val2 -- val1, val2, val3 if (oparg))) { + val3 = SPAM(); + } + macro(OP) = A + B; + """ + output = """ + case OP: { + *effect = Py_MAX(2, 2 + ((oparg) ? 1 : 0)); + return 0; + } + """ + self.check(input, output) + def test_pop_push_array(self): input = """ inst(OP, (values[oparg] -- values[oparg], above)) { @@ -905,6 +938,90 @@ class TestGeneratedCases(unittest.TestCase): """ self.run_cases_test(input, output) + def test_cond_effect(self): + input = """ + inst(OP, (aa, input if ((oparg & 1) == 1), cc -- xx, output if (oparg & 2), zz)) { + output = SPAM(oparg, aa, cc, input); + INPUTS_DEAD(); + xx = 0; + zz = 0; + } + """ + output = """ + TARGET(OP) { + frame->instr_ptr = next_instr; + next_instr += 1; + INSTRUCTION_STATS(OP); + _PyStackRef aa; + _PyStackRef input = PyStackRef_NULL; + _PyStackRef cc; + _PyStackRef xx; + _PyStackRef output = PyStackRef_NULL; + _PyStackRef zz; + cc = stack_pointer[-1]; + if ((oparg & 1) == 1) { input = stack_pointer[-1 - (((oparg & 1) == 1) ? 1 : 0)]; } + aa = stack_pointer[-2 - (((oparg & 1) == 1) ? 1 : 0)]; + output = SPAM(oparg, aa, cc, input); + xx = 0; + zz = 0; + stack_pointer[-2 - (((oparg & 1) == 1) ? 1 : 0)] = xx; + if (oparg & 2) stack_pointer[-1 - (((oparg & 1) == 1) ? 1 : 0)] = output; + stack_pointer[-1 - (((oparg & 1) == 1) ? 1 : 0) + ((oparg & 2) ? 1 : 0)] = zz; + stack_pointer += -(((oparg & 1) == 1) ? 1 : 0) + ((oparg & 2) ? 1 : 0); + assert(WITHIN_STACK_BOUNDS()); + DISPATCH(); + } + """ + self.run_cases_test(input, output) + + def test_macro_cond_effect(self): + input = """ + op(A, (left, middle, right --)) { + USE(left, middle, right); + INPUTS_DEAD(); + } + op(B, (-- deep, extra if (oparg), res)) { + deep = -1; + res = 0; + extra = 1; + INPUTS_DEAD(); + } + macro(M) = A + B; + """ + output = """ + TARGET(M) { + frame->instr_ptr = next_instr; + next_instr += 1; + INSTRUCTION_STATS(M); + _PyStackRef left; + _PyStackRef middle; + _PyStackRef right; + _PyStackRef deep; + _PyStackRef extra = PyStackRef_NULL; + _PyStackRef res; + // A + { + right = stack_pointer[-1]; + middle = stack_pointer[-2]; + left = stack_pointer[-3]; + USE(left, middle, right); + } + // B + { + deep = -1; + res = 0; + extra = 1; + } + stack_pointer[-3] = deep; + if (oparg) stack_pointer[-2] = extra; + stack_pointer[-2 + ((oparg) ? 1 : 0)] = res; + stack_pointer += -1 + ((oparg) ? 1 : 0); + assert(WITHIN_STACK_BOUNDS()); + DISPATCH(); + } + """ + self.run_cases_test(input, output) + def test_macro_push_push(self): input = """ op(A, (-- val1)) { |