Skip to content

rdna2spirv: v_mul_f64 and v_fma_f64 - #3896

Closed
Vonsek wants to merge 1 commit into
ItsNotRexed:mainfrom
Vonsek:claude/f64-mul-fma
Closed

Vonsek wants to merge 1 commit into
ItsNotRexed:mainfrom
Vonsek:claude/f64-mul-fma

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

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

What and why

v_mul_f64 and v_fma_f64 raised Unsupported. Both are valid gfx1013 forms. They turned up in a sweep that translated every gfx1013 opcode form on main; this one was not claimed and not in an open PR. #3230 only touches null sources of the f64 ops main already has.

Change (tools/rdna2spirv.py, the f64 VALU branch):

  • The result is D = S0 × S1 (+ S2) rounded once to binary64, to nearest even, via OpFMul and GLSL.std.450 Fma on %double. Source modifiers work as for v_add_f64.
  • VOP3 clamp applies.
  • The omod is dropped. Measured natively on gfx1036, the omod of these ops is ignored while f64 denormals are kept, whether MODE.IEEE is on or off. It applies only with IEEE off and f64 denormals flushed. The translator assumes f16/f64 denormals are kept.
  • A program that writes MODE.FP_ROUND[3:2] would need the product rounded toward zero. That is not modelled, so both ops raise Unsupported there.

Measured on RDNA2 gfx1036 (Radeon iGPU of a Ryzen 9 9950X3D, driver 26.10.1, tools/hw_oracle raw wave32 kernels, v0-v15 / s4-s15). The table runs with the assembler's default MODE:

case result
v_mul_f64 1.5 × -2 0xc008000000000000 (-3)
v_fma_f64 (1+2^-30)^2 - (1+2^-29) 0x3c30000000000000 (2^-60; rounding the product first gives 0)
v_mul_f64 (1+2^-52)^2 0x3ff0000000000002
v_mul_f64 2^-1022 × 0.5 0x0008000000000000 (subnormal kept; 0 with denorm_mode_16_64 = 0)
v_mul_f64 1.5 × 1.5 mul:2 2.25 with denormals kept (IEEE on or off); 4.5 only with IEEE off and f64 denormals flushed
v_add_f64 1.5 + 1.5 mul:2 3.0 with denormals kept; 6.0 only with IEEE off and flushed

New contract row in docs/design.md.

Finding, not fixed here: the existing v_add_f64 applies its omod. Under the same MODE assumption, the hardware ignores it (last row of the table). This is the binary64 counterpart of #1970 (f16, SHADER-297). I'll post it as a finding rather than change v_add_f64 here.

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_mul_fma:

GPU Driver Result
AMD Radeon RDNA2 iGPU, Ryzen 9 9950X3D 26.10.1 PASS 0 3221749760 0 1009778688 2 1072693248 0 1073872896
NVIDIA GeForce RTX 5080 616.92 PASS, same words
  • New fixture runtime/test/shaders/cs_w32_f64_mul_fma.asm covers -3, the fused 2^-60, 1+2^-51, and omod ignored. The words are derived by hand in its header. It is registered in check.py, run_gpu_tests.py and regen_fixtures.py.
  • New test tests/semantic/test_f64_mul_fma.py runs through tests/spirv_interp.py, which rounds the exact binary64 product and Fma once. It covers nine cases, among them the subnormal, clamp and omod cases. It also includes a plain-Python reference and the refusal under a MODE.FP_ROUND write.
  • On main, the test errors with Unsupported: v_mul_f64 / v_fma_f64.
  • Negative control: I computed v_fma_f64 as a rounded product plus an add. The test fails, and the Radeon run fails with the fused word at 0 (0 3221749760 0 0 ...). I reverted it.
  • Passing: python -m unittest discover -s tests/semantic (no new failures: the 7 failures and 3 errors it reports fail the same way on main aa2988cc, in test_loop_ballot_barrier (emulate), test_vcmp16_opsel (spirv-val), test_cmp_class_f64 (TEST-853) and test_mutations (v_mul_legacy_f32 anchor)), 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 rounding of the exact product (and sum) to binary64, clamp applied, the
VOP3 omod dropped: on gfx1036 it is ignored while f64 denormals are kept,
the MODE the translator assumes. A MODE.FP_ROUND write makes both
Unsupported (no toward-zero product). GPU fixture cs_w32_f64_mul_fma,
semantic test test_f64_mul_fma.py, design.md row.

AI-assisted.
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

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

@crastinator

Copy link
Copy Markdown
Contributor

Tested 93f6f04 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_mul_fma (0 3221749760 0 1009778688 2 1072693248 0 1073872896).
  • 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_mul_fma.py: 4 passed, 11 subtests passed.

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

@tupacfan04

Copy link
Copy Markdown
Contributor

Closed as a duplicate of #1976, so this is only for whoever lands that one: the content checks out (tests/semantic/test_f64_mul_fma.py 4 passed / 11 subtests, regen_fixtures --check clean, test_shader_checks 75, the fixture translates with correct hand-derived words, and docs/design.md:390 matches the code), but the same code has two points to settle there.

  • tools/rdna2spirv.py:6279 always emits the GLSL.std.450 Fma, even under --fma khr, while the project's own emit_fma (:908) says GLSL Fma may round twice - and SPV_KHR_fma supports f64. An exact CPU interpreter and two GPU runs do not make "rounded once" a contract.
  • :6272 rejects any FP_ROUND write, including value 0 (nearest-even); only value 3 needs toward-zero. Over-conservative rather than wrong, but docs/design.md:390 phrases it as if every write needs toward-zero.

AI-assisted review, no game files, no GPU.

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