fix(libc): compute exp2f with FreeBSD msun's algorithm, as titles' libc.prx does #9844
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9844"
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 JJenkx on 2026-10-22T17:41:41Z.
What
exp2freturned the host'sexp2, so its last bit and itserrnodepended on the host. On Windows (UCRT) the bits differ from thelibc.prxthat titles ship on 213,306,266 of the 2^32 floats (5 %). Examples, console thenmain:0x3f000303→0x3fb5066d, and0xbf400909→0x3f183437.The titles'
exp2f(NIDwuAQt-j+p4o) is FreeBSD msun'ss_exp2f.c.exp2fnow computes it the same way:exp2ft;x + redux, rounded to float asSTRICT_ASSIGNdoes;2^kscale built from its high word;hugeandtwom100read at run time, as msun'svolatilereads do.errno: msun sets none, but the titles' copy setsERANGEin exactly msun's overflow branch (x >= 128) and its underflow branch (x <= -150). A subnormal result leaveserrnoalone, for exampleexp2f(-149)=0x00000001. So do NaN and the infinities. This port setsERANGEin those two branches only.exp2fis imported by all 22 titles whose relinker registries I audited, for example PPSA01528, PPSA02630 and PPSA09614. Unlikeexpf(#9839) andlogf(#9841), the FMA-contracted copy of PPSA13934 gives the same bits here, because the core is in double precision, so one port matches every copy checked.Tested
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,main6a6a35fdf5.libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. Theirexp2fand this build'sexp2f_nid_postfixgive the same bits and the sameerrnofor all 2^32 arguments, in all three copies.guest_math: the newCheckExp2fConsoleBitshas 24 cases with the console's results anderrno: values in each range where UCRT differs, ±0, the2^-25shortcut, 1, the edges below and at 128,FLT_MAX, the infinities, the smallest normal and subnormal results, -149 and its neighbour, -150 and below,-FLT_MAXand NaN payloads of both signs.guest_mathand the libc tests (8) pass in three runs out of three. Withmain'sMath.cppand this test,guest_mathaborts in aRequire.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.exp2f's one-line definition sits between theexpfandlogflines ofMath.cpp, so this conflicts textually with #9839 and #9841, which replace those neighbours. Keeping all three changes resolves it; the newexp2fbody lives afterlogbf. There are no other conflicts with comparable PRs, and none with #9771, #9777 or #9784.45a5dde7dmerged cleanly ontomainfcd455870: Ubuntu 26.04 in Docker on Windows, GCC 15, glibc 2.43, WSL2 kernel 6.6, Release,BUILD_TESTING=ON. The reviewer reports five passingguest_mathruns (--repeat until-fail:5). Keeping this PR's test while restoring main's changed production sources makes the test fail on Linux as well. This supplies a Linux regression comparison in addition to the Windows evidence above; it is reviewer-supplied evidence for those revisions, not a local rerun or a latest-main claim.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)sinhfentry didMath.cpp; this one rebases after it lands)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T03:51:20Z.
Review: APPROVED
Reviewed exact head
45a5dde7df1031f0d7c563b6879b8cfd664b69fd. The port follows FreeBSD 11.4 msun'sexp2freduction, table, polynomial and scaling; errno handling and the 24 boundary/special-value cases are explicit. The production and test files are unchanged between the branch base and current upstreammain; only the adjacent debt index changed.I built the exact PR
Math.cppandGuestMath.cppin the available older configured Release build and ran the isolatedCheckExp2fConsoleBits; all 24 cases passed on Linux. This is a focused check, not a fresh full-tree build. The author reports exhaustive all-float comparisons on three Windows title libraries and repeated Windows tests; independent reviewer evidence reports five passing Linuxguest_mathruns. Hosted policy and relinker/register-context/write-watch checks pass; product jobs are skipped.