fix(libc): round fmal correctly with FreeBSD msun s_fmal.c #18524
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18524"
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 AlfaRojo on 2026-11-11T20:06:26Z.
What
fmalcalled the hoststd::fma(long double)after its special cases. On Windows (WinLibs) that is not correctly rounded: against exact rational arithmetic it was wrong for about 29% of random operands and 11% of operands that cancel, and it returnedx * ywheneverzwas far below the product, which loses the sticky bit (a product that is an exact tie and a tiny negativezmust round down).It is now FreeBSD msun
s_fmal.cfrom release/11.4.0 (Dekker splitting, scaling, sticky-bit adjustment, directed rounding modes), incore/libs/prx/libc/src/MathExact.cpp. The special cases and their order are unchanged. The 11.4 source, still unfixed in FreeBSD main, calls the doubleldexpon its extended-subnormal path (line 119), which loses that result; the long double overload ofldexpis used there, the only divergence from the source. It is recorded indocs/dev/debt/libc.mdwith the 53-bit x87 precision caveat. The tie check inGuestMathExact.cpp(a tie product with a tiny negativez) previously expectedx * y, from4f608a8c49, whose message claims a bit-for-bit match with PPSA08427'slibc.prx. Unmodified msun built with host gcc returns the lower neighbour for these operands, as this port does, so the expected bits now follow msun; the claimedlibc.prxmatch is unverified here.Tested
Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release, based on
main65351c2931.guest_math_exact_testspasses 3/3 runs. New checks: Annex F specials (infinity times zero, infinity minus infinity, NaN propagation, signed zeros, overflow,LDBL_MAX * 1 + LDBL_MAX), 100+ cases whose expected bits were computed with Pythonfractionsexact arithmetic and agree with unmodified msun built with host gcc (nearest, down, up, toward zero; cancellation, near-tie,zfar above and far below, subnormal results with ties,x * yoverflowing while the result is finite) and the sign of an exact zero in each rounding mode. The host-differing example-0xd.80abeb4fa460f27p-6 * -0xe.21454d37039f87cp-14 + -0xb.ecaa4c8a13997a9p-16gives0x9.3815b7c884c1ee4p-80(host0x9.3815b7e884c1ee4p-80).MathExact.cppfrommainthe test aborts at the corrected tie check (GuestMathExact.cpp:139).s_fmal.c(host gcc), 16,000,000 calls over all four rounding modes (random, cancellation, z far above and far below the product, subnormal results, exact ties): the port equals msun with the long doubleldexpin every call; against the unmodified source it differs in 116,891 calls, all extended-subnormal results through the doubleldexp. The comparison found a far-apart toward-zero branch with an inverted sign test, fixed with a test for all four modes.libc.prxor a console.tools/check_test_registration.pyandtools/check_conventions.py --base upstream/mainpass.tools/pr_overlap.pyfound 116 open PRs sharing files, all throughdocs/dev/debt/libc.mdorGuestMathExact.cpp. It could not compare 44 of them because they conflict with the base. I grepped the diffs of the PRs it could not compare that touchMathExact.cppor the test (#10780_LExp, #15141, #15142, #15143) and the others: none mentionsfmalexcept #14212 (unrelated debt wording) and #18122, which only adds alibSceLibcInternalforward that callsfmal_nid_postfixand does not change it.gh pr list --search fmalshows no open PR.9b00be5c6e(merged with upstream/main):guest_math,guest_math_elementaryandguest_math_exact, all three test executables rebuilt, pass in 3/3 runs;check_conventions.py --base upstream/mainreports no errors.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T06:08:39Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
6f22dea341:tools/check_conventions.pypassed;git diff --checkclean.guest_math_exact_testsbuilt cleanly.guest_math_exact):core/libs/prx/libc/src/MathExact.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me