Skip to content

test_lane_masks_edge_cases: s_and_b32 of a lane mask with -1 stays a mask (EGEN-MASK-AND-M1-TEST) - #6509

Open
evilclanker9000 wants to merge 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:claude/mask-and-minus-one
Open

evilclanker9000 wants to merge 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:claude/mask-and-minus-one

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: EGEN-MASK-AND-M1-TEST (Vonsek4), #4933 (comment)

Depends on: none (a test in tests/semantic/test_lane_masks_edge_cases.py). #293 is about reading a mask as data; this test is about the translator still knowing the result is a mask.

What and why

tools/lane_masks.py kind() returns EITHER for the immediates 0 and -1 (a constant: no lanes or all lanes). That is what keeps s_and_b32 s5, s4, -1 on a compare result a lane mask, so a later s_bcnt1_i32_b32 s6, s5 counts the wave's bits instead of the lane's own.

I changed a["v"] in (0, -1) to in (0,) in a copy of tools/ and ran the 13 mask-related files of tests/semantic: all stayed green. The new test fails on it.

The test (wave32, 4 lanes): v_cmp_gt_u32_e64 s4, 3, v0 (lanes 0-2), s_and_b32 s5, s4, -1, s_bcnt1_i32_b32 s6, s5, store s6. Expected 3 in every lane; a lane that reads s5 as its own per-lane bit would count 0 or 32.

Tested

No GPU needed (CPU interpreter).

  • python -I -m unittest discover -s tests/semantic -p test_lane_masks_edge_cases.py -k minus_one: OK on this branch.
  • Negative control: (0, -1) -> (0,) in kind(): the test fails (the file was green without the change).
  • No translator change, so no corpus run.

Notes

AI-assisted.

…mask

lane_masks.kind answers EITHER for the immediates 0 and -1, so s_and_b32 s5, s4, -1 on a compare result leaves s5 a lane mask. Dropping -1 from that rule (only 0 kept) made s5 plain data and left every test that passes on main green. The new test counts the bits of s5 with s_bcnt1_i32_b32: 3 in every lane for a compare true in lanes 0-2, where a lane reading its own bit as data would get 0 or 32.
@AsgerCode

Copy link
Copy Markdown

Tested 0505665 on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass

What I ran:

  • python -I -m unittest discover -s tests/semantic -p test_lane_masks_edge_cases.py: 7 tests, OK.
  • python -I scripts/run_semantic_tests.py tests/semantic: 433 files, 5822 tests, 1 file failed: test_float_nan_fract (3 subtests, f32 NaN payload 0xFFC00001 != 0xFF800001). This PR's parent is the tip of main and the PR only adds a test to another file, so that failure is on main and not from this PR.
  • python -I tests/test_lane_masks.py: OK.
  • The test exercises the real code: support.translate_lines runs tools/rdna2spirv.py and spirv_mini_interp.run_workgroup runs the SPIR-V that it emits. No model of the rule is written in the test.
  • Negative control 1, the PR's own: (0, -1) -> (0,) in lane_masks.kind(). The new test fails with [32, 32, 32, 0] != [3, 3, 3, 3].
  • Negative control 2, narrower: kind() unchanged, but in the BITWISE branch of step() a b32 immediate -1 counts as unknown. Only the new test fails; tests/test_lane_masks.py and the other 12 tests/semantic files that use lane_masks stay green. So this test is the only one that pins s_and_b32 <mask>, -1.
  • Merge with current main (0 commits ahead): clean.

One correction to the description, not blocking: with negative control 1, not all mask-related files stay green. tests/semantic/test_wave64_vcc_half_write.py fails 17 subtests (for example test_mask_and_const_half_writes_keep_vcc_mask: {} != {'vcc': 'mask'}, the s_mov_b32 vcc_hi, -1 copy path). tests/test_lane_masks.py also fails (AssertionError: v_bfi_b32). Both pass without the change. The -1 rule was already pinned for copies and v_bfi_b32. This PR adds the SALU bitwise path, which negative control 2 shows nothing else catches.

Overlap: #6502 "a mask parked in lane 8 survives a word written to lane 40" and #6572 "v_mov_b32 of a lane mask keeps the lane that is off in EXEC" add different tests at the same place in tests/semantic/test_lane_masks_edge_cases.py. They are not duplicates, but each pair of the three conflicts (git merge-tree), so the second and third to land need a rebase.

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 0505665 merged with main e36d4c4 on Linux/Python 3.12.16: pass

Test-only (one new test in tests/semantic/test_lane_masks_edge_cases.py, test_an_and_with_minus_one_keeps_a_lane_mask_a_mask).

  • python -I -m unittest discover -s tests/semantic -p test_lane_masks_edge_cases.py: 7 tests OK
  • Negative control (mutation, since no source file changes): in tools/lane_masks.py kind(), a["v"] in (0, -1) changed to a["v"] in (0,) so -1 is no longer read as the constant EITHER. The same command then gives FAILED (failures=1), the failing test is the new test_an_and_with_minus_one_keeps_a_lane_mask_a_mask; restored with git checkout HEAD --.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants