fix(libc): compute logf with FreeBSD msun's algorithm, as titles' libc.prx does #9841
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9841"
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:20:55Z.
What
logfreturned the host'slog, so its last bit and itserrnodepended on the host. On Windows (UCRT) the bits differ from thelibc.prxthat titles ship on 13,225,175 of the 2^32 floats, for example0x3f7f0a10→0xbb76666fand0x40400de0→0x3f8ca894.The titles'
logf(NIDRQXLbdT2lc4) is FreeBSD msun'se_logf.c.logfnow computes it the same way:2^25;[sqrt(2)/2, sqrt(2));|f| < 2^-9path;Lg1–Lg4polynomial with its two branches;vzeroread at run time, as msun'svolatileread does.errno: msun sets none, but the titles' copy setsERANGEfor ±0 (result-inf) andEDOMfor every argument with the sign bit set, negative NaNs and-infincluded. Positive NaNs and+infleaveerrnounchanged. These map onto msun's own branches, so the port setsERANGEin the zero branch andEDOMin theix < 0branch.logfis imported by 20 of the 22 titles whose relinker registries I audited, for example PPSA01528, PPSA02630 and PPSA04158. This is thelogfcounterpart of #9839 (expf).Tested
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,main11f976b27c.libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. It compared theirlogfwith this build'slogf_nid_postfixfor all 2^32 arguments, bits anderrno.errnoeverywhere.errnoeverywhere. The bits differ by 1 ulp on 961,881 arguments, because that copy is an FMA-contracted build, as withexpf(#9839) andasinf(#9771).guest_math: the newCheckLogfConsoleBitshas 21 cases with the console's results anderrno: values where UCRT differs (a subnormal, both sides of 1, and larger values), 1, 2, the smallest subnormal and normal,FLT_MAX,+inf, the neighbours of 1, a NaN payload, ±0, a negative subnormal, -1,-infand a negative NaN.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. The branch merges without conflicts with #8865, #9771, #9777, #9784 and #9839.a22e959cdmerged 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 didAI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T17:25:17Z.
Review: APPROVED
Reviewed the 56-line port against FreeBSD 11.4
e_logf.c, including subnormal scaling, normalization, polynomial branches, and special-value handling. I also compiled the exact PRMath.cppand ran a focused local harness covering all 21 added bit/errno cases; it passed. The PR reports exhaustive 2^32-input comparisons against three bundled title libraries, with the documented 1-ulp FMA variant. The hosted Linux/Windows product jobs are skipped by policy, and the Windows relinker and macOS x86-64 relinker checks are still pending at review time.