rdna2spirv: flush literal MAD denormals (SHADER-LITERAL-MAD-DENORM) #1287

Manually merged
github merged 1 commit from gh-pr/1287/head into gh-pr/1287/base 2026-11-26 09:46:05 +00:00
Owner

@⁠anonymechab-droid on GitHub · 2026-11-24 21:16 UTC · original
anonymechab-droid:fix/literal-mad-denorm → main · +119 −18 · 5 files · 1 commits · merged 2026-11-25 02:38 UTC

Claimed in the coordination issue as: SHADER-LITERAL-MAD-DENORM — #14

Depends on: none.

What and why

Literal MAD currently preserves f32 subnormals, unlike the existing v_mad_f32 lowering and Mesa ACO's documented always-flush rule for v_madak_f32 / v_madmk_f32. For example, the synthetic calculation 0x00000001 * 0x7e800000 + 0 returns 0x34000000 instead of zero.

Flush each operand, the separately rounded product and the final sum with the existing Gen.flush_f32 helper. Keep the literal operand order, separate rounding and destination masking. Add a hand-written fixture and 64 boundary/control combinations across both instructions and their _e32 spellings, plus NaN propagation checks. Update the contract row with the Mesa reference and the limits of the verification.

The existing negative controls now locate the multiply and add independently, preserving the intervening flush chain while still proving that operand swapping and accidental fusion change the result.

Tested

  • Before the fix, the new regression file reports 41 failures (40 boundary subcases plus the fixture); after the fix, all 3 tests pass.
  • python -m unittest discover -s tests/semantic -p test_valu_mad_lit.py: 15 tests passed, including the adapted negative controls.
  • python -I scripts/run_semantic_tests.py tests/semantic -j 12: 472 files, 6,180 tests, 0 files failed in 446 seconds, on the final commit fed33bea.
  • python -m compileall -q make_game.py tools tests: passed.
  • python -I tests/test_semantic_translator_use.py: 3 tests passed.
  • python -I tests/test_docs_links.py: 16 tests passed.
  • python -I tests/test_text_write_line_endings.py: 3 tests passed.
  • python -I make_game.py --help, git diff --check, and scripts/check_no_game_data.py on all five changed files: passed.

Host: Windows, Python 3.14.7. GPUs tested: n/a (CPU interpreter only). No game files were used. Game-corpus translation/validation counts and spirv-val results are not available in this environment; the denormal rule has not been measured on a GPU here.

Upstream GitHub Actions currently reports action_required with no jobs started for CI, No Game Data and Runtime; those remote workflows still need maintainer intervention.

AI-assisted: yes (OpenAI Codex).

Checklist

  • One topic, based on main at 6261ca91; no dependencies.
  • No game data, keys or decryption, including in the examples and fixtures.
  • Contract row updated with its source and CPU verification.
  • Final full translator suite passed.
**@⁠anonymechab-droid** on GitHub · 2026-11-24 21:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1287) `anonymechab-droid:fix/literal-mad-denorm` → `main` · +119 −18 · 5 files · 1 commits · merged 2026-11-25 02:38 UTC Claimed in the coordination issue as: SHADER-LITERAL-MAD-DENORM — https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 Depends on: none. ### What and why Literal MAD currently preserves f32 subnormals, unlike the existing `v_mad_f32` lowering and Mesa ACO's documented always-flush rule for `v_madak_f32` / `v_madmk_f32`. For example, the synthetic calculation `0x00000001 * 0x7e800000 + 0` returns `0x34000000` instead of zero. Flush each operand, the separately rounded product and the final sum with the existing `Gen.flush_f32` helper. Keep the literal operand order, separate rounding and destination masking. Add a hand-written fixture and 64 boundary/control combinations across both instructions and their `_e32` spellings, plus NaN propagation checks. Update the contract row with the Mesa reference and the limits of the verification. The existing negative controls now locate the multiply and add independently, preserving the intervening flush chain while still proving that operand swapping and accidental fusion change the result. ### Tested - Before the fix, the new regression file reports 41 failures (40 boundary subcases plus the fixture); after the fix, all 3 tests pass. - `python -m unittest discover -s tests/semantic -p test_valu_mad_lit.py`: 15 tests passed, including the adapted negative controls. - `python -I scripts/run_semantic_tests.py tests/semantic -j 12`: 472 files, 6,180 tests, 0 files failed in 446 seconds, on the final commit `fed33bea`. - `python -m compileall -q make_game.py tools tests`: passed. - `python -I tests/test_semantic_translator_use.py`: 3 tests passed. - `python -I tests/test_docs_links.py`: 16 tests passed. - `python -I tests/test_text_write_line_endings.py`: 3 tests passed. - `python -I make_game.py --help`, `git diff --check`, and `scripts/check_no_game_data.py` on all five changed files: passed. Host: Windows, Python 3.14.7. GPUs tested: n/a (CPU interpreter only). No game files were used. Game-corpus translation/validation counts and `spirv-val` results are not available in this environment; the denormal rule has not been measured on a GPU here. Upstream GitHub Actions currently reports `action_required` with no jobs started for CI, No Game Data and Runtime; those remote workflows still need maintainer intervention. AI-assisted: yes (OpenAI Codex). ### Checklist - [x] One topic, based on `main` at `6261ca91`; no dependencies. - [x] No game data, keys or decryption, including in the examples and fixtures. - [x] Contract row updated with its source and CPU verification. - [x] Final full translator suite passed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:46:04 +00:00
github manually merged commit fed33beaf5 into gh-pr/1287/base 2026-11-26 09:46:05 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 02:39 UTC · original

Merged. Thanks.

  • Claim: SHADER-LITERAL-MAD-DENORM, valid.
  • The rule: v_madak_f32 and v_madmk_f32 flush denormals the same way main's v_mad_f32 path already does; the contract row is updated and says the rule is confirmed on the CPU.
  • Tests: 40 subcases fail on main; all pass with the change.
  • On the user's own shader corpus (counts only): 4,077 shaders use these instructions; a slice of 120 still translates and validates in full, and 117 of the 120 modules change.
  • Checked again on main 82f033512 + fed33beaf: the semantic suite passes (486 files, 6,275 tests, 0 files failed); the 14 docs and writer tests pass; check_no_game_data.py is clean on the 5 changed files.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 02:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1287#issuecomment-7150999470) Merged. Thanks. - **Claim:** `SHADER-LITERAL-MAD-DENORM`, valid. - **The rule:** `v_madak_f32` and `v_madmk_f32` flush denormals the same way `main`'s `v_mad_f32` path already does; the contract row is updated and says the rule is confirmed on the CPU. - **Tests:** 40 subcases fail on `main`; all pass with the change. - **On the user's own shader corpus (counts only):** 4,077 shaders use these instructions; a slice of 120 still translates and validates in full, and 117 of the 120 modules change. - **Checked again on `main` `82f033512` + `fed33beaf`:** the semantic suite passes (486 files, 6,275 tests, 0 files failed); the 14 docs and writer tests pass; `check_no_game_data.py` is clean on the 5 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.