[PR #1933] 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) #1939

Open
opened 2026-11-26 21:19:28 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1933
Author: @ShotTechOp
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/f64-literal-sources


📝 Commits (1)

  • b14335e rdna2spirv, shader_ir: route div/cmp f64 literals through f64_source_words (SHADER-F64-LITERAL-SOURCES)

📊 Changes

5 files changed (+335 additions, -65 deletions)

View changed files

📝 docs/design.md (+1 -1)
➕ tests/semantic/test_f64_literal_sources.py (+280 -0)
📝 tests/test_shader_ir_parse.py (+36 -0)
📝 tools/rdna2spirv.py (+5 -60)
📝 tools/shader_ir.py (+13 -4)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1933 **Author:** [@ShotTechOp](https://github.com/ShotTechOp) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/f64-literal-sources` --- ### 📝 Commits (1) - [`b14335e`](https://github.com/ubiquitarianism/leonida/commit/b14335e0bbc6577d24c4a0993484807e0845f93e) rdna2spirv, shader_ir: route div/cmp f64 literals through f64_source_words (SHADER-F64-LITERAL-SOURCES) ### 📊 Changes **5 files changed** (+335 additions, -65 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) ➕ `tests/semantic/test_f64_literal_sources.py` (+280 -0) 📝 `tests/test_shader_ir_parse.py` (+36 -0) 📝 `tools/rdna2spirv.py` (+5 -60) 📝 `tools/shader_ir.py` (+13 -4) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1939
No description provided.