fix(shader): return +0 when v_div_fmas_f32 cancels with |src2| >= 2^64 #1963
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1963"
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 Deftera186 on 2026-10-09T03:04:20Z.
What
v_div_fmas_f32with VCC set and a src2 exponent field of 128 or more (|src2| >= 2, scale 2^64) recomputed a plain fma result with exponent field 0 asfma(smaller multiplicand * 2^64, other multiplicand, src2 * 2^64). For |src2| >= 2^64,src2 * 2^64rounds to infinity, so an fma that cancels exactly returned -inf or +inf. The hardware returns +0, for example(1.0, FLT_MAX, -FLT_MAX)gave0xff800000and(1.0, -2^100, 2^100)gave0x7f800000.Only exact cancellations reach that recomputation. With |src2| >= 2, a nonzero exact sum S below 2^-126 needs |src0 * src1| > 1; such a product is a multiple of 2^-47 (two 24-bit significands, exponents >= -149) and src2 is a multiple of 2^-22, so a nonzero S is at least 2^-47 and the fma result is normal. The result is therefore the plain fma times 2^64, which is +0 for a cancellation and the single rounding of 2^64 * S otherwise. The recomputation is now done only for the 2^-64 scale, when the plain fma overflows;
scaleLhsonly differed fromlhsLargerin the removed case and is replaced by it. VCC=0, the 2^-64 path,v_div_scale_f32andv_div_fixup_f32are unchanged, and so is the unmodelled f32 denormal flush of thev_div_fmas_f32result (TechnicalDebt "f32 denormals").Source: hardware measurement (below). The 2^64 / 2^-64 scaling rule is the one measured for
11bc2799; the ISA pseudocode does not match the hardware there.Tested
Gentoo Linux, AMD Radeon RX 7700 XT (gfx1101), RADV (Mesa 26.2.3).
agc_driver_divisionwith 7 rows added toHelperVectors. Before the fix:AGC graphics: division helpers: vector 256 (0x3f800000, 0x7f7fffff, 0xff7fffff) vcc 1: v_div_fmas_f32 is 0xff800000, expected 0x00000000. After: passed.100% tests passed, 0 tests failed out of 494.v_div_fmas_f32only when the device fuses fma, as the existing rows do.Hardware: gfx1101 through
tools/hw-oracle, with the instruction sequence ofHelperCode(v_div_scale_f32,v_cmp_ne_u32 vcc_lo, 0, v7,v_div_fmas_f32,v_div_fixup_f32), in all 16 combinations of IEEE 0/1, f32 denormals 0/3, f16/f64 denormals 0/3 and DX10_CLAMP 0/1 (round mode 0). Every value below is the same in all 16 modes. The 256 existingHelperVectorsrows (from11bc2799, measured on RDNA2 according to its message) match gfx1101 bit for bit in the test's mode. Not re-measured on RDNA2.0x3f800000, 0x7f7fffff, 0xff7fffff(1.0, FLT_MAX, -FLT_MAX)0x000000000xff8000000x000000000x3f800000, 0xf1800000, 0x71800000(1.0, -2^100, 2^100)0x000000000x7f8000000x000000000x7f7fffff, 0xbf800000, 0x7f7fffff(FLT_MAX, -1.0, FLT_MAX)0x000000000x7f8000000x000000000x3f800000, 0xdf800000, 0x5f800000(1.0, -2^64, 2^64)0x000000000x7f8000000x000000000x5f400000, 0xdf200000, 0x7ef00000(1.5 * 2^63, -1.25 * 2^63, 1.875 * 2^126)0x000000000x7f8000000x000000000xe40a117d, 0xbf800000, 0xe40a117d(existing row, VCC set)0x000000000xff8000000x000000000x3f800000, 0xdf7fffff, 0x5f7fffff(1.0, -(2^64 - 2^40), 2^64 - 2^40)0x000000000x000000000x00000000With VCC 0 every row gives
0x00000000on hardware, before and after.Sweep: 11502 operand triples, each with VCC 0 and 1 (23004 rows), on gfx1101 in all 16 modes and through the recompiler before and after: the 256 table rows with both VCC values, 8126 exact cancellations (8120 with 2 <= |src2| <= FLT_MAX; every sign combination), 5736 nonzero near-cancellations with |src2| >= 2, ±0 operands, overflowing products with |src2| < 2, and 8000 random normal rows.
0x7f800000(902) or0xff800000(918); hardware and the fix give0x00000000in all 16 modes. No other row changes.0x00000000on hardware in all 16 modes; the 28 rows giving0x80000000have a -0 product and src2 = -0 and match before and after.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T03:11:06Z.
The hardware measurements and local full-suite results are documented in detail, but this head currently has no upstream check runs (
gh pr checksreports none). CONTRIBUTING says a fork PR with anaction_requiredworkflow needs maintainer approval before CI has actually run. Could you check whether the Build/Conventions workflows are waiting for approval and request a rerun if so?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T03:14:26Z.
I checked the Actions API for this exact head: Build, Conventions and Progress report are marked
action_required, so upstream CI has not run. Per CONTRIBUTING, a maintainer needs to approve those workflow runs; please request that approval.Imported from boykopovar/AnyPS5. Originally posted by snoozedDev on 2026-10-09T03:51:10Z.
Re-measured on RDNA2: Ryzen 7 7700X iGPU (Raphael, gfx1036, not the PS5's gfx1013),
tools/hw-oracleon Linux (hsa-rocr 7.2.4, LLVM 22.1.8), headccef16b4.HelperCodewords 10-18 unchanged, oneHelperVectorsrow per lane, wave32, in the same 16 modes as above (IEEE 0/1 × f32 denormals 0/3 × f16/f64 denormals 0/3 × DX10_CLAMP 0/1, round modes 0, FP16_OVFL 0).0x7f800001vs0x7fc00001), as on gfx1101. The 7 new rows match in all 16 modes.v_div_fmas_f32is0x00000000in every row and mode.agc_driver_divisionpasses on an RTX 3090 (NVIDIA 610.57.04) and on the RADV iGPU (Mesa 26.2.2); withmain'sFloatInstructions.cppboth fail atvector 256 ... v_div_fmas_f32 is 0xff800000, expected 0x00000000.Bodies, rows and per-mode results: https://gist.github.com/snoozedDev/c81c82507b46f9de87c5ecbdff54cde6 (
pr1963-*). Generated with Claude Code (Claude Fable 5.1), driven and checked by me; the numbers are the hardware's output.Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-09T08:59:51Z.
NVIDIA and Intel results on Windows, to go with the RADV runs.
Windows 11, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, fullctestwithANYPS5_REQUIRE_VULKAN=1on both GPUs of one machine: RTX 4080 (driver 617.42) and Intel UHD Graphics 770 (Raptor Lake-S, driver 101.6129, Vulkan 1.3.295), selected withANYPS5_GPU. Base:main6cc0503dplus #2093, sincemainalone does not build its tests right now (spirv/unified1/spirv.hppnot found).agc_driver_divisionpasses on both GPUs. The five UHD 770 failures are the same tests with and without this PR (vop3_mad_i64, #1246, plus four filed as #2114), so nothing new fails.Since the new
v_div_fmas_f32rows are only checked whenHostFusesFmais true, I added a temporary print to confirm: it returns true on both the RTX 4080 and the UHD 770, so the new rows were checked on both.Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T09:26:08Z.
NVIDIA data point. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), GCC 15.2.0 (WinLibs r7), Release. Head
ccef16b4merged ontomaind9484c71, together with #1979 and #1966.agc_driver_divisionpasses. The device fuses fma (the test doesn't print its "splits fma" message), so the newv_div_fmas_f32rows are checked on NVIDIA too.🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:06:14Z.
Checked on the HW oracle (gfx1035, IEEE 0/1 × f32 denormals flush/keep, 15660 rows incl. 3000 exact cancellations with |src2| >= 2): every result this PR changes now matches hardware and nothing else moves; the |a*b| > 1 ⇒ multiple of 2^-47 argument holds.
agc_driver_divisionfails without the fix and passes with it on RADV and CI's lavapipe. Merging.