Repository navigation
fix(libc): compute exp2f with FreeBSD msun's algorithm, as titles' libc.prx does - #9844
Conversation
|
I compared the new function with the official FreeBSD 11.4 Two integration items remain before merge: this head is based on |
|
@MarcZX10 thanks. #9839, #9841 and this PR are all mine, so their order is settled here: any order works. Whichever merges first, I'll rebase the other two keeping all three changes, and rerun |
|
Thanks for clarifying the order among your three math PRs; no dependency entry is needed if any order works and you will preserve all changes. I still recommend updating this branch to current |
cef6c79 to
9f11a6c
Compare
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Thanks for the detailed final-head Windows run. I compared current upstream |
|
Rebased onto current |
9f11a6c to
45a5dde
Compare
|
Linux run (the description lists Linux as not tested). Docker on Windows: Ubuntu 26.04, GCC 15, glibc 2.43, WSL2 kernel 6.6, Release,
No findings. AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed exact head 45a5dde7df1031f0d7c563b6879b8cfd664b69fd. The port follows FreeBSD 11.4 msun's exp2f reduction, 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 upstream main; only the adjacent debt index changed.
I built the exact PR Math.cpp and GuestMath.cpp in the available older configured Release build and ran the isolated CheckExp2fConsoleBits; 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 Linux guest_math runs. Hosted policy and relinker/register-context/write-watch checks pass; product jobs are skipped.
…bc.prx does exp2f returned the host exp2, so its last bit and errno depended on the host: on Windows the bits differ from the libc.prx that titles ship on 213,306,266 of the 2^32 floats. That libc.prx is msun's s_exp2f.c, setting ERANGE only in its overflow and underflow branches. The port gives the same bits and errno as PPSA07923's, PPSA05916's and PPSA13934's copies for every argument. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45a5dde to
8b83c68
Compare
Additive conflicts with main's newer libc math changes: the debt list keeps both sides' entries (per entry), the GuestMath.cpp test functions and calls from both sides are kept, and Math.cpp keeps both sides' independent changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Linux run at this PR's exact head Arch Linux, kernel 7.2.9, Ryzen 9 7950X, g++ (GCC) 16.2.1 20260810, glibc 2.44, x86-64. Release,
This is the focused test only; no title, console or floating-point exception flags were checked. AI-assisted: yes (Claude Code). |
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,main6a6a35f.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 fix(libc): compute expf with FreeBSD msun's algorithm, as titles' libc.prx does #9839 and fix(libc): compute logf with FreeBSD msun's algorithm, as titles' libc.prx does #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 fix(libc): compute asinf with FreeBSD msun's algorithm, as titles' libc.prx does #9771, fix(libc): compute atanf with FreeBSD msun's algorithm, as titles' libc.prx does #9777 or fix(libc): compute atan2f with FreeBSD msun's algorithm, as titles' libc.prx does #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).