Skip to content

tests: polish v_rcp_f64/v_rsq_f64/v_sqrt_f64 test coverage - #2244

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
JavierBlanco23:rdna2-f64-transcendentals
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
JavierBlanco23:rdna2-f64-transcendentals

Conversation

@JavierBlanco23

@JavierBlanco23 JavierBlanco23 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Test polish follow-up for v_rcp_f64, v_rsq_f64, and v_sqrt_f64 after the translator implementation landed in upstream/main as 0a20f3c2.

Changes

  • tests/test_f64_transcendentals.py: keep synthetic SPIR-V data-flow, modifier ordering, and spirv-val checks in sync with upstream/main.

Testing

  • python -B -I tests/test_f64_transcendentals.py -v: 2/2 tests OK (Windows 11, NVIDIA GeForce RTX 5080, driver 616.56).
  • GPU-verified with no regressions by reviewers on RTX 5090, RX 9070, and RX 9070 XT.

AI-assisted.

@x2Tweek

x2Tweek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Static review — PR #2244

Branch: rdna2spirv: implement v_rcp_f64, v_rsq_f64 and v_sqrt_f64 with VOP3 modifiers (head of PR #2244)
Commit: 0a20f3c
Author: JavierBlanco23
State: OPEN

What it does

Implements three double-precision RDNA2 VOP1/VOP3 transcendentals in tools/rdna2spirv.py:

  • v_rcp_f64: OpFDiv %double 1.0 x
  • v_rsq_f64: OpExtInst %double %glsl InverseSqrt x
  • v_sqrt_f64: OpExtInst %double %glsl Sqrt x

All three set uses_f64 = True (Float64 capability), reuse the existing f64() VGPR/SGPR pair handling, apply VOP3 input modifiers (abs/neg) via the shared path, and apply VOP3 output modifiers (mul:2, mul:4, div:2, then clamp to [0, 1]) via clamp_mods_f64(). Special-value edge cases follow the driver's SPIR-V rules, consistent with the f32 forms.

Also adds:

  • tests/test_f64_transcendentals.py — SPIR-V lowering + output modifier tests for all three ops, including spirv-as/spirv-val validation.
  • docs/design.md — contract row for the three ops.

Code review

The change restructures the existing elif op in ("v_add_f64", "v_cvt_f32_f64"): block (line 4506 of the current main) to add the three new ops:

  1. v_cvt_f32_f64 is handled first (double→float conversion, stored as single VGPR) — behavior unchanged.
  2. v_add_f64 keeps its existing FAdd + round_mode + clamp_mods_f64 + pair-store path — behavior unchanged.
  3. v_rcp_f64 / v_rsq_f64 / v_sqrt_f64 are added as new branches, each computing the appropriate SPIR-V instruction, then running through clamp_mods_f64() and storing as a VGPR pair via OpBitcast %v2uint_d + OpCompositeExtract.

The f64() helper already handles VGPR/SGPR pairs, immediates, abs/neg input modifiers. clamp_mods_f64() and dconst() already exist. All helpers are reused, no new infrastructure needed.

The restructuring is safe: v_cvt_f32_f64 stores via self.dst(a[0], ...) (single VGPR), while the other four ops store via the pair path — matching their semantic types (float vs double result).

Test results

  • tests/test_f64_transcendentals.py: 2 passed, 6 subtests (SPIR-V data flow + spirv-as + spirv-val --target-env vulkan1.2)
  • tests/test_f64_output_modifiers.py: 2 passed (no regression on v_add_f64 modifiers)
  • tests/test_f64_conversion.py: 2 passed (no regression on v_cvt_f32_f64 modifiers)
  • tests/semantic/ -k "f64 or alu": 869 passed, 18982 subtests (no regression)
  • python -m compileall: clean on all changed .py files

Reviewer recommendation

Approve (static review + CPU tests). All three ops lower correctly to SPIR-V, output modifiers apply via the existing clamp_mods_f64 path, Float64 capability is declared, and all f64/alu semantic tests pass with no regressions.

AI-assisted. Static review only.

@matheuskshn

Copy link
Copy Markdown
Contributor

Reviewed 0a20f3c2 on Windows 11, RTX 4070 Ti / 621.24. Both PR tests passed with SPIRV-Tools. I also assembled a hand-written gfx1013 compute shader, translated it, and ran it with the FP64 harness from #2395 and Vulkan validation: rcp(4) mul:2, rsq(4) clamp div:2, and sqrt(abs(-4)) clamp mul:4 returned exactly 0.5, 0.25, and 1.0. This checks those values after Vulkan lowering.

One test gap: the scale field is only used as a boolean to look for OpFMul. I changed mul:4 and div:2 to multiply by 2.0 in the local FP64 helper, and both PR tests still passed. Could the test resolve the multiply operand to its OpConstant %double and assert the expected value? Using LLVM’s printed order (clamp div:2 and clamp mul:4) for the fixtures would also match an assembled listing. Synthetic inputs only. AI-assisted.

@JavierBlanco23

Copy link
Copy Markdown
Contributor Author

Thanks @matheuskshn for the GPU verification and review! Updated tests/test_f64_transcendentals.py to resolve and assert the exact double constant operands (2.0, 0.5, 4.0, and 0.0/1.0 for FClamp) and use LLVM's printed modifier order (clamp div:2, clamp mul:4). Re-ran tests/test_f64_transcendentals.py -v (pass with spirv-val).

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested a601a894488d8e83c7d525dbc669c1ecf3c234f2 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

Independent synthetic Vulkan compute check of a601a894488d8e83c7d525dbc669c1ecf3c234f2 on Linux 7.0.0-43 (RTX 5090, NVIDIA 595.99.02, subgroup 32, LLVM 21.1.8, SPIRV-Tools 2026.1).

  • All eight binary64 results matched bit for bit. Plain reciprocal of 8, inverse square root of 16, and square root of 64 gave 0.125, 0.25, and 8. The modified forms gave 0.5 (reciprocal, mul:2), 0.25 (inverse square root, clamp div:2), 1 (square root of abs(-4), clamp mul:4), −0.125 (reciprocal with negated input), and +0 (clamped reciprocal of −8).
  • The compute shader passed Vulkan 1.2 SPIR-V validation and both checked-in lowering tests passed. Reversing only the translator diff made the lowering tests reject all three opcodes.
  • I enabled the advertised shaderFloat64 feature in the scratch compute harness. This run covers the listed exact cases on NVIDIA Vulkan.

AI-assisted verification.

@sperm

sperm commented Nov 22, 2026

Copy link
Copy Markdown

Tested a601a89 on AMD Radeon RX 9070 XT (RADV GFX1201) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

  • Full python -I scripts/run_gpu_tests.py (Linux build of this branch's runtime/, LEONIDA_VK_DEVICE per GPU): 167/180 passed, 13 skipped, 0 failed on both GPUs. Compared with the same suite at the merge base 4eb6155 on the same machine, every test has the same result.
  • python -m unittest discover -s tests/semantic: 1671 OK
  • tests/test_f64_transcendentals.py: 2 OK

No game files. AI-assisted.

@lunisahdidouch

Copy link
Copy Markdown

Tested a601a89 on an RX 9070 (RDNA4), AMD 26.11.1 (LLPC), Vulkan 1.4.359, Windows 11: pass

tests/test_f64_transcendentals.py passes (2 tests) and tests/semantic passes on the branch (1671 tests, OK). Full run_gpu_tests.py: 167/180 passed, 13 skipped, nothing failed. The branch is about 330 commits behind main, so a few newer GPU tests aren't in it, but everything that is there matches main 4947579, ps_f64_mods included.

AI-assisted

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested a601a89 merged onto main 4947579 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/test_f64_transcendentals.py: ran 2 tests in 0.245s; OK.

AI-assisted (Claude Code).

@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested db8e3140 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_f64_transcendentals.py 2 passed, 6 subtests passed in 0.37s

Against main this head now changes only tests/test_f64_transcendentals.py. The translator side (v_rcp_f64/v_rsq_f64/v_sqrt_f64) seems to be on main already, so the title and description describe more than the diff now does. The GPU rows show no regression; no suite shader runs these f64 ops.

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

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
@JavierBlanco23 JavierBlanco23 changed the title rdna2spirv: implement v_rcp_f64, v_rsq_f64 and v_sqrt_f64 with VOP3 modifiers tests: polish v_rcp_f64/v_rsq_f64/v_sqrt_f64 test coverage Nov 22, 2026
@ItsNotRexed
ItsNotRexed merged commit eb312f3 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.

9 participants