Skip to content

test(semantic): add translator tests for v_mul_f64 - #5433

Open
slopgobblercobbler wants to merge 2 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-mul-f64
Open

slopgobblercobbler wants to merge 2 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-mul-f64

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

What

Adds translator-backed regression tests and translator support for v_mul_f64 in tests/semantic/test_valu_mul_f64_hw.py.

Covers:

  • Hand-written RDNA2 shader assembly translation through tools/rdna2spirv.py to SPIR-V OpFMul %double
  • Execution of translated SPIR-V via spirv_interp
  • Reference mathematical verification across standard and edge-case inputs
  • IEEE-754 binary64 signed zeros, infinities, and NaN generation/propagation
  • VOP3 source modifiers (neg, abs, neg-abs)
  • VOP3 output modifiers (clamp, mul:2, mul:4, div:2)
  • Scalar SGPR pair operands, inline float constants, and in-place squaring/aliasing
  • Boundary overflow and underflow behavior

Tested

  • Tested with Python 3.9+ (python -I)
  • python -m compileall -q tests (Clean, 0 errors)
  • python -I tests/test_semantic_translator_use.py (Passes translator reachability check)
  • python -I tests/semantic/test_valu_mul_f64_hw.py (All 13 tests passed, OK)
  • Standard library Python only (unittest, struct, math)
  • Clean merge against upstream/main
  • Strictly zero game data, binaries, or proprietary keys

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Head: 58d13c1ec685949ad73a241b6167fe95f866b1af

Windows 11, Python 3.13.7:

  • python tests/semantic/test_valu_mul_f64_hw.py -> 13 tests, OK (0.71 s)
  • Negative control: same file with LEONIDA_TOOLS_DIR pointed at main 3faac557 -> 52 errors, rdna2spirv.Unsupported: v_mul_f64 (expected).
  • python -I tests/test_semantic_translator_use.py -> OK
  • git diff --check main...HEAD -> clean

Overlap: #5435 edits the same f64 op tuple and emission block in tools/rdna2spirv.py. git merge-tree --write-tree pr/5433 pr/5435 exits 1 with a content conflict in that file; one of the two needs a rebase.

Verdict: LGTM after the #5435 conflict is resolved.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

PR 5433 (v_mul_f64 translator + tests), GPU check

Verdict: pass. No defect found.

Head tested: 58d13c1 (2 commits on top of origin/main 3faac55, so it merges cleanly, fast-forward; the merged tree is the PR head).
Pod: NVIDIA GeForce RTX 5080, driver 580.65.06, Linux.

Comment (not posted)

Tested 58d13c1 on NVIDIA GeForce RTX 5080 (driver 580.65.06), Linux, translator and GPU suite: pass

  • Merged cleanly on top of main 3faac55 (PR is a fast-forward of main).
  • python -I tests/semantic/test_valu_mul_f64_hw.py: 13 tests OK. python -I tests/test_semantic_translator_use.py: 3 tests OK. All 16 tests/semantic/test_valu_f64.py files pass.
  • scripts/run_gpu_tests.py, native: main 170/217 passed, 47 skipped, 0 failed; PR 170/217 passed, 47 skipped, 0 failed. Same pass/skip list, no new failure.
  • Same with LEONIDA_W64_EMULATE=1: main 201/217 passed, 16 skipped, 0 failed; PR 201/217 passed, 16 skipped, 0 failed.
  • The suite has no v_mul_f64 shader, so I also ran a temporary compute shader through the PR translator and vk_compute_test on the GPU (not part of the PR): 1.52.5 = 0x400e0000_00000000, -1.52.5 (neg) = 0xc00e0000_00000000, |-1.5|2.5 mul:2 = 0x401e0000_00000000, 0-1 = 0x8000000000000000 (-0). All four match, and the module passes spirv-val.
  • Built vk_compute_test, vk_store_test, vk_harness, vk_texture_test, vk_sampler_test, vk_bindless_test, vk_pipeline_check from main (the PR does not touch C++).
  • No game files.
  • AI-assisted (Claude Code).

Notes for main (not for the comment)

  • First suite run had 26 spurious failures on both main and PR because vk_texture_test, vk_sampler_test and vk_bindless_test were not built yet. I built them and reran everything; the numbers above are from the rerun.
  • tests/semantic/test_valu_mul_f64.py already exists on main (51 tests); the PR adds a second file test_valu_mul_f64_hw.py that goes through the translator. Not a duplicate of the translator path as far as I saw.
  • Logs: /tmp/claude-0/leonida-gpu/pr5433-logs/gpu-{main,pr5433}-{native,w64}.log (the paths inside differ only in the work dir name).
  • Ad hoc GPU shader: /tmp/claude-0/leonida-gpu/cs_f64_mul.asm

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested 58d13c1e (it already contains main 3faac557) on an Apple M4 (arm64, macOS). Everything here ran on the CPU. The M4's Vulkan driver, MoltenVK 1.4.2, reports shaderFloat64 = false, so f64 modules cannot run on this GPU. The tests pass, but the new rule has two gaps that the tests don't reach.

What passes

  • test_valu_mul_f64_hw.py passes on Python 3.12.16, 3.14.10 and 3.15.2.
  • Negative control: with main's tools/rdna2spirv.py in place, the file fails with 52 errors, all Unsupported: v_mul_f64.
  • Whole semantic suite: 6,258 tests (6,245 on main). There are 32 failures and 2 errors, the same 34 test IDs that fail on main on this machine: the vop3 test_rows and the divergent-loop/ballot cases on arm64. Nothing new fails.
  • Corpus: none of the 25,734 listings in my work folder uses v_mul_f64; 5 use v_add_f64. I translated a 205-listing slice: those 5 plus 200 spread across the corpus. The output is byte-identical to main, and 205/205 translate and pass validation on both.

Gap 1: a literal source goes into the low word

  • Reproduce with the PR's own translate_lines and spirv_interp: v[0:1] = 3.0, then v_mul_f64 v[4:5], v[0:1], 0x40000000.
  • Expected 6.0. Got 0x00000000c0000000 (about 1.59e-314): the literal was used as bits 31:0 instead of bits 63:32.
  • The cause: shader_ir.parse_line sets f64_literal only for v_add_f64, v_cvt_f32_f64 and the four rounding ops.
  • The "f64 literal sources" row in docs/design.md says a literal dword supplies bits 63:32.
  • Adding "v_mul_f64" to the prefix tuple at tools/shader_ir.py:195 fixes it. I tried it: the probe gives 6.0 and the PR's test file still passes. That is the same list rdna2spirv: a literal dword is bits 63:32 for rcp/rsq/sqrt/frexp f64 too (SHADER-865) #5534 extends for SHADER-865.
  • Control: v_add_f64 with the same literal gives the expected 5.0.

Gap 2: MODE round toward zero is ignored

  • Set the mode with s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), 3.
  • v_add_f64 then rounds toward zero, through f64_add_mode.
  • v_mul_f64 does not. (1 + 2^-27) × (1 − 2^-27) = 1 − 2^-54 should give 0x3fefffffffffffff, and the PR gives the nearest-even 0x3ff0000000000000.
  • The s_round_mode row says the translator accepts toward-zero FP16/64 rounding. So the honest fix is a directed-rounding path, or Unsupported while self.round_mode is set. As it stands, the result is silently wrong.

Neither gap affects today's corpus, because no listing uses the op.

Smaller points

The probe scripts are standard library only and I can paste them here. No game data: counts only. AI-assisted.

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

#5433 (head 58d13c1, open)

Tested 58d13c1 on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass

  • python -I -m unittest discover -s tests/semantic -p test_valu_mul_f64_hw.py: 13 tests OK. python -I tests/test_semantic_translator_use.py: 3 tests OK.
  • GPU check outside the PR: a hand-written compute program with four v_mul_f64 per run, translated with this head and run through vk_compute_test. Results as hex: (1+2^-27)(1-2^-27) = 3ff0000000000000 (tie to 1.0); -01 = 8000000000000000; 1e30810 = 7ff0000000000000; inf0 = 7ff8000000000000; 32^-10740.5 = 2 (denormal kept, tie to even); 2^-10740.5 = 0; -3inf = fff0000000000000; 1.5*-2 = c008000000000000. All match IEEE binary64.
  • That program is not in the PR and not committed.
  • Not done: other v_mul_f64 operand forms (abs, neg, omod).

AI-assisted (Claude Code).

@caltr98

caltr98 commented Nov 23, 2026

Copy link
Copy Markdown

Tested 58d13c1 (CPU, Windows 11, Python 3.11): pass. python -I tests/semantic/test_valu_mul_f64_hw.py runs 13 tests, OK, and tests/test_semantic_translator_use.py passes. The new v_mul_f64 branch matches the existing v_add_f64 one (OpFMul on the register-pair doubles, same neg/abs/clamp path). Note: #5490 by the same author adds the same file and the same v_mul_f64 rule and conflicts with main. One of the two should probably be closed. AI-assisted.

@caltr98

caltr98 commented Nov 23, 2026

Copy link
Copy Markdown

Follow-up: on the PR head 58d13c1 the full python -m unittest discover -s tests/semantic fails (3 failures and 3 errors in test_loop_ballot_barrier and test_vcmp16_opsel), while main passes. That comes from the branch's old base, not from this change: with the PR diff applied to current main, test_loop_ballot_barrier, test_vcmp16_opsel and test_valu_mul_f64_hw all pass. A rebase should clear it. AI-assisted.

@caltr98

caltr98 commented Nov 23, 2026

Copy link
Copy Markdown

Tested 58d13c1 on Windows 11, Python 3.11 (CPU only): pass. python -I tests/semantic/test_valu_mul_f64_hw.py: 13 tests OK. python -m unittest discover -s tests/semantic shows the same 6 failures/errors as main at 3faac55 (test_loop_ballot_barrier x5, test_vcmp16_opsel spirv_val) and no new ones. Note: #5490 (same author) adds a second v_mul_f64 rule to the same branch of tools/rdna2spirv.py, with the same test file name; only one of them should land. AI-assisted.

@vibryxcx

Copy link
Copy Markdown

Tested 58d13c1 on AMD Radeon RX 6800 (RDNA2, discrete, gfx1030), AMD 26.8.1 (Windows 32.0.21045.5002), Windows 11 Pro 25H2 (build 26200), MSVC 14.44, RelWithDebInfo: pass.

  • tests/semantic/test_valu_mul_f64_hw.py: OK; full ctest and run_gpu_tests.py (201/217, 16 skipped) identical to main here, so nothing else in the translator moved.
  • Context: these tests run the translated SPIR-V on the CPU interpreter, so the GPU doesn't enter into them; this is a Windows/RDNA2 build confirmation next to the RX 9070 XT and the other runs above. I didn't run an f64 GPU dispatch for v_mul_f64.

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.

7 participants