Recompiler: f32 product tininess is checked before rounding (RDNA2 checks after), and the check makes float-heavy shaders slow to compile #2682

Closed
opened 2026-10-10 10:51:11 +00:00 by AlxcBTW · 5 comments
AlxcBTW commented 2026-10-10 10:51:11 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-10T10:51:11Z.


With f32 denormals flushed, flushTinyProduct checks a product for tininess on its exact value, from the factor exponents and a UMulHi of the significands. RDNA2 checks after rounding to 24 bits with an unbounded exponent. The f32 denormals entry in TechnicalDebt records this as measured on gfx1036: 0x3f7ffffe * 0x00800001 gives 0x00800000 on the hardware and 0 here.

The check also costs about 20 IR instructions per product, and that makes float-heavy pixel shaders slow for drivers to compile. The ps5-opengl UI renderer's large pixel shader (VITA5 PPSA39410, Homebrew UI Lab PPSA99050) has 1,587 checked products. Creating its graphics pipeline takes 14.7 s on an RTX 5070 Laptop (616.92) with a cold driver cache. UI Lab waits at most 2 s for a submission to retire, so it stops at submission retirement failed on every cold start. I timed the module dumped from Pipeline.cpp in a standalone Vulkan program. With only the tiny-product select replaced by a pass-through (a timing experiment, not correct), NVIDIA's time dropped from about 15.5 s to 8.3 s.

Fix

AlxcBTW/AnyPS5#18 (bb822ef5, on main be403084). One factor is multiplied by 2^64, which is exact below 2^64, and the product with the other factor is rounded once to 24 bits in the normal range. One unsigned compare of its magnitude bits minus 1 against 0x207fffff then gives the tininess. That is 6 IR instructions instead of 20, and it gives the hardware's result for the row above. Full CI passed, merged onto main 507f49fb. I can't open it as a PR while intake is limited, so it's here if a collaborator wants to cherry-pick it.

before after
VITA5's pipeline in the title, NVIDIA, cold driver cache 14.7 s 11.4 s
the dumped module standalone, NVIDIA 14.9-16.4 s 10.0-11.5 s
the dumped module standalone, AMD Radeon 880M 49.9 s 22.4 s

That still exceeds UI Lab's 2 s wait. The NaN-result and denormal-flush selects are the other two large costs: replacing all three with pass-throughs brings the module to 1.4 s.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, NVIDIA RTX 5070 Laptop (616.92) and AMD Radeon 880M (AMDVLK 2.0.353).

  • agc_driver_f32_constant_factor_tininess pins the lane 0x3f7ffffe * 0x00800001. It fails without the change (is 0x00000000, expected ... 0x00800000) and passes with it.
  • The 48 agc_driver float tests pass on both GPUs, in a fresh build.
  • vector_constant_factor_tininess now counts the new compare: one per checked product, with no significand product.
  • The new rule agrees with rounding the exact product to 24 bits with an unbounded exponent on 297,572 random factor pairs near 2^-126. This is a host-side model, not a GPU run.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5790531159 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2682). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-10T10:51:11Z. --- With f32 denormals flushed, `flushTinyProduct` checks a product for tininess on its exact value, from the factor exponents and a `UMulHi` of the significands. RDNA2 checks after rounding to 24 bits with an unbounded exponent. The f32 denormals entry in TechnicalDebt records this as measured on gfx1036: `0x3f7ffffe * 0x00800001` gives `0x00800000` on the hardware and 0 here. The check also costs about 20 IR instructions per product, and that makes float-heavy pixel shaders slow for drivers to compile. The ps5-opengl UI renderer's large pixel shader (VITA5 PPSA39410, Homebrew UI Lab PPSA99050) has 1,587 checked products. Creating its graphics pipeline takes 14.7 s on an RTX 5070 Laptop (616.92) with a cold driver cache. UI Lab waits at most 2 s for a submission to retire, so it stops at `submission retirement failed` on every cold start. I timed the module dumped from `Pipeline.cpp` in a standalone Vulkan program. With only the tiny-product select replaced by a pass-through (a timing experiment, not correct), NVIDIA's time dropped from about 15.5 s to 8.3 s. ### Fix [AlxcBTW/AnyPS5#18](https://github.com/AlxcBTW/AnyPS5/pull/18) (`bb822ef5`, on `main` be403084). One factor is multiplied by 2^64, which is exact below 2^64, and the product with the other factor is rounded once to 24 bits in the normal range. One unsigned compare of its magnitude bits minus 1 against `0x207fffff` then gives the tininess. That is 6 IR instructions instead of 20, and it gives the hardware's result for the row above. [Full CI](https://github.com/AlxcBTW/AnyPS5/actions/runs/38045849134) passed, merged onto `main` 507f49fb. I can't open it as a PR while intake is limited, so it's here if a collaborator wants to cherry-pick it. | | before | after | |---|---|---| | VITA5's pipeline in the title, NVIDIA, cold driver cache | 14.7 s | 11.4 s | | the dumped module standalone, NVIDIA | 14.9-16.4 s | 10.0-11.5 s | | the dumped module standalone, AMD Radeon 880M | 49.9 s | 22.4 s | That still exceeds UI Lab's 2 s wait. The NaN-result and denormal-flush selects are the other two large costs: replacing all three with pass-throughs brings the module to 1.4 s. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, NVIDIA RTX 5070 Laptop (616.92) and AMD Radeon 880M (AMDVLK 2.0.353). - `agc_driver_f32_constant_factor_tininess` pins the lane `0x3f7ffffe * 0x00800001`. It fails without the change (`is 0x00000000, expected ... 0x00800000`) and passes with it. - The 48 `agc_driver` float tests pass on both GPUs, in a fresh build. - `vector_constant_factor_tininess` now counts the new compare: one per checked product, with no significand product. - The new rule agrees with rounding the exact product to 24 bits with an unbounded exponent on 297,572 random factor pairs near 2^-126. This is a host-side model, not a GPU run. AI-assisted: yes (Claude Code).
SleglJan commented 2026-10-10 12:35:43 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-10T12:35:43Z.


Measured on RDNA2 hardware (gfx1036, Ryzen 7950X3D iGPU, tools/hw-oracle) and compared with main 197ffac9 and with AlxcBTW/AnyPS5#18 (bb822ef5, cherry-picked onto it). Both ran through KernelReplay, on the same iGPU through RADV (Mesa 26.2.4) and on an RTX 3080 (NVIDIA 615.71.09). Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), Release with ANYPS5_ENABLE_SPIRV_TOOLS=ON.

The sweep has 3,214 rows of two factors:

  • 1,968 rows of 0x3f800000 - k times 0x00800000 + j (k 1 to 48, j 0 to 40).
  • 1,200 rows with part of the same significands (k 1 to 24, j 0 to 24) but factors just below 2^-61 and at or just above 2^-65, half of them with a negative factor. The products of both blocks lie around 2^-126.
  • 32 random pairs with exponents summing to −128 … −123.
  • 14 edge rows: this issue's row, 2^64 × 2^-126, the largest finite value × 2^-126, 2^-64 × 2^-64, products near 2^-127, 1 × 2^-126, zeros, infinity, NaN and denormal inputs.

Each row runs through six instructions: v_mul_f32 in both operand orders, v_fma_f32 with a 0 and with a varying addend, v_fmac_f32 with a 0 accumulator, and v_mul_legacy_f32. The mode is round to nearest even with f32 denormals flushed (FLOAT_MODE bits 5:4 = 0), at IEEE=0 and IEEE=1.

Rows that differ from the hardware (of 3,214) main with #18
v_mul_f32 (both orders), v_fma_f32 with 0, v_fmac_f32, v_mul_legacy_f32 49 each 0
v_fma_f32 with a varying addend 12 0

The counts are the same on both hosts and in both IEEE modes.

  • The 49 rows. On main they are the rows whose exact product is below 2^-126 in magnitude but rounds to 2^-126 (this issue's row appears twice); 12 of them are negative. The hardware gives ±0x00800000 on all of them, for each of the five instructions in the first row, and main gives ±0. So the zero-addend v_fma_f32 and v_fmac_f32 forms and v_mul_legacy_f32, which #18 lists as not measured, detect tininess after rounding like v_mul_f32. The 12 rows with a varying addend are the 12 of the 49 whose addend is ±0 or a denormal (all with positive products here); for the other 37 the addend is ±2^-126 or 1.0.
  • v_fma_legacy_f32 is left out. On RDNA2, VOP3 0x140 is the fused v_fma_legacy_f32, but the recompiler translates it as v_mad_legacy_f32, as measured on gfx1010 and as LLVM decodes it for the PS5's gfx1013 (TechnicalDebt). So a gfx1036 measurement is not evidence for it.
  • Directed rounding. In each of the three directed modes (toward +∞, −∞ and zero, IEEE=0), neither build rounds f32 results in the mode's direction: 1,038 to 1,167 rows per column differ on main and 1,050 to 1,152 with #18. With rounding toward −∞ or toward zero, this issue's row gives 0 on the hardware and on main, and 0x00800000 with #18.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6097552373 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2682#issuecomment-6097552373). Originally posted by [SleglJan](https://github.com/SleglJan) on 2026-10-10T12:35:43Z. --- Measured on RDNA2 hardware (gfx1036, Ryzen 7950X3D iGPU, `tools/hw-oracle`) and compared with `main` 197ffac9 and with AlxcBTW/AnyPS5#18 (bb822ef5, cherry-picked onto it). Both ran through [`KernelReplay`](https://github.com/SleglJan/AnyPS5/blob/audit/oracle-2026-10-08/oracle-audit/KernelReplay.cpp), on the same iGPU through RADV (Mesa 26.2.4) and on an RTX 3080 (NVIDIA 615.71.09). Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), Release with `ANYPS5_ENABLE_SPIRV_TOOLS=ON`. The sweep has 3,214 rows of two factors: - 1,968 rows of `0x3f800000 - k` times `0x00800000 + j` (k 1 to 48, j 0 to 40). - 1,200 rows with part of the same significands (k 1 to 24, j 0 to 24) but factors just below 2^-61 and at or just above 2^-65, half of them with a negative factor. The products of both blocks lie around 2^-126. - 32 random pairs with exponents summing to −128 … −123. - 14 edge rows: this issue's row, 2^64 × 2^-126, the largest finite value × 2^-126, 2^-64 × 2^-64, products near 2^-127, 1 × 2^-126, zeros, infinity, NaN and denormal inputs. Each row runs through six instructions: `v_mul_f32` in both operand orders, `v_fma_f32` with a 0 and with a varying addend, `v_fmac_f32` with a 0 accumulator, and `v_mul_legacy_f32`. The mode is round to nearest even with f32 denormals flushed (FLOAT_MODE bits 5:4 = 0), at IEEE=0 and IEEE=1. | Rows that differ from the hardware (of 3,214) | `main` | with #18 | |---|---|---| | `v_mul_f32` (both orders), `v_fma_f32` with 0, `v_fmac_f32`, `v_mul_legacy_f32` | 49 each | 0 | | `v_fma_f32` with a varying addend | 12 | 0 | The counts are the same on both hosts and in both IEEE modes. - **The 49 rows.** On `main` they are the rows whose exact product is below 2^-126 in magnitude but rounds to 2^-126 (this issue's row appears twice); 12 of them are negative. The hardware gives ±0x00800000 on all of them, for each of the five instructions in the first row, and `main` gives ±0. So the zero-addend `v_fma_f32` and `v_fmac_f32` forms and `v_mul_legacy_f32`, which #18 lists as not measured, detect tininess after rounding like `v_mul_f32`. The 12 rows with a varying addend are the 12 of the 49 whose addend is ±0 or a denormal (all with positive products here); for the other 37 the addend is ±2^-126 or 1.0. - **`v_fma_legacy_f32` is left out.** On RDNA2, VOP3 0x140 is the fused `v_fma_legacy_f32`, but the recompiler translates it as `v_mad_legacy_f32`, as measured on gfx1010 and as LLVM decodes it for the PS5's gfx1013 (TechnicalDebt). So a gfx1036 measurement is not evidence for it. - **Directed rounding.** In each of the three directed modes (toward +∞, −∞ and zero, IEEE=0), neither build rounds f32 results in the mode's direction: 1,038 to 1,167 rows per column differ on `main` and 1,050 to 1,152 with #18. With rounding toward −∞ or toward zero, this issue's row gives 0 on the hardware and on `main`, and 0x00800000 with #18. AI-assisted: yes (Claude Code)
AlxcBTW commented 2026-10-10 12:41:07 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-10T12:41:07Z.


@SleglJan thank you, that is exactly the measurement the PR was missing. I added it to the TechnicalDebt entry on AlxcBTW/AnyPS5#18 (336a8486, docs only). The zero-addend v_fma_f32, v_fmac_f32 and v_mul_legacy_f32 now count as measured instead of assumed.

On the directed modes, you're right that the rounding toward −∞ / toward zero row now gives 0x00800000 where the hardware gives 0. The check rounds the scaled product to nearest, like the rest of the f32 arithmetic, which doesn't round in those directions on any build. On main that row matched only because "tiny before rounding" happens to agree with rounding down there. The entry now says this. Directed f32 rounding as a whole would be its own change.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6097595394 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2682#issuecomment-6097595394). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-10T12:41:07Z. --- @SleglJan thank you, that is exactly the measurement the PR was missing. I added it to the TechnicalDebt entry on AlxcBTW/AnyPS5#18 (`336a8486`, docs only). The zero-addend `v_fma_f32`, `v_fmac_f32` and `v_mul_legacy_f32` now count as measured instead of assumed. On the directed modes, you're right that the rounding toward −∞ / toward zero row now gives `0x00800000` where the hardware gives 0. The check rounds the scaled product to nearest, like the rest of the f32 arithmetic, which doesn't round in those directions on any build. On `main` that row matched only because "tiny before rounding" happens to agree with rounding down there. The entry now says this. Directed f32 rounding as a whole would be its own change. AI-assisted: yes (Claude Code).
adriadam10 commented 2026-10-10 22:57:23 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:57:23Z.


Fixed in part by #2839: f32 product tininess is now detected after rounding in all four round modes, covered by agc_driver_f32_denormal_flush; the compile cost of the check is still open.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103081708 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2682#issuecomment-6103081708). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T22:57:23Z. --- Fixed in part by #2839: f32 product tininess is now detected after rounding in all four round modes, covered by `agc_driver_f32_denormal_flush`; the compile cost of the check is still open.
BharatYadav007 commented 2026-10-12 04:13:55 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by BharatYadav007 on 2026-10-12T04:13:55Z.


There is a further update beyond #2839: main at d146ec1b6 also contains commit 4e7511dc3 (perf(shader): check f32 product tininess in one multiply to nearest even). The nearest-even path in TranslationContext::flushTinyProduct now uses the scaled-product check and magnitude comparison against 0x207fffff, rather than the significand-product calculation. Directed rounding retains its separate handling.

The commit also adds the 0x3f7ffffe * 0x00800001 -> 0x00800000 regression to F32ConstantFactorTininess.cpp and updates the IR checks. The original correctness fix and the proposed cheaper nearest-even check are therefore both present in main. I have not rerun the title’s cold-pipeline benchmark, so this is a source-status update rather than a claim that its startup timeout is resolved.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117622713 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2682#issuecomment-6117622713). Originally posted by [BharatYadav007](https://github.com/BharatYadav007) on 2026-10-12T04:13:55Z. --- There is a further update beyond #2839: `main` at `d146ec1b6` also contains commit `4e7511dc3` (`perf(shader): check f32 product tininess in one multiply to nearest even`). The nearest-even path in `TranslationContext::flushTinyProduct` now uses the scaled-product check and magnitude comparison against `0x207fffff`, rather than the significand-product calculation. Directed rounding retains its separate handling. The commit also adds the `0x3f7ffffe * 0x00800001 -> 0x00800000` regression to `F32ConstantFactorTininess.cpp` and updates the IR checks. The original correctness fix and the proposed cheaper nearest-even check are therefore both present in main. I have not rerun the title’s cold-pipeline benchmark, so this is a source-status update rather than a claim that its startup timeout is resolved.
AlxcBTW commented 2026-10-12 04:14:55 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T04:14:55Z.


Thanks @BharatYadav007, confirmed: #2839 (tininess after rounding) and 4e7511dc3 (the one-multiply nearest-even check) are both on main, with the 0x3f7ffffe * 0x00800001 -> 0x00800000 regression in F32ConstantFactorTininess.cpp. Both halves of this issue are addressed, so I'm closing it. If the cold-pipeline startup timeout still shows up on that title, it deserves its own issue with fresh numbers.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117631713 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2682#issuecomment-6117631713). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-12T04:14:55Z. --- Thanks @BharatYadav007, confirmed: #2839 (tininess after rounding) and 4e7511dc3 (the one-multiply nearest-even check) are both on `main`, with the `0x3f7ffffe * 0x00800001 -> 0x00800000` regression in `F32ConstantFactorTininess.cpp`. Both halves of this issue are addressed, so I'm closing it. If the cold-pipeline startup timeout still shows up on that title, it deserves its own issue with fresh numbers. AI-assisted: yes (Claude Code)
Sign in to join this conversation.
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#2682
No description provided.