Skip to content

test(semantic): add semantic interpreter tests for v_div_fixup_f16 - #3709

Closed
slopgobblercobbler wants to merge 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-div-fixup-f16
Closed

slopgobblercobbler wants to merge 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-div-fixup-f16

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

What

Adds reference oracle and semantic interpreter tests for v_div_fixup_f16 in tests/semantic/test_valu_div_fixup_f16.py.

  • Architectural reference model and bitfield verification
  • SIMD multi-lane divergence under Wave32 / Wave64 EXEC masking
  • IEEE 754 float boundaries, subnormals, and signed zeros
  • Negative rejection and syntax validation

Tested

  • Tested with Python 3.9+ (python -I)
  • python -m compileall -q tests (Passed)
  • python -I tests/semantic/test_valu_div_fixup_f16.py (Passed)
  • Standard library only (unittest, struct, math), strictly zero game data

@2-CD

2-CD commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Linux, no GPU (headless Ubuntu 24.04.5, no Vulkan device): checked head f30b2e12673c0d88a4c1126f0121670d3686633a (base f847748).

CPU-only — this box has no GPU, so the runtime/GPU ctest suite was not built or run. This PR adds one semantic test file and touches no other code.

  • python -m compileall -q tests/semantic/test_valu_div_fixup_f16.py → OK.
  • python -m unittest discover -s tests/semantic -p test_valu_div_fixup_f16.py → Ran 48 tests, OK, exit 0.

The new test drives the repository's translator / semantic interpreters on hand-written RDNA2 fixtures for V_DIV_FIXUP_F16 — no game data, no GPU. CI on this head: change-scope and no-game-data are queued (fork PR awaiting maintainer approval), so there was no CI result to reproduce — this is an independent local check.

Synthetic fixtures only, no game files. AI-assisted (opencode); runs on my machine.

@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Reviewed and tested f30b2e12 on Windows 11 Pro 10.0.26300, AMD Ryzen 7 9800X3D CPU (64 GB RAM), AMD Radeon RX 9070 XT (AMD 26.11.2), Python 3.12.10: changes suggested.

run result
unittest discover -s tests/semantic -p test_valu_div_fixup_f16.py 48 OK

Review: I read the whole new file and compared it with the v_div_fixup_f16 lowering on current main (tools/rdna2spirv.py:7615-7690), its contract in docs/design.md:382, and the existing tests tests/semantic/test_alu_div_fixup.py and tests/semantic/test_valu_div_fixup.py. The file imports only enum, math, struct and unittest, so none of its 48 tests reach the translator. The "scalar interpreter", SIMD, aliasing and mutation tests all check the file's own ref_div_fixup_f16 against itself, so they cannot fail on any change to the repository. 2-CD's comment says the test "drives the repository's translator / semantic interpreters", but no repository module is imported. I ran the PR's oracle on the f16 cases in test_alu_div_fixup.py, and it gives a different answer from the translator in three places (finding 2).

  1. tests/semantic/test_valu_div_fixup_f16.py:25-28, :779: DivFixupF16ScalarInterpreter.execute (and SIMDWaveState) just call the in-file ref_div_fixup_f16. The mutation tests (:1582-1637) compare in-file mutants against that same oracle. So breaking rdna2spirv.py's v_div_fixup_f16 lowering still leaves all 48 tests passing. To test the repository, the file should drive rdna2spirv.translate + spirv_mini_interp.run_fragment as test_alu_div_fixup.py does. Otherwise it should say plainly that it is a standalone model, as the scope note in test_valu_div_fixup.py does.

  2. tests/semantic/test_valu_div_fixup_f16.py:210-215: the oracle disagrees with the translator's documented contract on these inputs (oracle ran here; translator values read from rdna2spirv.py:7652-7679 and test_alu_div_fixup.py):

    • NaN quotient: s0=0x7E35, s1=0xC000, s2=0x3C00. Oracle → 0xFC00 (−inf). Translator → 0xFE35 (sign-fixed passthrough, case nan_quot_signed_passthrough). test_s0_nan_overflow (:335-340) and test_mutation_detection_s0_nan_overflow (:1598-1603) assert the oracle's answer.
    • Underflow edge: s0=0x3C00, s1=0x6800 (2048), s2=0x0400 (2^-14), exponent difference exactly −25. Oracle → 0x3C00, because it tests < -25 on unbiased exponents. Translator → 0x0000, because it tests biased ediff < -24.
    • Overflow: s0=0x3C00, s1=0x0400, s2=0x7800. Oracle → 0x3C00, because it has no overflow branch. Translator → 0x7C00 (case exp_overflow_to_inf).

    Question: which f16 behaviour is intended for these three cases? f16 has not been measured on hardware. The measured f32 row (docs/design.md:424) shows NaN(S0) → ±inf and no overflow check. On main, the comment at rdna2spirv.py:7618 and the docstring at test_alu_div_fixup.py:8 also say NaN(S0) → ±inf, but the code, its test case and docs/design.md:382 pass it through. As it stands, this file asserts one answer and the translator produces another, with no test connecting them.

  3. Overlap: main already has a standalone f16 oracle, tests/semantic/test_valu_div_fixup.py (scoped in rdna2spirv: implement v_div_fixup_f32 (measured on RDNA2 gfx1036) #2858). Its docstring (:27-29) uses different rules again: s1 NaN first, canonical NaN 0x7E00. This PR follows the translator on NaN priority and 0xFE00 but not on the three cases above, so it would make a third f16 model. Folding the useful cases into test_alu_div_fixup.py would avoid that.

AI-assisted (Claude Code); I checked the results.

@ItsNotRexed

Copy link
Copy Markdown
Owner

Closing: the tests never exercise the translator (they model the instruction in Python without calling tools/rdna2spirv.py), so tests/test_semantic_translator_use.py rejects them. Please translate a listing through support.translate_* and check its result instead.

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