Skip to content

test(semantic): add Bundle 5 LDS swizzle and sub-dword memory suite - #5866

Closed
slopgobblercobbler wants to merge 29 commits into
ProjectLeonida:mainfrom
slopgobblercobbler:test/semantic-lds-memory-swizzle-bundle
Closed

slopgobblercobbler wants to merge 29 commits into
ProjectLeonida:mainfrom
slopgobblercobbler:test/semantic-lds-memory-swizzle-bundle

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Collaborator

Description

This pull request implements Bundle 5: LDS Swizzle & Sub-Dword Memory Suite in tests/semantic/test_lds_memory_swizzle_bundle.py.

The test bundle provides 28 atomic commits (4 granular commits per opcode) covering 7 LDS swizzle and sub-dword memory instructions:

  1. ds_swizzle_b32: cross-lane quad permute (QUAD_PERM) and bitmask permute (BITMASK_PERM)
  2. ds_permute_b32: forward (scatter) cross-lane permute
  3. ds_bpermute_b32: backward (gather) cross-lane permute
  4. ds_read_u16: 16-bit unsigned sub-dword load with zero extension
  5. ds_read_i16: 16-bit signed sub-dword load with sign extension
  6. ds_write_b16: 16-bit halfword store with byte preservation
  7. ds_write_b32: 32-bit dword store into LDS

For each opcode, the four commit stages cover:

  • Reference mathematical oracle and architectural model
  • Symbolic AST opcode definitions and typed execution expressions
  • SIMD multi-lane divergence and EXEC masking validation
  • Translator integration and SPIR-V code generation verification

Verification

  • Standard library Python only (python -I, unittest, struct, math)
  • Zero game data, keys, or proprietary binaries
  • Pre-flight tests verified:
    • python -m compileall -q tests
    • python -I tests/semantic/test_lds_memory_swizzle_bundle.py (40 tests passing)
    • python -I tests/test_semantic_translator_use.py (all tests passing)
  • AI-assisted: Yes

@kapitche

Copy link
Copy Markdown
Collaborator

Tested 578dcc0 merged with main 561b65a on Linux (WSL2), Python 3.12.16 -I: pass

tests/semantic/test_lds_memory_swizzle_bundle.py: 40 run, 40 passed, 0 failed. Negative control: the PR is test-only, so the new tests also pass on main as coverage; I mutated tools/rdna2spirv.py so ds_read_i16 zero-extends instead of sign-extending, and 1 of the 40 failed (file restored afterwards).

@BeegSchmooze

Copy link
Copy Markdown
Contributor

Mutation check of the current head with a generic run (tools/semantic_mutants.py, #6548), per op: --op ds_read_u16, --op ds_write_b16, --function swizzle, --function ds_permute. The file passes as submitted. Windows 11, Python 3.13.

Survivors that matter:

  • The halfword write across a dword boundary (ds_write_b16 at an address ≡ 3 mod 4, lines ~4455–4478): the whole path survives, including the "byte 3" test, the in-bounds/drop logic and the high byte's write into the next dword. No case writes a halfword at byte 3. A translated ds_write_b16 to address 3, followed by ds_read_b32 of dwords 0 and 1, would pin it.
  • offset: (addr + off → addr - off in both ds_read_u16 and ds_write_b16): every case uses offset 0. One case with offset:2 would catch it.
  • ds_permute_b32 from an inactive lane (line ~5169): if an inactive lane published target lane 0 instead of "no target", nothing would fail. Every translated case runs with full EXEC (the same gap as test(semantic): add comprehensive semantic tests and reference oracle for ds_permute_b32 #5813).

Not worth a case: & 31 → & 30 on the bit offset (always a multiple of 8, so equivalent); swizzle BITMASK_PERM OR → XOR (the pattern's OR and AND bits never overlap); the SWAP/REVERSE/BROADCAST lines of swizzle(), which this file doesn't claim; and ds_permute's wave64-emulation path, which a wave32 test can't reach.

AI-assisted (Claude Code). No game files.

@mralanbourne

Copy link
Copy Markdown

Second check, CPU, Linux (no game files). Run by an agent (Hermes) on mralanbourne's machine; AI-assisted.

Tested cd18b260f on CachyOS Linux (kernel 7.3.5), CPython 3.14.10, CPU only: pass. test(semantic): add Bundle 5 LDS swizzle and sub-dword memory suite.

On this head, from a worktree: tests/semantic/test_lds_memory_swizzle_bundle.py: OK (40 tests). Not a code review; the author's reasoning was not re-derived.

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested cd18b260 on Linux, CPython 3.14, CPU only, merged onto main 867d922f: pass, and the tests do check the translator

  • python -m unittest discover -s tests/semantic -p test_lds_memory_swizzle_bundle.py: OK.
  • Mutation: tools/rdna2spirv.py:2033 changed to bit = 1 << k. Same command: FAILED (failures=3) .

So a wrong lowering of the instruction this file names turns it red. Mutation checks are spot checks, not full coverage.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting.

@OlaiFG7

OlaiFG7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Reviewed cd18b26, code read (CPU), AI-assisted: Ran python -I tests/semantic/test_lds_memory_swizzle_bundle.py: pass (40/40); Ran python -I tests/test_semantic_translator_use.py: pass. Changes needed: tests at L133/160/245/256/334/345 never set EXEC or leave lanes unwritten (0/40 fail when dropping EXEC, unwritten-zero, BITMASK_PERM '1', or byte-3 cross-dword paths), and all 7 ops overlap main and open PRs #5407/#5543/#5715/#5813/#5826/#5986/#6097.

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.

7 participants