Skip to content

test(semantic): add reference oracle and semantic tests for v_mul_clamp_f16 - #2824

Merged
ItsNotRexed merged 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-mul-clamp-f16
Nov 22, 2026
Merged

ItsNotRexed merged 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-mul-clamp-f16

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

What and why

Adds a bit-accurate reference mathematical oracle and comprehensive semantic validation suite for v_mul_clamp_f16 in tests/semantic/test_valu_mul_clamp_f16.py.

Covers:

  • Reference mathematical oracle matching AMD RDNA2 ISA hardware specifications
  • Symbolic AST opcode definitions and typed expressions
  • Deterministic scalar instruction interpreter and execution model
  • SIMD multi-lane divergence under Wave32 and Wave64 EXEC masking
  • Register aliasing hazards and in-place operand preservation
  • Condition codes, status flags, and carry/borrow bit generation
  • IEEE 754 boundary extremes: signed zeros, subnormals, infinities, and quiet NaNs
  • Negative controls, syntax rejection, and mutation detection

Tested

  • python -m compileall -q tests (Clean, 0 errors)
  • python -I tests/semantic/test_valu_mul_clamp_f16.py (All tests pass)
  • Standard library Python only (python -I compatible, 0 external dependencies)
  • AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

@Yourrespawn

Copy link
Copy Markdown
Contributor

This suite tests an instruction that does not exist in the RDNA2 ISA, so its oracle pins invented semantics. Three independent checks (Windows 11 Pro 10.0.26200):

  1. v_mul_clamp_f16 is not an RDNA2 instruction. llvm-mc 21.1.8 with -mcpu=gfx1030 rejects the mnemonic outright ("invalid instruction"). Clamp is a VOP3 modifier on v_mul_f16 (v_mul_f16_e64 ... clamp), which is exactly how the repo already treats it: docs/design.md row 241 lists the plain f16 forms "_e64 with neg/abs/clamp" as hardware-verified on RX 6800, and grep -rn mul_clamp over tools/ docs/ tests/ runtime/ finds nothing — the translator has no such opcode and never will from a disassembly.

  2. The NaN rule contradicts what the repo has measured. The docstring says "If S0 * S1 is NaN (including 0 * inf or NaN operand): clamping forces result to +0.0 (0x0000)". The repo's contract table (row 291, same clamp semantics as f32/f64) documents NaN under clamp as left to the driver (GLSL.std.450 FClamp does not define a NaN result); nothing in the repo's hardware measurements pins NaN-under-clamp to +0.0. An oracle that hard-codes a NaN answer asserts more than the ISA or any measurement does.

  3. The suite verifies only itself. It imports no repo code — not tools/rdna2spirv.py, not tests/semantic/spirv_mini_interp.py — so even for a real instruction it would compare the in-file oracle against the in-file interpreter. The repo's established pattern for this kind of work is differential: reference model vs the translator + interpreter (e.g. tools: add differential fuzzer for 32-bit and 16-bit integer VALU ops (valu_int_diff.py) #2820 valu_int_diff.py), with tools/hw_oracle rows where hardware is available.

My suggestion: retarget this file at the real thing it's describing — v_mul_f16 with the VOP3 clamp modifier (and op_sel half selection, which row 241 already pins to hardware) — wire the checks to rdna2spirv.py/spirv_mini_interp.py, and drop or hedge the NaN case to match the documented driver-dependent behavior.

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

@Marukooh

Copy link
Copy Markdown
Contributor

Tested fe18a9f6 on CachyOS Linux, Python 3.14. tests/semantic/test_valu_mul_clamp_f16.py: 35 passed.

The checked-in tests run a Python model. As a separate spot check of the production path, I translated a handwritten fragment shader for v_mul_f16 clamp with 0.5, 1.0, and an upper-half sentinel. Its Vulkan 1.2 SPIR-V validated and all 4,096 pixels matched 0xbeef3800 exactly on an RTX 5070 Ti, NVIDIA 620.73.04. The GPU check covers this case.

AI-assisted, synthetic inputs only.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Measured on gfx1036 (RDNA2, AMD Radeon iGPU, driver 26.10.1, game MODE: ieee 0, dx10_clamp 1, denorm32 0, denorm16_64 3): all 130 cases match. ref_mul_clamp_f16 vs native v_mul_f16_e64 ... clamp in raw hw_oracle kernels, 130 operand pairs (+-0, +-1, 1 +- 1ulp, +-inf, 0 x inf, quiet and signalling NaN, f16 denormals, +-65504, random) with random abs/neg modifiers, low 16 bits compared, 0 mismatches.

AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit 02f7d59 into ItsNotRexed:main Nov 22, 2026
2 checks passed
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.

5 participants