Skip to content

test(semantic): add semantic interpreter tests for v_sad_hi_u16 - #5365

Open
slopgobblercobbler wants to merge 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-sad-hi-u16
Open

slopgobblercobbler wants to merge 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-sad-hi-u16

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

What

Adds reference oracle and semantic interpreter tests for v_sad_hi_u16 in tests/semantic/test_valu_sad_hi_u16.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_sad_hi_u16.py (Passed)
  • Standard library only (unittest, struct, math), strictly zero game data

@cynbun

cynbun commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Reviewed 24da2a0 (code read + CPU tests on Linux, Python 3.14): not ready.

The file runs (python -I tests/semantic/test_valu_sad_hi_u16.py: 56 OK; python -m unittest discover -s tests/semantic: 73 OK), but:

  • v_sad_hi_u16 does not exist in RDNA2. llvm-mc -arch=amdgcn -mcpu=gfx1030 rejects v_sad_hi_u16 v0, v1, v2, v3 ("invalid instruction"). The SAD ops are v_sad_u8, v_sad_hi_u8, v_sad_u16, v_sad_u32 and v_msad_u8, all of which are already implemented (tools/rdna2spirv.py:7627) and covered (docs/design.md:392, tests/semantic/test_alu_sad.py). v_msad_hi_u16 (docstring lines 17-24, ref_msad_hi_u16 line 142) doesn't exist either.
  • It imports only the standard library (lines 43-48) and never calls the translator. The oracle ref_sad_hi_u16 (line 127) is compared with the file's own interpreters. Copied alone into an empty directory, it still passes 56/56, so it cannot catch a translator regression.
  • clamp is modelled as saturating to 0xFFFFFFFF (lines 137-138). For the real SAD ops, docs/design.md:392 says the translator raises Unsupported on clamp, because the ISA pseudocode doesn't define it.
  • TestValuSadHiU16IEEE754Boundaries (line 1045) feeds f16/f32 NaN and subnormal bit patterns to an integer op, so it only re-checks integer subtraction.

Since the instruction doesn't exist and the existing SAD ops are covered, I'd suggest closing this PR.

AI-assisted review (Claude Code).

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested 24da2a0 (merged onto main 3faac55) on Apple M4, macOS, CPU only, Python 3.15.2. This is a second check, and it agrees with cynbun's review:

  • llvm-mc -arch=amdgcn -mcpu=gfx1030 rejects v_sad_hi_u16 v0, v1, v2, v3 ("invalid instruction") and assembles v_sad_u16.
  • On a one-line synthetic pixel shader, tools/rdna2spirv.py raises Unsupported: v_sad_hi_u16 and translates v_sad_u16.
  • python3 -I tests/test_semantic_translator_use.py fails on this head: "test_valu_sad_hi_u16.py: imports no rdna2spirv and no helper that does".
  • Copied alone into an empty folder, the file still passes 56/56, so no change in the repository can make it fail.

The real SAD ops are already covered by tests/semantic/test_alu_sad.py. I'd close this PR too.

AI-assisted; no game files.

@memorypressure

Copy link
Copy Markdown

The 56 tests pass on a merge with main 3faac55 (re-run) and the model is internally sound — but please confirm the instruction exists on gfx10 before merge, because I could not find it anywhere: v_sad_hi_u16 appears zero times in the repo's ISA opcode tables (rdna2_isa_tables.py, which lists v_sad_u8/hi_u8/u16/u32, v_msad_u8, qsad_pk_u16_u8, mqsad_pk_u16_u8, mqsad_u32_u8) and zero times in the translator (rdna2spirv.py implements exactly that family), and the modeled (sum<<16)+src2 accumulation is GCN's V_MSAD_HI_U16 — also absent from RDNA2 — which contradicts main's test_alu_sad_hi_u32.py, where "hi" means the high word of the 64-bit sum. Green tests pinning an instruction the ISA tables do not define is the dot4acc-fake pattern (#3539), so this wants confirmation against a real RDNA2 disassembly or retargeting to the real mnemonic. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@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 24da2a00103f352a820f803d5a167126db49f119 (base 0aa98400, 8 commits; main is 3faac557b).

Blockers:

  1. Not a translator test. python tests/semantic/test_valu_sad_hi_u16.py -> 56 tests OK, but python -I tests/test_semantic_translator_use.py -> FAILED (failures=1): tests/semantic/test_valu_sad_hi_u16.py:1: imports no rdna2spirv and no helper that does. Same failure after merging 3faac557b locally, so CI is red after merge. The suite exercises its own oracle/interpreter only.

  2. v_sad_hi_u16 is not in the RDNA2 ISA: llvm-mc 21 says "invalid instruction"; the ISA table has v_sad_hi_u8 (0x15b) but the 16-bit family stops at v_sad_u16 (0x15c). There is no v_sad_hi_u16, so no listing or hardware result can confirm the numbers.

  3. The PR lists "IEEE 754 float boundaries, subnormals, and signed zeros" (and the file imports math) for an unsigned-integer SAD; that section tests the template, not the instruction.

Same 8-commit template as #5359/#5360/#5364/#5368/#5371.

@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.

Merging main (3faac557b) into this head and running the semantic guard fails:

python -I -m pytest tests/test_semantic_translator_use.py -q -> 1 failed, 2 passed, test_every_semantic_test_reaches_the_translator: tests/semantic/test_valu_sad_hi_u16.py imports no rdna2spirv and no helper that does.

Fix, following #3448/#3457/#3472: keep the operand tables and expected words, replace the private interpreter with support.translate_lines plus the mini interpreter, and pin Unsupported where the translator has no lowering yet (as #4397 does). Python only, no game files, no GPU.

Also raised in #5361 by @JakubRasken, who found the same nine files across the batch.

@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.

ISA check on the opcode this test models: "invalid instruction" on gfx1013 and gfx1030 (llvm-mc -arch=amdgcn -mcpu=<gpu>, LLVM 21).

  • v_sad_hi_u16 has zero hits in tools/rdna2_isa_tables.py, tools/rdna2spirv.py and docs/design.md.
  • gfx1013: and gfx1030

If the instruction is real but LLVM does not know it, the PR needs the ISA source and the correct encoding, and the test should say which GPU it exists on. If it is a spelling variant, please rename to the mnemonic LLVM accepts. As it stands the test exercises an opcode the project's RDNA2 translator cannot receive, in addition to the semantic guard failure noted above.

(Together with the guard failure this looks like a close-or-rework rather than a rebase.)

@caltr98

caltr98 commented Nov 23, 2026

Copy link
Copy Markdown

Review of 24da2a0: changes suggested. v_sad_hi_u16 is not in tools/rdna2_isa_tables.py (the decoder has v_sad_hi_u8 and v_sad_u16), and the file never calls tools/rdna2spirv.py or tests/semantic/support.py, so its tests check a model written inside the file, not the translator. Your newer semantic PRs (e.g. #5838, #5817) translate a listing through support; the same pattern here would test the real op. Same issue as #5359 and #5360. 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.

6 participants