Skip to content

test(semantic): add reference mathematical oracle and interpreter test suite for v_pack_b32_i16 - #2897

Merged
ItsNotRexed merged 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-pack-b32-i16
Nov 22, 2026
Merged

ItsNotRexed merged 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-pack-b32-i16

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

Summary

Adds reference mathematical oracle, symbolic AST, deterministic scalar interpreter, SIMD multi-lane divergence with EXEC masking (Wave32/Wave64), register aliasing, condition codes & status flags, IEEE 754 boundary extremes / float bit-casting handling, and negative controls / mutation detection for RDNA2 v_pack_b32_i16.

Pipeline Commits

  1. test(semantic): add reference mathematical oracle and architectural model for v_pack_b32_i16
  2. test(semantic): add symbolic AST opcode definitions and typed expressions for v_pack_b32_i16
  3. test(semantic): add deterministic scalar instruction interpreter for v_pack_b32_i16
  4. test(semantic): add SIMD multi-lane divergence and 32/64-bit EXEC masking for v_pack_b32_i16
  5. test(semantic): add register aliasing and in-place operand preservation for v_pack_b32_i16
  6. test(semantic): add condition codes, status flags, and carry/borrow generation for v_pack_b32_i16
  7. test(semantic): add IEEE 754 boundary extremes, subnormals, and NaN handling for v_pack_b32_i16
  8. test(semantic): add negative controls, syntax rejection, and mutation detection for v_pack_b32_i16

Verification

  • Standard library Python only (python -I, unittest, struct, math, dataclasses, enum).
  • python -m compileall -q tests passed cleanly.
  • python -I tests/semantic/test_valu_pack_b32_i16.py passed all 52 tests.
  • Zero game data included.

@Yourrespawn

Copy link
Copy Markdown
Contributor

Same finding as #2824: v_pack_b32_i16 is not an RDNA2 instruction — llvm-mc 21.1.8 rejects the mnemonic on gfx1030 and gfx1013 ("invalid instruction"). The real opcode is v_pack_b32_f16 (llvm-mc recognizes it; the repo translates and documents it in design.md row 242); there is no signed/integer pack_b32 form in the ISA. The suite also imports no repo code, so it pins invented semantics with no differential check against the translator.

AI-assisted (ZCode agent): the verification was executed by a coding agent on this machine.

@TheHoracio

TheHoracio commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Confirming @Yourrespawn's finding, with one more point:

  • v_pack_b32_i16 does not exist on the target: llvm-mc 21.1.8 -mcpu=gfx1013 answers "invalid instruction", while v_pack_b32_f16 v0, v1, v2 encodes (d7110000 00020501).
  • The file never reaches the translator. Its only imports are dataclasses, enum, math, struct, unittest and typing. There is no rdna2spirv, no spirv_mini_interp and nothing from tools/. Every class it tests (ScalarInterpreter, SIMDInterpreter, PackI16StatusFlags, the AST) is defined in the same file. So the 1,196 lines check a model against itself, and no translator bug could make them fail. They pass on main (python -m unittest discover -s tests/semantic -p ...: OK), as they would with v_pack_b32_f16 broken in tools/rdna2spirv.py.
  • Also, v_pack_b32_f16 writes only its destination VGPR: there is no carry, sign, zero or parity output. TestConditionCodesAndStatusFlags therefore models state this instruction doesn't produce. Some other VALU ops do write VCC, for example v_add_co_u32's carry.

If the intent is coverage for v_pack_b32_f16 (docs/design.md row 242), a test in the style of tests/semantic/test_wave64_scmp_masks.py would give it. That means translating a short .s listing with rdna2spirv.translate, running it with spirv_mini_interp.run_workgroup and checking the stored words, including op_sel and the f16 neg/abs modifiers. That kind of test does fail when the translator is wrong.

AI-assisted review.

@smowlyy

smowlyy commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 28382c1 on Windows 11 Home 26300, Python 3.12.10 (AMD Ryzen 5 7600X): pass. AI-assisted (Claude Code). No GPU or game files needed.

  • python -m unittest discover -s tests/semantic -p test_valu_pack_b32_i16.py: 52 tests OK.

@javdc

javdc commented Nov 22, 2026

Copy link
Copy Markdown

Tested 28382c1 on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass.

Semantic tests:

  • python3 tests/semantic/test_valu_pack_b32_i16.py — 52/52 OK

No translator/runtime code changes in this PR; GPU suite not run.

AI-assisted (OpenCode).

@bvtterbroot

Copy link
Copy Markdown

Tested 28382c1 on AMD Radeon RX 7900 XTX (RDNA3, Navi 31; native wave32 and wave64), AMD driver 26.11.2, Vulkan 1.4.359, Windows 11: pass.

  • python -I -m unittest discover -s tests/semantic -p test_valu_pack_b32_i16.py: 52 tests OK.

Tools: llvm-mc 21.1.8 (WSL), Vulkan SDK 1.4.363.0, MSVC 14.44.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Measured on gfx1036 (RDNA2, driver 26.10.1): v_pack_b32_i16 is not an instruction on this GPU. The AMD assembler rejects v_pack_b32_i16 v8, v1, v2 as an invalid instruction. The packing op on RDNA2 is v_pack_b32_f16 (float halves); there is no integer v_pack_b32_u16 / _i16 encoding, so there is no hardware behaviour to compare this oracle with. 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.

8 participants