fix(shader): flush v_mullit_f32 denormals in the float modes that flush them #2046

Merged
CouchRiv merged 2 commits from upstream-pr/2046 into main 2026-10-10 07:13:08 +00:00
CouchRiv commented 2026-10-09 05:45:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-09T05:45:50Z.


fix(shader): flush v_mullit_f32 denormals in the float modes that flush them

What

Part of #981 (FLOAT_MODE family), a follow-up to #1850. With f32 denormals flushed, v_mullit_f32 gave other bits than the hardware when a source was a denormal:

src0, src1, src2 hardware main (NVIDIA, RADV)
0, 0x3f800000, 0x00000001 0xff7fffff 0x00000000
0xbfc00000, 0x00000001, 0x3f800000 0x00000000 0x80000000
0x7f800000, 0x00000001, 0x3f800000 0x00000000 0x7fffffff, 0xffc00000

TechnicalDebt said only the denormals-kept behaviour was modelled. On hardware v_mullit_f32 flushes like v_mul_f32: all three sources and the product are flushed, so a positive denormal limit (src2) counts as zero and selects -FLT_MAX, and tininess is detected before rounding.

v_mullit_f32 is now in the "inputs and result flushed" group of f32DenormalFlushFor. It reads its sources through flushF32Denormal and passes the product through flushTinyProduct, both from #1850. The existing NaN, zero and limit rules are unchanged, so a flushed source now takes the zero-operand path and gives +0. The product flush and tininess (0x3f7fffff * 0x00800000 gives 0, not 0x00800000) already match NVIDIA's and RADV's default behaviour, but not a driver that keeps denormals, such as lavapipe. With f32 denormals kept nothing changes.

Measured on RDNA2 (gfx1036, the same family as the gfx1035 used for #1850) with the HW oracle, all float controls set: 6907 rows (19 values per operand, 5 of them denormals, plus 48 products near 2^-126) with f32 denormals flushed and kept, at IEEE=0 and IEEE=1. This rule matches every row. Flushing only src2 misses 723 rows per flushing mode, and flushing the inputs but not the product misses 69.

Which title needs it

Titles run their shaders with f32 denormals flushed: TechnicalDebt's float mode entry records it for Astro's Playroom's 0xc0, and a shader without a known float mode is translated the same way. This changes the result of v_mullit_f32 in that mode. No specific title run was done: we have no title copy to run.

Tested

CachyOS Linux, GCC 16.2, RTX 4070 Ti (NVIDIA 615.71.09) and Radeon 610M (RADV, Mesa 26.2.4).

  • agc_driver_f32_denormal_flush gets two results on the test's 32 rows, captured on hardware with f32 denormals flushed: v_mullit_f32 v26, v4, v5, v6 for the limit, and v_mullit_f32 v27, v4, v5, 1.0 for the product, since the rows with a tiny product all have a zero src2. 31 of the 64 new cells differ from the hardware's result with denormals kept. On main it fails on both drivers (lane 1 no float mode v_mullit_f32 v26, v4, v5, v6 is 0x80000000, expected 0x00000000); with the change it passes, in under a second.
  • Without the tininess check the test still passes on NVIDIA and RADV, which already flush a tiny product before rounding; as in #1850, only lavapipe tells them apart. Not run on lavapipe locally.
  • Full Release ctest: 498/498 on NVIDIA and on RADV, including agc_driver_nan_quieting, which runs v_mullit_f32 in 0xc0.
  • A local differential run of 2744 rows against the hardware: 208 rows differed in each flushing mode on main, none now, on NVIDIA and RADV. With denormals kept, 91 rows still differ, as on main: both drivers flush f32 denormals by default, which TechnicalDebt already records.
  • check_conventions.py and git diff --check pass.

Not tested: a title run; f32 denormal modes 1 and 2 now throw for v_mullit_f32, like the rest of its group.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none. The v_div_fixup_f32 flush PR (#2045) extends the same test kernel; whichever lands second needs a small rebase. #2020 changes flushTinyProduct for constant factors; this PR only calls it.
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4796522012 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2046). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-09T05:45:50Z. --- fix(shader): flush v_mullit_f32 denormals in the float modes that flush them ### What Part of #981 (FLOAT_MODE family), a follow-up to #1850. With f32 denormals flushed, `v_mullit_f32` gave other bits than the hardware when a source was a denormal: | src0, src1, src2 | hardware | `main` (NVIDIA, RADV) | |---|---|---| | `0`, `0x3f800000`, `0x00000001` | `0xff7fffff` | `0x00000000` | | `0xbfc00000`, `0x00000001`, `0x3f800000` | `0x00000000` | `0x80000000` | | `0x7f800000`, `0x00000001`, `0x3f800000` | `0x00000000` | `0x7fffffff`, `0xffc00000` | TechnicalDebt said only the denormals-kept behaviour was modelled. On hardware `v_mullit_f32` flushes like `v_mul_f32`: all three sources and the product are flushed, so a positive denormal limit (src2) counts as zero and selects -FLT_MAX, and tininess is detected before rounding. `v_mullit_f32` is now in the "inputs and result flushed" group of `f32DenormalFlushFor`. It reads its sources through `flushF32Denormal` and passes the product through `flushTinyProduct`, both from #1850. The existing NaN, zero and limit rules are unchanged, so a flushed source now takes the zero-operand path and gives `+0`. The product flush and tininess (`0x3f7fffff * 0x00800000` gives `0`, not `0x00800000`) already match NVIDIA's and RADV's default behaviour, but not a driver that keeps denormals, such as lavapipe. With f32 denormals kept nothing changes. Measured on RDNA2 (gfx1036, the same family as the gfx1035 used for #1850) with the HW oracle, all float controls set: 6907 rows (19 values per operand, 5 of them denormals, plus 48 products near 2^-126) with f32 denormals flushed and kept, at IEEE=0 and IEEE=1. This rule matches every row. Flushing only src2 misses 723 rows per flushing mode, and flushing the inputs but not the product misses 69. ### Which title needs it Titles run their shaders with f32 denormals flushed: TechnicalDebt's float mode entry records it for Astro's Playroom's 0xc0, and a shader without a known float mode is translated the same way. This changes the result of `v_mullit_f32` in that mode. No specific title run was done: we have no title copy to run. ### Tested CachyOS Linux, GCC 16.2, RTX 4070 Ti (NVIDIA 615.71.09) and Radeon 610M (RADV, Mesa 26.2.4). - `agc_driver_f32_denormal_flush` gets two results on the test's 32 rows, captured on hardware with f32 denormals flushed: `v_mullit_f32 v26, v4, v5, v6` for the limit, and `v_mullit_f32 v27, v4, v5, 1.0` for the product, since the rows with a tiny product all have a zero src2. 31 of the 64 new cells differ from the hardware's result with denormals kept. On `main` it fails on both drivers (`lane 1 no float mode v_mullit_f32 v26, v4, v5, v6 is 0x80000000, expected 0x00000000`); with the change it passes, in under a second. - Without the tininess check the test still passes on NVIDIA and RADV, which already flush a tiny product before rounding; as in #1850, only lavapipe tells them apart. Not run on lavapipe locally. - Full Release ctest: 498/498 on NVIDIA and on RADV, including `agc_driver_nan_quieting`, which runs `v_mullit_f32` in 0xc0. - A local differential run of 2744 rows against the hardware: 208 rows differed in each flushing mode on `main`, none now, on NVIDIA and RADV. With denormals kept, 91 rows still differ, as on `main`: both drivers flush f32 denormals by default, which TechnicalDebt already records. - `check_conventions.py` and `git diff --check` pass. Not tested: a title run; f32 denormal modes 1 and 2 now throw for `v_mullit_f32`, like the rest of its group. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none. The `v_div_fixup_f32` flush PR (#2045) extends the same test kernel; whichever lands second needs a small rebase. #2020 changes `flushTinyProduct` for constant factors; this PR only calls it. - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
popcoder565 commented 2026-10-09 15:46:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:46:39Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 0e421967, merged onto main d70b8998 in one build with 38 other PRs that had no Windows run.

  • It conflicts with #2045, so it was tested on main without it.
  • This PR's tests pass: agc_driver_f32_denormal_flush. None of them reported skipping a case.
  • Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there).

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6084275160 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2046#issuecomment-6084275160). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:46:39Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `0e421967`, merged onto `main` d70b8998 in one build with 38 other PRs that had no Windows run. - It conflicts with #2045, so it was tested on `main` without it. - This PR's tests pass: `agc_driver_f32_denormal_flush`. None of them reported skipping a case. - Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there). No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
adriadam10 commented 2026-10-10 06:12:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:12:46Z.


Checked on RDNA2 (gfx1035) with tools/hw-oracle, f32 denormals flushed, IEEE=0 and IEEE=1: v_mullit_f32 with a register and an inline 1.0 src2 over 13992 operand triples (24 values per operand incl. denormals, ±FLT_MAX, NaNs, plus products near 2^-126). Built and ran ctest on the PR merged onto main; agc_driver_f32_denormal_flush fails without the change and passes with it, also on CI's lavapipe.

The new flush matches the hardware except for 9 rows per mode, all products just below 2^-126 that round up to it, e.g. 0x3f7ffffe * 0x00800001 (2^-126 * (1 - 2^-46)): hardware 0x00800000, this PR 0. v_mul_f32 gives the same on hardware and the same 0 on main, so it comes from flushTinyProduct, which checks the exact product: the hardware detects tininess after rounding to 24 bits with an unbounded exponent (that rule matched every row, in both modes). So "this rule matches every row" in the description doesn't hold for those rows; as you found on #2020.

Added as our own commit:

  • docs/dev/TechnicalDebt.md: the f32 denormals entry no longer says tininess is detected before rounding; it records the measured hardware rule and the 0x3f7ffffe * 0x00800001 case. Fixing flushTinyProduct itself is a separate change (it affects v_mul_f32 and the fma forms too).

Rebased on main; #2045 will need the small rebase you mentioned. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094537847 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2046#issuecomment-6094537847). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:12:46Z. --- Checked on RDNA2 (gfx1035) with `tools/hw-oracle`, f32 denormals flushed, IEEE=0 and IEEE=1: `v_mullit_f32` with a register and an inline `1.0` src2 over 13992 operand triples (24 values per operand incl. denormals, ±FLT_MAX, NaNs, plus products near 2^-126). Built and ran ctest on the PR merged onto `main`; `agc_driver_f32_denormal_flush` fails without the change and passes with it, also on CI's lavapipe. The new flush matches the hardware except for 9 rows per mode, all products just below 2^-126 that round up to it, e.g. `0x3f7ffffe * 0x00800001` (2^-126 * (1 - 2^-46)): hardware `0x00800000`, this PR `0`. `v_mul_f32` gives the same on hardware and the same `0` on `main`, so it comes from `flushTinyProduct`, which checks the exact product: the hardware detects tininess after rounding to 24 bits with an unbounded exponent (that rule matched every row, in both modes). So "this rule matches every row" in the description doesn't hold for those rows; as you found on #2020. Added as our own commit: - `docs/dev/TechnicalDebt.md`: the f32 denormals entry no longer says tininess is detected before rounding; it records the measured hardware rule and the `0x3f7ffffe * 0x00800001` case. Fixing `flushTinyProduct` itself is a separate change (it affects `v_mul_f32` and the fma forms too). Rebased on `main`; #2045 will need the small rebase you mentioned. Merging once CI is green.
adriadam10 commented 2026-10-10 06:59:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:59:19Z.


Rebased on main after #2045 landed (both extend F32DenormalFlush.cpp and the f32 denormals entry in TechnicalDebt):

  • The test keeps v_div_fixup_f32 as result 17 and adds this PR's two v_mullit_f32 results as 18 and 19; the kernel is re-assembled with llvm-mc and the result buffer grown accordingly.
  • TechnicalDebt: the v_mullit_f32 and f32 denormals entries combine #2045's text with this PR's and the measured tininess note added earlier.

Scoped build and ctest 323/323 on the rebased head; agc_driver_f32_denormal_flush and agc_driver_nan_quieting also pass on CI's lavapipe. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094894919 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2046#issuecomment-6094894919). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:59:19Z. --- Rebased on `main` after #2045 landed (both extend `F32DenormalFlush.cpp` and the f32 denormals entry in TechnicalDebt): - The test keeps `v_div_fixup_f32` as result 17 and adds this PR's two `v_mullit_f32` results as 18 and 19; the kernel is re-assembled with `llvm-mc` and the result buffer grown accordingly. - TechnicalDebt: the `v_mullit_f32` and f32 denormals entries combine #2045's text with this PR's and the measured tininess note added earlier. Scoped build and ctest 323/323 on the rebased head; `agc_driver_f32_denormal_flush` and `agc_driver_nan_quieting` also pass on CI's lavapipe. Merging once CI is green.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
boykopovar/AnyPS5!2046
No description provided.