Skip to content

rdna2spirv: implement v_cmp_class_f64 and v_cmpx_class_f64 - #2535

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
FaKL-Code:shader-cmp-class-f64
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
FaKL-Code:shader-cmp-class-f64

Conversation

@FaKL-Code

Copy link
Copy Markdown
Contributor

Implements v_cmp_class_f64 and v_cmpx_class_f64 in tools/rdna2spirv.py (claimed in #2300 (comment)). Separate from #2254 (v_cmp_class_f16 / v_cmpx_class_f16).

What & Why

  • Adds Gen.cmp_class_f64 for v_cmp_class_f64 (e32/e64, writing VCC or an SGPR lane mask) and v_cmpx_class_f64 (e32/e64, narrowing EXEC).
  • Evaluates all 10 IEEE-754 binary64 numeric classes (0 sNaN, 1 qNaN, 2 -inf, 3 -normal, 4 -subnormal, 5 -0, 6 +0, 7 +subnormal, 8 +normal, 9 +inf) using pure 32-bit %uint bit extraction on (lo, hi) — no Float64 capability required, so it works on devices without shaderFloat64 and executes directly in spirv_mini_interp.
  • Handles VGPR/SGPR pairs, float inline constants (fimm), sign-extended inline integers (-16..64), 32-bit literals in bits [63:32] (per RDNA2 ISA), and VOP3 abs/neg sign-bit modifiers on src0 (abs clears bit 63 first, neg flips bit 63 second, without quieting sNaN).
  • Inactive lanes write 0 for v_cmp_class_f64 and stay inactive for v_cmpx_class_f64; invalid operands/masks/destinations/modifiers raise Unsupported.

Changes

  • tools/rdna2spirv.py: added Gen.cmp_class_f64 and dispatch for v_cmp_class_f64 / v_cmpx_class_f64.
  • tests/semantic/test_cmp_class_f64.py: added CPU semantic tests covering all 10 classes (including payloads solely in the low 32 bits), complementary/high-bit masks, SGPR pairs, fimm/inline/literal constants, abs/neg/-|x|, v_cmpx_class_f64 EXEC narrowing, inactive lanes, absence of OpCapability Float64, and rejected forms.
  • docs/design.md: added the translator contract table row (marked Not GPU-verified).

Verification

  • Environment: Windows 11 x64, Python 3.14.4 (python -I), CPU-only (not GPU-verified), synthetic fixtures only (no game files).
  • python -m compileall -q make_game.py tools tests — pass
  • python -I tests/semantic/test_cmp_class_f64.py -v — 6/6 pass
  • python -I tests/semantic/test_vop3_const_mods.py -v — 10/10 pass
  • python -I tests/test_shader_meta.py — 15/15 pass
  • python -I tests/test_docs_links.py — 5/5 pass
  • python -I tests/test_docs_repo_paths.py — 2/2 pass
  • python -I tests/test_text_write_line_endings.py — 2/2 pass
  • python -I tests/test_isa_coverage.py — 10 pass, 3 skipped (no local ISA XML)

AI-assisted (Gemini).

@duudiis

duudiis commented Nov 22, 2026 •

Copy link
Copy Markdown

Independent GPU verification at 37bdaa8 on Windows 11, RTX 5070 (driver 621.24, Vulkan subgroups 32..32). I translated a synthetic compute shader for native wave32 and for wave64 emulated on the same device. Both modules passed spirv-val --target-env vulkan1.2 and emitted neither OpCapability Float64 nor a 64-bit float type.

For each wave configuration, all 2,048 classification results matched an independent binary64 bit-pattern oracle (512 inputs, each tested unmodified, negated, absolute, and negative absolute). The inputs covered all ten classes, including signaling NaNs and subnormals with payloads solely in the low word. The unmodified comparisons used E32 into VCC with a VGPR mask. The modified E64 comparisons wrote SGPR masks and ignored a set bit above bit 9.

A pair of E32/E64 EXEC-only compares also matched all 1,024 output slots per wave configuration. Pre-disabled lanes stayed disabled even with matching input, and a distinct VCC-selected value survived both compares. All six PR CPU tests passed as well. The wave64 evidence here is for the translator's emulation path on NVIDIA.
Recheck: the first synthetic header omitted the FSSM magic, so its 64-thread run used wave32. I corrected the header, added explicit assertions for the translator's wave64 and emulation flags, and reran both configurations on the same commit. The counts and exact results above are confirmed by the corrected runs.

@timelery

Copy link
Copy Markdown
Contributor

Independent native RDNA2 hardware verification (AMD Radeon(TM) Graphics \gfx1036, Windows driver \32.0.21042.62, via \ ools/hw_oracle/\ in both wave32 and wave64, both \ lush\ \MODE=0x1c0\ and \ieee\ \MODE=0x3c0):

All rules implemented here match real \gfx1036\ silicon:

  • All 10 binary64 class bits (\S1[9:0]), including low-word-only significands (\sNaN\ with \lo=1\ / \lo=0x80000000\ -> \

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested head 37bdaa8 merged onto main 4947579 (clean merge), Windows 11, Python 3.13, CPU only. python -m pytest tests/semantic/test_cmp_class_f64.py: 6 passed, 31 subtests passed in 1.29s. Negative control: the same test file against main's non-test sources gives 28 failed, 2 passed, 7 subtests passed in 162.38s (0:02:42), so the test exercises the change.

AI-assisted (Claude Code); runs on my machine.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 37bdaa8 on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:

  • scripts/run_gpu_tests.py: 139/185 passed, 46 skipped, 0 failed. main 4947579 gives 139/185, 46 skipped, 0 failed. All 190 test shaders translate and pass spirv-val.
  • tests/semantic/test_cmp_class_f64.py: ran 6 tests in 0.423s; OK.

AI-assisted (Claude Code).

@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 685d16ed on AMD Radeon RX 9070 XT (RDNA4, subgroup 32..64), AMD 26.11.2, Windows 11 Pro 10.0.26300, AMD Ryzen 7 9800X3D CPU (64 GB RAM), Python 3.12.10: pass.

Runtime and test programs built from this head (MSVC 14.51, Ninja, RelWithDebInfo), native Windows llvm-mc 21.1.8, Vulkan SDK 1.4.363.0. No game files.

run result
run_gpu_tests.py (whole suite, native wave64) 175/189, 14 skipped, 0 failed (main 49475796: 170/185)
same with LEONIDA_W64_EMULATE=1 175/189, 14 skipped, 0 failed
pytest tests/test_translate.py 541 passed, 4 skipped in 62.44s (0:01:02)
unittest discover -s tests/semantic -p test_cmp_class_f64.py 6 OK

No suite shader uses v_cmp_class_f64/v_cmpx_class_f64, so the GPU rows show no regression, not the new ops on hardware; the semantic test covers those. The suite count is higher than main's because this head includes a newer main.

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

@ItsNotRexed
ItsNotRexed merged commit 2ae34a7 into ItsNotRexed:main Nov 22, 2026
2 of 4 checks passed
@Yourrespawn

Copy link
Copy Markdown
Contributor

Heads-up from a GPU test run (RTX 4080, Windows 11 Pro 10.0.26200, Python 3.12.10): two of this PR's rejection tests fail on current main aa2988cc:

FAIL: test_rejected_forms (test_cmp_class_f64.CmpClassF64Tests.test_rejected_forms)
  (line='v_cmp_class_f64_e64 s4, v[0:1], -v2')      AssertionError: Unsupported not raised
FAIL: test_rejected_forms (test_cmp_class_f64.CmpClassF64Tests.test_rejected_forms)
  (line='v_cmpx_class_f64_e64 s4, v[0:1], 0x1')     AssertionError: Unsupported not raised

So v_cmp_class_f64_e64 with a source neg modifier and v_cmpx_class_f64_e64 with a literal source now translate instead of raising — either the tests pinned the wrong rule or a later merge changed the acceptance; either way the suite is red on main since this landed. (I found this while bisecting an unrelated PR's failures; the same two failures reproduce on a clean aa2988cc checkout.)

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

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