fix(shader): flush v_mullit_f32 denormals in the float modes that flush them #2046
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2046"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_f32gave other bits than the hardware when a source was a denormal:main(NVIDIA, RADV)0,0x3f800000,0x000000010xff7fffff0x000000000xbfc00000,0x00000001,0x3f8000000x000000000x800000000x7f800000,0x00000001,0x3f8000000x000000000x7fffffff,0xffc00000TechnicalDebt said only the denormals-kept behaviour was modelled. On hardware
v_mullit_f32flushes likev_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_f32is now in the "inputs and result flushed" group off32DenormalFlushFor. It reads its sources throughflushF32Denormaland passes the product throughflushTinyProduct, 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 * 0x00800000gives0, not0x00800000) 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_f32in 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_flushgets two results on the test's 32 rows, captured on hardware with f32 denormals flushed:v_mullit_f32 v26, v4, v5, v6for the limit, andv_mullit_f32 v27, v4, v5, 1.0for 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. Onmainit 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.agc_driver_nan_quieting, which runsv_mullit_f32in 0xc0.main, none now, on NVIDIA and RADV. With denormals kept, 91 rows still differ, as onmain: both drivers flush f32 denormals by default, which TechnicalDebt already records.check_conventions.pyandgit diff --checkpass.Not tested: a title run; f32 denormal modes 1 and 2 now throw for
v_mullit_f32, like the rest of its group.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)v_div_fixup_f32flush PR (#2045) extends the same test kernel; whichever lands second needs a small rebase. #2020 changesflushTinyProductfor constant factors; this PR only calls it.🤖 Generated with Claude Code
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 ontomaind70b8998in one build with 38 other PRs that had no Windows run.mainwithout it.agc_driver_f32_denormal_flush. None of them reported skipping a case.No title was run.
🤖 Addressed by Claude Code
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_f32with a register and an inline1.0src2 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 ontomain;agc_driver_f32_denormal_flushfails 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)): hardware0x00800000, this PR0.v_mul_f32gives the same on hardware and the same0onmain, so it comes fromflushTinyProduct, 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 the0x3f7ffffe * 0x00800001case. FixingflushTinyProductitself is a separate change (it affectsv_mul_f32and the fma forms too).Rebased on
main; #2045 will need the small rebase you mentioned. Merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:59:19Z.
Rebased on
mainafter #2045 landed (both extendF32DenormalFlush.cppand the f32 denormals entry in TechnicalDebt):v_div_fixup_f32as result 17 and adds this PR's twov_mullit_f32results as 18 and 19; the kernel is re-assembled withllvm-mcand the result buffer grown accordingly.v_mullit_f32and 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_flushandagc_driver_nan_quietingalso pass on CI's lavapipe. Merging once CI is green.