fix(libc): compute log10 with fdlibm's algorithm, as titles' libc.prx does #10247
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10247"
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-23T15:30:23Z.
What
log10returned the host'slog10, so its last bit and itserrnodepended on the host. On Windows (UCRT) it differs from thelibc.prxthat titles ship on 3,066,397 of 320 million random arguments. For example,log10(0x4003a67d5567227b)is0x3fd8fa5a3b281494in the bundledlibc.prxand0x3fd8fa5a3b281493here, andlog10(0x4047f462f020acde)is0x3ffae2ff9b87b792there and0x3ffae2ff9b87b793here.The titles' copy (NID
WuMbPBKN1TU) is not the FreeBSD 11.4e_log10.c, which works throughk_log1p. That version differs from the bundled library on about 1% of arguments. It is the older fdlibme_log10.cover itsk_log.h__kernel_log, the same lineage as theerffin #10226.log10now computes it:log;__kernel_logas a staticLog10Kernel;ivln10hi/ivln10loandlog10_2hi/log10_2lorecombination, withx - 1split at its low word.errno: the bundled library's handling differs fromlog's (#10245).log10setsEDOMfor every nonzero argument with the sign bit set: the negative numbers, negative subnormals,-infand negative NaNs. It leaveserrnoalone for ±0, where it returns-inf, and for positive NaN and+inf. This port does the same, and keeps the NaN payloads of fdlibm'sx + xand(x - x) / 0._Logwith a positive base callslog10, and its existing test still passes:log10(1000)is exactly 3 here too.Tested
Current Linux refresh:
19999e0615e1f97ce018d3cea034071743014e32on main6c52b649e7b1592f28db0cb8fe9ac604f0a242e7. Fresh isolated libc/math build passed;guest_mathandguest_dinkumware_internalseach passed three consecutive runs. Diff and conventions checks pass; math and test topic changes remain unchanged after rebase. Linux logs and rebase checks.The Windows module comparisons and negative control below are historical evidence from original head
a24a71c90f2add35da580c8bed491078c791a2d8; Windows was not rerun on the refreshed commit. The original report's console results mean the supplied titles' bundled libraries executed on the Windows host, not measurements on a physical console.Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,main4997726a5f.Comparison: a scratch loader runs the decrypted
libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. It compared theirlog10with this PR's code, checking result bits (NaN payloads included) anderrno, on two sets:errnoon all of them.errno. The bits differ on 229,944 random arguments, because that copy is an FMA-contracted build.guest_math: the newCheckLog10ConsoleBitshas 26 cases with the bundled library's results anderrno:|f| < 2^-20edge;DBL_MAX, ±inf, −1 and NaN payloads of both signs;guest_mathandguest_dinkumware_internalspass in three runs out of three on the exact head.Negative control: with
main'sMath.cppand these tests,guest_mathaborts in aRequire, whileguest_dinkumware_internalsstill passes.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.Overlap and order: Refreshed as one standalone log10 topic on main
6c52b649e7b1592f28db0cb8fe9ac604f0a242e7. The previous #10245 dependency described series order rather than a required implementation. Nearby math ports still share text/test/debt anchors. #10317 requires this PR's kernel and remains stacked on it.Not tested: macOS, a physical console, floating-point exception flags, and
log10l. Original module comparison and negative control were Windows-only; the new Linux build and regression checks are scoped separately above.Current Linux qualification (2026-10-28)
Rebased onto
main2227f1366188cda5699dd20e2e756a18006a5d4b. Linux CPU validation on 2026-10-28 at6bceecd018be481d9a2b66a36f1704472eeeca5f(Arch Linux 7.2.9, AMD Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON).libc,guest_math_testsandguest_math_exact_testsrebuilt from this exact source.guest_mathandguest_math_exacteach passed three consecutive runs (6/6, no skips); the same two suites each passed three runs on the pinned main (6/6). Conventions and whitespace checks pass.Exact source pins, preservation proofs, dependency checks, build logs and JUnit, SHA-256
1176269c9e6948b5252a5db9e660978d7f978fb2d9f4ed6c68bc050b10b5ae68. This is focused Linux CPU qualification; earlier Windows/title/reference measurements retain their original pins. No new title or performance result is claimed.Canonical declaration cleanup (2026-10-28)
At
2f72ecea0435, removed 93 duplicate local export declarations fromGuestMath.cpp; its includedApi.hppsupplies them. Production code and numeric test bodies are unchanged. Original fails the actual header audit; candidate passes. Per-branch affected-test syntax compilation and conventions/whitespace pass; full standalone-header compilation passed once for the byte-identical header tree shared by the four affected PRs. Source/proofs/logs, SHA25644f560018e4f6b52e8dda4158383f64fc3059fcdb6444840fe5c04fb2c884f11. No new numerical-runtime/platform claim; earlier runs retain original pins. Normal fast-forward only, no rebase. AI-assisted: Codex.Current qualification — 2026-10-30
Integrated current main
08a10d225306ad102b57408e2ef7566bcfb829b2into this existing topic at476bb9f96cb5f66b7bfba9de65143f5d2568d24c. Current-main functions, fixtures, unrelated debt rows and exact dependency gitlinks are preserved; original topic functions and authored commits are retained.Rebuilt actual Linux libc and focused test binaries.
guest_math,guest_math_exact,guest_dinkumware_internalseach passed three consecutive runs (9 runtime passes), pluspublic_headers; conventions and whitespace checks pass. Pinned main passed all seven selected runtime suites plus the header audit three times (24 runs). This is focused Linux CPU qualification; prior Windows/reference evidence retains its original pins. No new Windows, console, SDK-module, title, GPU or performance claim. AI-assisted: yes.Evidence: https://github.com/JJenkx/AnyPS5/releases/download/linux-validation-20261023/owned-math6-main08a10-linux-20261030.tar.gz (SHA-256 b984a6334dce65b5c9148e3791ba21605074a5e762ea0f07f96de2f38062ef6e).
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 harisibrar1 on 2026-10-24T12:47:38Z.
Review: APPROVED
Checked against main
39a36bbec8and fdlibm e_log10.c and k_log.h at freebsd-src 59bc2f0952:log10is still the host's (Math.cpp:1082), and_Log(DinkumwareInternals.cpp:87) is the only internal caller.log10_nid_postfixandLog10Kernelline by line with e_log10.c and__kernel_log. Everything matches: the subnormal scaling, the0x95f64normalisation, the(2+hx)shortcut andi|=jselect, and the hi/lo recombination order. After scaling a subnormal, the low word is correctly taken from the scaled value.CheckLog10ConsoleBits. All of them give the expected bits, including the subnormals, DBL_MAX and the six UCRT-differing arguments.CheckExpm1ConsoleBits), so they conflict textually and the second to land needs a trivial rebase.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.