rdna2spirv, shader_ir: route v_div_fixup_f64, v_div_fmas_f64, v_cmp(x)_*_f64, and v_cmp(x)_class_f64 through f64_source_words (SHADER-F64-LITERAL-SOURCES) #1933

Open
github-bot wants to merge 1 commit from github-bot/gh-1933 into main AGit
Owner

@⁠ShotTechOp on GitHub · 2026-11-25 16:10 UTC · original
ShotTechOp:fix/f64-literal-sources → main · +335 −65 · 5 files · 1 commits · open

Claimed as SHADER-F64-LITERAL-SOURCES in #1608.

What changed and why

Four binary64 instruction families in tools/rdna2spirv.py bypassed Gen.f64_source_words() and were omitted from tools/shader_ir.py's binary64 literal tagging (f64_literal / literal_hex_digits):

  1. v_div_fixup_f64 (tools/rdna2spirv.py) and v_div_fmas_f64 (tools/rdna2spirv.py):
    • Local helpers (d64_words / f64) placed 32-bit hex literals such as 0x3ff00000 (+1.0), 0x40000000 (+2.0), 0x7ff00000 (+inf), 0x7ff80000 (qNaN), 0x80000000 (-0.0), and 0x1 into the low dword (lo = v, hi = 0, turning them into tiny subnormals) instead of bits [63:32] (lo = 0, hi = v) per the RDNA2 ISA and docs/design.md ("f64 literal sources").
    • In v_div_fmas_f64 with VCC=1, a 32-bit literal 0x40000000 (2.0) in S2 also fell below the |S2| >= 2.0 threshold and scaled down by 2^-128 instead of up by 2^128.
  2. compare_f64_cond (v_cmp(x)_*_f64) and cmp_class_f64 (v_cmp(x)_class_f64) (plus the fallback f64 branch in cmp_class):
    • Checked a nonexistent sv.get("literal") key (never set by tools/shader_ir.py, which sets f64_literal and literal_hex_digits) and checked value bounds instead of printed hex width (f64_literal_one_dword).
    • Printed 1-dword hex literals in -16..64 (e.g. 0x1) were misread as inline integers ((1, 0) instead of (0, 1)), so v_cmp_gt_f64_e64 s4, 0x1, 1 returned 0 instead of 1.
    • Full-width (>8 hex digit) padded literals written by tools/f64_diff.py (e.g. 0x000000003ff00000, 0x0000000080000000, 0x000000007ff00000) were shifted into bits [63:32] instead of decoded as whole 64-bit subnormals, making v_cmp_class_f64 classify 0x000000003ff00000 as +normal instead of +denormal and v_cmp_eq_f64 report 0x000000003ff00000 == 1.0.

Fix:

  • tools/shader_ir.py: tag f64_literal and literal_hex_digits (case-insensitive 0x/0X) on v_div_fixup_f64, v_div_fmas_f64, v_cmp(x)_class_f64 (src0 only, leaving the trailing 10-bit integer class mask untagged), and v_cmp(x)_*_f64 (last two operands, covering both 2-operand and 3-operand forms).
  • tools/rdna2spirv.py: route compare_f64_cond, cmp_class (f64 branch), cmp_class_f64, v_div_fixup_f64, and v_div_fmas_f64 through self.f64_source_words(...), removing 60 lines of duplicated ad-hoc operand decoding.
  • docs/design.md: document these four op families in the existing f64 literal sources contract row.
  • tests/semantic/test_f64_literal_sources.py & tests/test_shader_ir_parse.py: add semantic execution, SPIR-V constant-pair, spirv_asm.assemble, f64_diff.ref_program cross-check, and parser tests.

Negative control (RED on origin/main b0f3d39 -> GREEN on this branch)

  • LEONIDA_TOOLS_DIR=<origin/main tools> python -I tests/semantic/test_f64_literal_sources.py: FAILED (11 failures across all 7 tests) — v_div_fixup_f64 and v_div_fmas_f64 built (0x40000000, 0) instead of (0, 0x40000000); v_cmp_*_f64 and v_cmp_class_f64 misdecoded 0x1 and 16-digit padded literals.
  • On this branch: 7/7 OK.

Tests run (Windows 11, Python 3.12.10, CPU / standard library only; no GPU or game files)

  • python -I tests/semantic/test_f64_literal_sources.py -v -> 7/7 OK (also python -m unittest discover -s tests/semantic -p test_f64_literal_sources.py -> OK)
  • python -I tests/test_shader_ir_parse.py -v -> 4/4 OK
  • python -I tests/semantic/test_f64_literal_whole.py -> 5/5 OK
  • python -I tests/semantic/test_alu_div_fixup.py -> 6/6 OK
  • python -I tests/semantic/test_alu_div_fmas.py -> 9/9 OK
  • python -I tests/semantic/test_cmp_f64.py -> 5/5 OK
  • python -I tests/semantic/test_cmp_class_f64.py -> 6/6 OK
  • python -I tests/semantic/test_alu_cmp_class_f16_f64.py -> 5/5 OK
  • python -m unittest discover -s tests/semantic -p test_f64_round.py -> OK
  • python -I tests/semantic/test_alu_frexp_f64.py -> 9/9 OK
  • python -I tests/semantic/test_alu_ldexp_f64.py -> OK
  • python -I tests/semantic/test_vop3_const_mods.py -> OK
  • python -I tests/test_f64_diff.py -> OK
  • python -I tests/test_text_write_line_endings.py -> OK
  • All 12 tests/test_docs_*.py suites -> 12/12 OK
  • python -m compileall -q tools/shader_ir.py tools/rdna2spirv.py tests/test_shader_ir_parse.py tests/semantic/test_f64_literal_sources.py -> OK
  • python -I scripts/check_no_game_data.py tools/shader_ir.py tools/rdna2spirv.py docs/design.md tests/test_shader_ir_parse.py tests/semantic/test_f64_literal_sources.py -> OK
  • git diff --check -> clean

AI-assisted: yes.

**@⁠ShotTechOp** on GitHub · 2026-11-25 16:10 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1933) `ShotTechOp:fix/f64-literal-sources` → `main` · +335 −65 · 5 files · 1 commits · open Claimed as `SHADER-F64-LITERAL-SOURCES` in #1608. ### What changed and why Four binary64 instruction families in `tools/rdna2spirv.py` bypassed `Gen.f64_source_words()` and were omitted from `tools/shader_ir.py`'s binary64 literal tagging (`f64_literal` / `literal_hex_digits`): 1. **`v_div_fixup_f64` (`tools/rdna2spirv.py`)** and **`v_div_fmas_f64` (`tools/rdna2spirv.py`)**: - Local helpers (`d64_words` / `f64`) placed 32-bit hex literals such as `0x3ff00000` (`+1.0`), `0x40000000` (`+2.0`), `0x7ff00000` (`+inf`), `0x7ff80000` (`qNaN`), `0x80000000` (`-0.0`), and `0x1` into the **low** dword (`lo = v, hi = 0`, turning them into tiny subnormals) instead of bits `[63:32]` (`lo = 0, hi = v`) per the RDNA2 ISA and `docs/design.md` ("f64 literal sources"). - In `v_div_fmas_f64` with `VCC=1`, a 32-bit literal `0x40000000` (`2.0`) in `S2` also fell below the `|S2| >= 2.0` threshold and scaled down by `2^-128` instead of up by `2^128`. 2. **`compare_f64_cond` (`v_cmp(x)_*_f64`)** and **`cmp_class_f64` (`v_cmp(x)_class_f64`)** (plus the fallback f64 branch in `cmp_class`): - Checked a nonexistent `sv.get("literal")` key (never set by `tools/shader_ir.py`, which sets `f64_literal` and `literal_hex_digits`) and checked value bounds instead of printed hex width (`f64_literal_one_dword`). - Printed 1-dword hex literals in `-16..64` (e.g. `0x1`) were misread as inline integers (`(1, 0)` instead of `(0, 1)`), so `v_cmp_gt_f64_e64 s4, 0x1, 1` returned `0` instead of `1`. - Full-width (>8 hex digit) padded literals written by `tools/f64_diff.py` (e.g. `0x000000003ff00000`, `0x0000000080000000`, `0x000000007ff00000`) were shifted into bits `[63:32]` instead of decoded as whole 64-bit subnormals, making `v_cmp_class_f64` classify `0x000000003ff00000` as `+normal` instead of `+denormal` and `v_cmp_eq_f64` report `0x000000003ff00000 == 1.0`. **Fix:** - `tools/shader_ir.py`: tag `f64_literal` and `literal_hex_digits` (case-insensitive `0x`/`0X`) on `v_div_fixup_f64`, `v_div_fmas_f64`, `v_cmp(x)_class_f64` (`src0` only, leaving the trailing 10-bit integer class mask untagged), and `v_cmp(x)_*_f64` (last two operands, covering both 2-operand and 3-operand forms). - `tools/rdna2spirv.py`: route `compare_f64_cond`, `cmp_class` (f64 branch), `cmp_class_f64`, `v_div_fixup_f64`, and `v_div_fmas_f64` through `self.f64_source_words(...)`, removing 60 lines of duplicated ad-hoc operand decoding. - `docs/design.md`: document these four op families in the existing `f64 literal sources` contract row. - `tests/semantic/test_f64_literal_sources.py` & `tests/test_shader_ir_parse.py`: add semantic execution, SPIR-V constant-pair, `spirv_asm.assemble`, `f64_diff.ref_program` cross-check, and parser tests. ### Negative control (RED on `origin/main` `b0f3d39` -> GREEN on this branch) - `LEONIDA_TOOLS_DIR=<origin/main tools> python -I tests/semantic/test_f64_literal_sources.py`: **FAILED (11 failures across all 7 tests)** — `v_div_fixup_f64` and `v_div_fmas_f64` built `(0x40000000, 0)` instead of `(0, 0x40000000)`; `v_cmp_*_f64` and `v_cmp_class_f64` misdecoded `0x1` and 16-digit padded literals. - On this branch: **7/7 OK**. ### Tests run (Windows 11, Python 3.12.10, CPU / standard library only; no GPU or game files) - `python -I tests/semantic/test_f64_literal_sources.py -v` -> 7/7 OK (also `python -m unittest discover -s tests/semantic -p test_f64_literal_sources.py` -> OK) - `python -I tests/test_shader_ir_parse.py -v` -> 4/4 OK - `python -I tests/semantic/test_f64_literal_whole.py` -> 5/5 OK - `python -I tests/semantic/test_alu_div_fixup.py` -> 6/6 OK - `python -I tests/semantic/test_alu_div_fmas.py` -> 9/9 OK - `python -I tests/semantic/test_cmp_f64.py` -> 5/5 OK - `python -I tests/semantic/test_cmp_class_f64.py` -> 6/6 OK - `python -I tests/semantic/test_alu_cmp_class_f16_f64.py` -> 5/5 OK - `python -m unittest discover -s tests/semantic -p test_f64_round.py` -> OK - `python -I tests/semantic/test_alu_frexp_f64.py` -> 9/9 OK - `python -I tests/semantic/test_alu_ldexp_f64.py` -> OK - `python -I tests/semantic/test_vop3_const_mods.py` -> OK - `python -I tests/test_f64_diff.py` -> OK - `python -I tests/test_text_write_line_endings.py` -> OK - All 12 `tests/test_docs_*.py` suites -> 12/12 OK - `python -m compileall -q tools/shader_ir.py tools/rdna2spirv.py tests/test_shader_ir_parse.py tests/semantic/test_f64_literal_sources.py` -> OK - `python -I scripts/check_no_game_data.py tools/shader_ir.py tools/rdna2spirv.py docs/design.md tests/test_shader_ir_parse.py tests/semantic/test_f64_literal_sources.py` -> OK - `git diff --check` -> clean AI-assisted: yes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:11:44 +00:00
Author
Owner

@⁠efeekrb on GitHub · 2026-11-25 17:45 UTC · original

Tested on an NVIDIA GeForce RTX 4060 Laptop GPU (NVIDIA 610.78), Windows 11 build 26300, with an Intel UHD iGPU also present (LEONIDA_VK_DEVICE=4060). This PR's diff applies cleanly to main at 24a29f8 (where the test programs were built) and to main at b9320a118 (git apply --check).

  • Unit tests with the PR applied: tests/semantic/test_f64_literal_sources.py ran 7 tests, OK, and the changed tests/test_shader_ir_parse.py ran 4 tests, OK.
  • run_gpu_tests.py, full suite, with the PR applied: 274/274 shaders translated and pass spirv-val. Native 209/264 passed, 54 skipped, 1 failed; LEONIDA_W64_EMULATE=1 243/264 passed, 20 skipped, 1 failed. The one failure is cs_imgatomic_ext (the one #1518 addresses), and the counts are identical to main at 24a29f8 without this PR.

So no change on this GPU in either mode. The suite shows no regression; it does not tell whether a fixture exercises the rule this PR changes. No game files; counts and pass/fail lines only. AI-assisted (Claude Code).

**@⁠efeekrb** on GitHub · 2026-11-25 17:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1933#issuecomment-7169954307) Tested on an NVIDIA GeForce RTX 4060 Laptop GPU (NVIDIA 610.78), Windows 11 build 26300, with an Intel UHD iGPU also present (`LEONIDA_VK_DEVICE=4060`). This PR's diff applies cleanly to `main` at `24a29f8` (where the test programs were built) and to `main` at `b9320a118` (`git apply --check`). - Unit tests with the PR applied: `tests/semantic/test_f64_literal_sources.py` ran 7 tests, OK, and the changed `tests/test_shader_ir_parse.py` ran 4 tests, OK. - `run_gpu_tests.py`, full suite, with the PR applied: 274/274 shaders translated and pass spirv-val. Native 209/264 passed, 54 skipped, 1 failed; `LEONIDA_W64_EMULATE=1` 243/264 passed, 20 skipped, 1 failed. The one failure is `cs_imgatomic_ext` (the one #1518 addresses), and the counts are identical to `main` at `24a29f8` without this PR. So no change on this GPU in either mode. The suite shows no regression; it does not tell whether a fixture exercises the rule this PR changes. No game files; counts and pass/fail lines only. AI-assisted (Claude Code).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1933/head:github-bot/gh-1933'
git switch 'github-bot/gh-1933'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1933'
git switch 'github-bot/gh-1933'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1933'
git switch 'github-bot/gh-1933'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1933'
git switch 'main'
git merge --squash 'github-bot/gh-1933'
git switch 'main'
git merge --ff-only 'github-bot/gh-1933'
git switch 'main'
git merge 'github-bot/gh-1933'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.