fix(libc): compute log10f and log2f with FreeBSD msun 9.0's algorithms, as titles' libc.prx does #9873
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9873"
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-22T20:13:09Z.
What
log10fandlog2freturned the host'slog10andlog2, so their last bit and theirerrnodepended on the host. On Windows (UCRT), against thelibc.prxthat titles ship,log10fdiffers on 13,120,001 of the 2^32 floats andlog2fon 2,155,910,778 of them (50 %). Examples, console thenmain:log2f(0x40400990)→0x3fcae940, andlog10f(0x3f7f1a73)→0xbac7bc3b.The titles' versions are FreeBSD msun's
e_log10f.cande_log2f.cas of release/9.0.0, over that release's__kernel_logfink_logf.h. That kernel has a short path for|f| < 2^-9, and the final combination differs from 11.4's. I found it by disassembling thelog10fexport of PPSA07923's copy. 11.4's code, either its float or itsfloat_tpath, differs from the titles by 1 ulp on about 2.4M arguments.This PR adds:
Log9Kernel: that kernel;Log9Reduce: the shared subnormal scaling, special cases and normalisation;errno: as in the titles' copy, every argument with the sign bit set except -0 setsEDOM, negative NaNs and-infincluded. ±0 return-infwithouterrno, unlikelogf(#9841), which setsERANGEthere. Positive NaNs and+infleaveerrnoalone.log2fis imported by 21 andlog10fby 20 of the 22 titles whose relinker registries I audited, for example PPSA01528, PPSA04158 and PPSA09614.Tested
Main conflict refresh, 2026-10-27 10:18 UTC pass: exact head
fad8f0e3acd059f4a86db1d5010d18c84fd2b1c3on tested main3fea2a937ba9fbab2f06c51691fe0c5763659aa3. The topic implementations and fixtures are retained alongside current main's newer math functions and coverage.Linux Release focused rebuild:
guest_mathandguest_math_exacteach pass three repetitions: 6 passes, zero skips. Conventions, whitespace and merge checks pass. Every refreshed head's submodule pointers match the pinned main; the private dependency checkouts used for the gates are aligned. No new negative-control, Windows, console, title, GPU, full-suite or performance run is claimed. Earlier measurements below retain their original exact pins. Fulfilled merge-order dependencies have been cleared from the checklist; open prerequisites remain.Exact source/dependency pins, patch-preservation and gitlink proofs, builds, verbose tests, JUnit and lease-push receipts. SHA-256:
702c4110ee9dde421c2dd5e057ed53a2df05e0cf7b01f67e8fb9cb779e332f7c; downloaded copy verified.Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,mainf6075c2f4a.Exhaustive comparison: a scratch loader runs the decrypted
libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. It compared each copy'slog10fandlog2fwith this build's for all 2^32 arguments, bits anderrno.errnoeverywhere, for both.errnoeverywhere. Its FMA-contracted build differs by 1 ulp on 930,947 (log10f) and 61,530 (log2f) arguments.guest_math: the newCheckLog10fLog2fConsoleBitshas 21 inputs, each checked through both functions with the console's results anderrno: values where UCRT differs, exact powers (1, 2, 8, 100), the smallest subnormal and normal,FLT_MAX,+inf, ±0, a negative subnormal, -1,-inf, NaN payloads of both signs and the neighbours of 1.guest_math(including the existinglog10f(100) == 2check) and 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.Overlap: two of the conflicts are with my own PRs and come from neighbouring lines in
Math.cpp. Keeping both changes resolves each.log2fis defined on the line afterlogf, which #9841 replaces.log10fis the line aftertanf, which #9857 moves.tools/pr_overlap.pyalso finds onedocs/dev/debt/libc.mdadjacency with #8284. The branch merges cleanly with #9771, #9777, #9784, #9839, #9844, #9850, #9862 and #9867.Independent Linux review: Dom3005's report tested head
55659c815merged 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.Not tested: macOS, a console, the floating-point exception flags.
Refreshed focused validation (2026-10-23): head
7dc14749f4, rebased ontomaind271a49580. The only conflict was thedocs/dev/debt/libc.mdlist, and both entries are kept.guest_mathandguest_dinkumware_internalspass in three runs out of three on this exact head (Windows, GCC 15.2.0 UCRT r7, Release). Withmain'sMath.cppand these tests,guest_mathaborts. Conventions andgit diff --checkpass. This refresh does not repeat the exhaustive title-library comparisons above, which keep their original base. Earlier refresh:55659c815conmain7c900bbc21, 8/8 math/libc tests 3/3.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 did72641c92f6f8; #9857 merged ate9a551d6f40e; present in audited main3fea2a937ba)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T20:32:52Z.
Review: COMMENTED
I checked the implementation against the pinned FreeBSD 9.0.0
k_logf.h,e_log2f.c, ande_log10f.c: the polynomial constants, reduction/normalization, split high/low products, and final combinations match. The PR reports exhaustive bit/errno comparisons against three titlelibc.prxbuilds and 3/3 Windows focused runs. The current hosted run has conventions/eligibility/labels and several product-adjacent checks passing, with macOS registration/relinker and one write-watch job still pending; Linux/Windows product jobs are skipped. I did not run the math binaries locally. Current main is1da03c6f, while this head is based on3bbd2321(12 commits behind); please rebase and rerun the focused checks once the pending jobs finish. The reported 1-ulp difference for the FMA-contracted third title build remains documented.