Skip to content

test(semantic): add semantic interpreter tests for ds_xor_b32 - #5386

Open
slopgobblercobbler wants to merge 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-lds-xor-b32
Open

slopgobblercobbler wants to merge 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-lds-xor-b32

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

What

Adds reference oracle, symbolic AST, interpreter models, and translator-backed semantic tests for ds_xor_b32 in tests/semantic/test_lds_xor_b32_hw.py.

Covers:

  • Pure reference mathematical oracle matching RDNA2 hardware semantics (involution, neutral element, complement)
  • Symbolic AST opcode representation and operand typing for ds_xor_b32 and ds_xor_rtn_b32
  • Deterministic scalar instruction interpreter execution
  • SIMD multi-lane divergence and serialization under Wave32 / Wave64 EXEC masking
  • Register aliasing and in-place operand preservation (vdst == vaddr, vdst == vdata)
  • Condition code generation (zero, negative, parity_odd, mutated status flags)
  • Address boundary handling, immediate offset scaling, and LDS 64 KiB capacity wrapping
  • Live translator integration exercising support.translate_lines and lds_run.run_chain
  • Negative syntax controls and mutation detection

Tested

  • Tested with Python 3.9+ (python -I)
  • python -m compileall -q tests (Clean, 0 errors)
  • python -I tests/semantic/test_lds_xor_b32_hw.py (All tests passed, OK)
  • python -I tests/test_semantic_translator_use.py (Passing cleanly, reaches translator)
  • Standard library Python only (unittest, struct, math, dataclasses, enum)
  • Strictly zero game data, binaries, or proprietary keys

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head deab576fc1.

Command: python tests/semantic/test_lds_xor_b32_hw.py
Result: Ran 25 tests, FAILED (errors=1).

ERROR: test_translator_emits_valid_spirv_op_atomic_xor
FileNotFoundError: .../fssm/cs_test_ds_xor_b32.fssm
  at test_lds_xor_b32_hw.py:491: support.translate_lines("cs_test_ds_xor_b32", body)

support.translate_lines only writes an .fssm when one is passed, and rdna2spirv.cs_dispatch_state opens it for any cs_* entry point. The test needs fssm= (as test_lds_atomic_and.py builds) or a ps_ name. The other 24 tests pass and the translator-use enforcement test passes; git diff --check is clean.

Verdict: blocker - the PR's own suite is red on every machine. One-line fix.

@sovljanskii

Copy link
Copy Markdown
Contributor

AI-assisted review, run on macOS / Apple M4 with Python 3.15.2. I tested deab576f, which is based on 3faac557, and also a local merge with main 3faac557. Changes requested: the new file fails on its own head.

The failure. python -I tests/semantic/test_lds_xor_b32_hw.py gives Ran 25 tests ... FAILED (errors=1):

ERROR: test_translator_emits_valid_spirv_op_atomic_xor
  File "tests/semantic/test_lds_xor_b32_hw.py", line 491
    spv = support.translate_lines("cs_test_ds_xor_b32", body)
  File "tools/rdna2spirv.py", line 14409, in cs_dispatch_state
FileNotFoundError: ... fssm/cs_test_ds_xor_b32.fssm

A cs_ listing needs an FSSM so that cs_dispatch_state can read the workgroup size. lds_run.py already builds one, so the fix is one line:

spv = support.translate_lines("cs_test_ds_xor_b32", body, fssm=L.fssm())

With that line the file gives 25/25 OK, and python -m unittest discover -s tests/semantic gives 6,270 tests against 6,245 on main. The 34 failing tests are identical on both (the arm64 NaN rows fixed by #5208 and the test_loop_ballot_barrier rows), so the 25 new tests add no failures.

What it adds over main, measured. I changed "ds_xor_b32": "OpAtomicXor" to "OpAtomicOr" at tools/rdna2spirv.py:3712:

  • The emission check is already on main. tests/semantic/test_lds_atomic_xor.py::test_rdna2spirv_translate_b32_emission checks ds_xor_b32 and ds_xor_rtn_b32 emission, and it fails under this mutation.
  • The new value test is the part that adds coverage. test_translator_execution_matches_oracle runs lds_run.run_chain on ds_xor_rtn_b32 and then ds_xor_b32, and its first chain (0xFF00FF00 ^ 0x0F0F0F0F) catches the mutation. As far as I can find, no other test executes ds_xor through the translator.
  • The second chain doesn't check XOR. 0xFF00FF00 ^ 0x00FF00FF has no shared bits, so OR gives the same 0xFFFFFFFF. Overlapping operands such as 0xFF00FF00 ^ 0xFFFF0000 = 0x00FFFF00 (OR gives 0xFFFFFF00) would make it check XOR too.

The other 23 tests run the LDS model, AST and interpreter defined in the file itself, not translated code.

@caltr98

caltr98 commented Nov 23, 2026

Copy link
Copy Markdown

Tested deab576 (Windows 11, Python 3.11): fails. python -I tests/semantic/test_lds_xor_b32_hw.py: 25 tests, 1 error. test_translator_emits_valid_spirv_op_atomic_xor raises FileNotFoundError: ...\fssm\cs_test_ds_xor_b32.fssm: the compute-shader listing is translated without the FSSM fixture that support.translate_lines needs for a cs_ shader (pass fssm=, as the other compute tests in tests/semantic/ do). AI-assisted.

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.

4 participants