Repository navigation
tests/spirv_interp: hold integers as 32-bit patterns; signed ops convert themselves (TEST-720) - #3645
Conversation
slint6614-dev
left a comment
There was a problem hiding this comment.
Reviewed at 70154750. The interpreter now keeps integer values as 32-bit patterns and converts only where an operation is signed, which fixes signedness mismatches at those consumers. The new hand-written SPIR-V tests cover signed and unsigned comparisons, shifts, conversions, signed min/max, and signed-zero division.
Validation on this checkout: python -I tests/test_spirv_interp_signs.py (8/8), python -I tests/test_spirv_interp_bits.py (4/4), python -I tests/test_spirv_interp_f64_glsl.py (4/4), and python -I tests/semantic/test_valu_add_f64.py (8/8); git diff --check is clean. The broader pytest selection in the PR description could not be rerun because pytest is not installed in this environment.
whattheflop
left a comment
There was a problem hiding this comment.
AI-assisted independent review at 70154750 versus f847748c. On uv CPython 3.12.13, the eight stock interpreter suites passed 297 tests and 72 subtests on both commits. The new suite passed 8/8 on head and 1/8 on parent. I assembled and validated another 46 synthetic modules for Vulkan 1.2, which confirmed the scalar signedness gains and exposed a vector regression.
Vector SMin/SMax: With valid signed vectors (1, 2) and (-1, 1), head raises TypeError in s32(tuple) for both instructions. Parent returns the expected words for these inputs: SMin ffffffff/00000001 and SMax 00000001/00000002. A crossed-component case also shows that the parent's lexicographic tuple comparison was already wrong in general, and head still uses that comparison for UMin/UMax. Use the scalar operators per component for these four GLSL instructions and test crossed vectors. Dispatch
The focused fixtures also use an interpreter-only scaffold: module-scope Function variables, stores with signed values through a uint pointer, a signed bitfield extract with different base/result types, and an out-of-range float-to-int conversion that assumes saturation. The independent modules used a validator-clean scaffold. Moving locals into the function, matching operand/store types, and choosing representable conversion inputs would let the committed cases run through the validator. Fixture
CPU only, no game data.
…ert themselves The interpreter kept a value of a signed type as a negative Python int and a value of an unsigned type as a non-negative one, and used both raw. SPIR-V defines its signed and unsigned instructions on the bits, so wherever the instruction and the type disagreed the result was wrong: OpSLessThanEqual 0x80000000u 1u false (true) OpShiftRightLogical (int -8) 1 0xfffffffc (0x7ffffffc) OpULessThan (int -8) 1u true (false) OpConvertUToF (int -8) -8.0 (2^32) SMin / SMax of uint values unsigned order Integers are now always the unsigned 32-bit pattern, and OpS* compares, SMin and SMax read them through s32(). Also x / -0.0 gave +inf for a positive x. The 297 tests that run translator output through this interpreter give the same results. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
7015475 to
f69db1a
Compare
|
Rebased on |
TEST-720 (listed in #3574). Claim: #3232 (comment)
What was wrong
tests/spirv_interp.pyruns translator output fortests/test_f16_hw_words.py,test_values.py,test_mode_round.pyand others. It kept a value of a signed type as a negative Python int and a value of an unsigned type as a non-negative one, and used both raw. SPIR-V defines its instructions on the bits of the operands, not on their types, so wherever instruction and type disagreed the result was wrong:OpSLessThanEqual 0x80000000u 1uOpShiftRightLogical (int -8) 1OpULessThan (int -8) 1uOpConvertUToF (int -8)SMin/SMaxof uint valuesOpFDiv 1.0 -0.0A translator change that feeds a uint into a signed compare (or an int into an unsigned one) would have been evaluated wrongly against the hardware-measured words, without any error.
What changed
An integer is always its unsigned 32-bit pattern (constants,
OpBitcast,OpConvertFToS,OpBitFieldSExtract).OpSLessThanEqual,OpSGreaterThanEqual,SMinandSMaxread their operands throughs32().OpFDivby a zero takes the sign of the zero into account, and NaN / 0 is now a NaN (it was an infinity). The module docstring states the rule.Tests
tests/test_spirv_interp_signs.py(8 tests, hand-written modules). Onmain7 of the 8 fail.mainaa2988ccthat is nine files:python -m pytest tests/test_f16_hw_words.py tests/test_f16_op_sel_values.py tests/test_mode_round.py tests/test_values.py tests/test_rcp_iflag_mods.py tests/test_spirv_interp_bits.py tests/test_spirv_interp_f64_glsl.py tests/test_u16_high_half.py tests/semantic/test_valu_add_f64.py: 350 passed and 1 failed with this change, and the same 350 passed and 1 failed withmain's interpreter. The failure istest_u16_high_half.py::test_d16_buffer_store_no_redundant_extract_after_shr16, which fails onmainwithout this PR:spirv-valrejects the translated module ("Operand ... requires a previous definition"), before the interpreter runs.tests/semantic/test_valu_add_f64.pyis the only file undertests/semanticthat imports this interpreter, and it is in that set.python -m unittest discover -s tests/semantic: 7,456 tests; the only failures are 7 failures and 2 errors thatmainaa2988cchas without this PR (intest_loop_ballot_barrier,test_mutationsandtest_cmp_class_f64: the same 9, checked on a clean checkout ofmain), so this PR adds none.Open #3526 (TEST-661, f16 NaN helpers) also edits
tests/spirv_interp.py, on different lines;git merge-treeof the two is clean. Open #3642 (binary64OpFDiv,OpFConvert,Sqrt/InverseSqrt) edits the same file next to the binary32OpFDivthis changes; that trial merge is clean too.Windows 11, Python 3.13.7. No GPU involved.
AI-assisted (Claude Code).
🤖 Generated with Claude Code