Skip to content

rdna2spirv: v_min_f64 and v_max_f64 as a bit-exact selection - #3917

Closed
evilclanker9000 wants to merge 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:claude/f64-minmax
Closed

evilclanker9000 wants to merge 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:claude/f64-minmax

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-F64-MINMAX, #3796 (comment)

What and why

v_min_f64 and v_max_f64 raised Unsupported. Both are valid gfx1013 forms, found in the same sweep of every gfx1013 opcode form as #3896. No open PR or claim covers them.

Change (tools/rdna2spirv.py, Gen.minmax_f64, Gen.f64_words). The result is one source's 64 bits, selected with integer ops only, so the driver's f64 NaN and denormal handling never enters:

  • A NaN operand, quiet or signalling, gives the other operand.
  • Two NaNs give src0 unchanged.
  • -0 < +0.
  • Subnormals order by value.
  • Everything else is the numeric order: an unsigned compare of the sign-magnitude words, mapped to a total order.
  • VOP3 abs/neg act on the sign bit and clamp applies. The omod is ignored, as on hardware while f64 denormals are kept (see rdna2spirv: v_mul_f64 and v_fma_f64 #3896).

Measured natively on RDNA2 gfx1036 (Radeon iGPU of a Ryzen 9 9950X3D, driver 26.10.1, tools/hw_oracle raw wave32 kernels, v0-v15 / s4-s15): 28 words, all reproduced by the translator. The set covers:

  • min and max of a quiet NaN against a number in both orders, two NaNs, and a signalling NaN in both orders;
  • ±0 in both orders, positive and negative subnormals against 0, and -inf;
  • mul:2, clamp, abs/neg, and the inline constant 0.5.

The measurements use MODE.IEEE off, the MODE inferred for the game. With IEEE on, the only difference is a signalling NaN operand: the hardware returns it quieted instead of returning the other operand. That case is documented and not modelled.

New contract row in docs/design.md.

Tested

Windows 11, LLVM llvm-mc (-mcpu=gfx1013), VK_LOADER_LAYERS_DISABLE=~implicit~, one GPU at a time, python -I scripts/run_gpu_tests.py --filter cs_w32_f64_minmax:

GPU Driver Result
AMD Radeon RDNA2 iGPU, Ryzen 9 9950X3D 26.10.1 PASS 0 1074266112 0 2147483648 1 0 1 2146435072
NVIDIA GeForce RTX 5080 616.92 PASS, same words
  • New fixture: runtime/test/shaders/cs_w32_f64_minmax.asm. It covers a quiet NaN, -0/+0, a subnormal with an ignored mul:2, and two NaNs giving src0. The words are derived in its header. Registered in check.py, run_gpu_tests.py and regen_fixtures.py.
  • New test: tests/semantic/test_f64_minmax.py checks the 28 measured words through tests/spirv_interp.py, a plain-Python reference of the rule against the same words, and the fixture words through spirv_mini_interp.
  • Before the fix: on main the test errors with Unsupported: v_min_f64 / v_max_f64.
  • Negative control: making a NaN src0 always give src1 fails 6 tests, and the Radeon run fails with ... 1 2146959360. Reverted.
  • Passing: python -m unittest discover -s tests/semantic, python tests/semantic/regen_fixtures.py --check (clean), python -I tests/test_shader_checks.py, and pytest tests/test_docs_design_rows.py tests/test_run_gpu_tests.py.

AI-assisted.

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.

One source's 64 bits, chosen with integer ops: a NaN operand gives the
other one, two NaNs give src0, -0 < +0, subnormals by value; clamp applies,
the omod is ignored. 28 words measured natively on gfx1036 (IEEE off).
GPU fixture cs_w32_f64_minmax, semantic test test_f64_minmax.py,
design.md row.

AI-assisted.
@ray3242

ray3242 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

This overlaps #1976 by @IAmNotSiob. In 855870a that PR added v_min_f64/v_max_f64, and also v_mul_f64/v_fma_f64 (#3896), as part of 15 f64 ops. It is open but conflicts with main, and was checked on an RTX 6000 Ada only.

I ran this PR's and #3896's tests with #1976's translator. Its NaN selection and omod disagree with your gfx1036 words. The case-by-case table is in my comment there.

AI-assisted (Devin).

@evilclanker9000

Copy link
Copy Markdown
Contributor Author

Closing: duplicate of #1976 (open earlier); measurements posted there. AI-assisted.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 54ec81f merged into main aa2988cc (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • New test passes natively: cs_w32_f64_minmax (0 1074266112 0 2147483648 1 0 1 2146435072).
  • Whole run_gpu_tests.py: 197/211 native, 197/211 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 47/47.
  • tests/semantic/test_f64_minmax.py: 3 passed, 52 subtests passed.

No game files. AI-assisted (Claude Code).

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.

3 participants