fix(libc): compute log2 with fdlibm's algorithm, as titles' libc.prx does #10317
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10317"
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-23T17:31:27Z.
What
log2returned the host'slog2, so its last bit depended on the host. For example,log2(0x3f3738a98e70dc5c)is0xc026ecdca3e646fcin the bundledlibc.prxand0xc026ecdca3e646fdon Windows (UCRT). On 20 million random arguments, UCRT'slog2differs from the titles' copy on 93,080.The titles' copy (NID
Y5DhuDKGlnQ) is not FreeBSD 11.4'se_log2.c, which differs from it on 35,914 of 4 million arguments. It is the older fdlibme_log2.cover the samek_log.hkernel that the bundled library'slog10uses (#10247).log2now computes it:log10;ivln2hi/ivln2lorecombination, withx - 1split at its low word, plusk.The kernel was
Log10Kernelin #10247. This PR renames itKernelLog, because both functions now call it.errno: it follows the same rule as the bundled library'slog10, measured separately here.EDOMis set for every nonzero argument with the sign bit set: the negative numbers, negative subnormals,-infand negative NaNs. ±0 return-infand leaveerrnoalone, and so do positive NaN and+inf._Logwith a negative base callslog2, and its existing test still passes:log2(8)is exactly 3.Tested
Current-main conflict refresh, 2026-10-27 UTC: exact head
4c2e6155280830aed0c66a43e2d097844a71c3f9on tested main74acfad65b3f0fd4eab653f3a3989d298fba1157. Resolved overlapping test/debt context while preserving this branch's authored production/test edits and main's nextafter environment implementation and coverage. Existing prerequisite commits remain in their original series order.Linux focused rebuild of
libcand selected test executables passesguest_math,guest_math_exact,guest_dinkumware_internals, andpublic_headers, each three times: 12 passes, zero skips. Conventions and whitespace checks pass. Final fetched maincb45ae2ddf6e113a4619e8fed91fe7b9333c5c0fmerges cleanly; its later change is an unrelated Windows crash-test pattern, and the executed qualification remains pinned to the stated base. No new Windows, console, GPU, title, full-suite or negative-control run is claimed. Earlier reference/Windows evidence keeps its original pins.Exact pins, branch patches, preservation proofs, build/test logs, JUnit and lease-push receipts for this refresh batch. SHA-256:
e33f98cc467f038af662cc5fa491c3acc1806bb47171cf77b748f0d4d052c1f2; downloaded copy verified.Historical Linux validation:
c44ba39a7bb5b6bf6900d876dd28a7fff6e49283is directly on current #102473b6fd8ded3acddf99c4c67cb9442db492555976c, without the former merge commit or a duplicated older parent. The public log2, log10 and shared KernelLog function bodies are byte-identical to the prior reviewed head. Main/parent expm1 fixtures and debt entries are retained alongside log2. Obsolete manual declarations remain removed in favor of the API headers.Fresh independent Linux x86-64 / GCC 16.2.1 / Release libc and math builds passed; guest_math and guest_dinkumware_internals each pass three runs. With only production Math.cpp reverted to the direct #10247 parent and the log2 fixture retained, guest_math aborts. Restoring the fix returns both groups to passing and reproduces the original libc library SHA-256
6e0f1db6f63a9e2d08751b2b8710dd661706aa19959031168462d2cfad72b42f. No named assertion is emitted by this Release negative control. Conventions and whitespace pass.Read-only merge-tree against fetched main
52a8bed576e5c54a7f443728cdf663a080f8f9edis clean; that merge tree was not rebuilt. Exact-head logs/JUnit/rebase proof and negative/restoration controls, SHA-256bf0ae4aba56f483f939667425b9346864970f969aaa2cd2cb64ee62d73310875. Windows remains user-paused and was not rerun on this head.Historical previous-head reports (not rerun on this head):
Independent Windows regression report on the refreshed head (ycbuzi): PR head
54751d9271607a752f481682cfafa6164c1fef21was cleanly integrated onto mainfa515def85as9b0ef6d130on Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 UCRT r7, Release withBUILD_TESTING=ON. The reporter builtlibc,guest_math_testsandguest_dinkumware_internals_testswithout reported errors or warnings; both focused groups passed twice usingctest --repeat until-fail:2. Their negative control replacedMath.cppwith main's version:guest_mathaborted while the Dinkumware group still passed. This is attributed independent integration/regression evidence; original-module matrices and titles were not rerun.The Windows module comparisons and negative control below are historical evidence from original head
0a2b4c0a7c6b77eb542d95f98902a33dd35dea42; 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, on #10247's head.Comparison: a scratch loader runs the decrypted
libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. It compared theirlog2with this PR's code, checking result bits (NaN payloads included) anderrno, on:Results:
errnoon all of them.errno. The bits differ on 727 random arguments, because that copy is an FMA-contracted build.guest_math: the newCheckLog2ConsoleBitshas 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 #10247's
Math.cppand these tests,guest_mathaborts in aRequire, whileguest_dinkumware_internalsstill passes.python tools/check_conventions.py --base#10247's head, andgit diff --check, pass.Order: Actual refreshed #10247 parent
476bb9f96cb5f66b7bfba9de65143f5d2568d24cis an ancestor. Current main is integrated with merge commits; original topic history and shared-kernel arithmetic are preserved.Not tested: macOS, a physical console, floating-point exception flags, and
log2l. 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 at2cf7d26d3c733921cd1757f607cc61a97769143c(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.Current qualification — 2026-10-30
Integrated current main
08a10d225306ad102b57408e2ef7566bcfb829b2into this existing topic atedceab45c77be9c8d66bef00a6ff15caa2844838. Includes actual refreshed #10247 parent476bb9f96cb5f66b7bfba9de65143f5d2568d24c. Current-main functions, fixtures, unrelated debt rows and exact dependency gitlinks are preserved; original topic functions and authored commits are retained. The original shared log kernel and both log10/log2 bodies are retained; the redundant byte-identical parent helper is removed.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 did476bb9f96cb5f66b7bfba9de65143f5d2568d24cis retained)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:08:49Z.
Review: APPROVED
Checked against main
99feaf0eb8and FreeBSD 59bc2f09lib/msun/src/e_log2.c/k_log.h:log2_nid_postfixandKernelLogmatch the cited fdlibm source line by line.two54,ivln2hi/ivln2loand Lg1–Lg7 are bit-identical to the hex values in the source comments.CheckLog2ConsoleBits. Five of the six "UCRT differs" inputs are not correctly rounded (for example0x3f3738a98e70dc5c→0xc026ecdca3e646fc, where correct rounding gives...46fd), so the test should also catch a revert on a correctly rounding host, not only on UCRT.GuestMath.cppanchors.log2.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T21:12:15Z.
Review: CHANGES_REQUESTED
The prior source comparison and the current reported Linux/Windows exact-head runs provide good coverage of the math path. The remaining blockers are integration/order:
1e20650, 6,822 commits behind currentmain. Please refresh #10247 and this dependent branch onto currentmain; then rerunguest_mathandguest_dinkumware_internalson the final head. Hosted product jobs are skipped for these paths.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T04:10:05Z.
Review: APPROVED
Re-checked — new head, looks good
The refreshed head includes its current #10247 prerequisite, resolves the declared #10274 ordering gap, and has focused exact-head Linux evidence; I found no remaining blocker.
What I ran
edceab45c77be9c8d66bef00a6ff15caa2844838; base: currentupstream/main5ecef095b61e7a406b279c97896f3a8a6fbd6353.3245a52c4637f7847dbd2530d1f7ba14b945347c.476bb9f96cb5f66b7bfba9de65143f5d2568d24is an ancestor of this PR head. The refreshed branch includes main08a10d225306ad102b57408e2ef7566bcfb829b2; I found no paths changed on current main since then that are also changed by this PR.Results
3245a52c4637f7847dbd2530d1f7ba14b945347c.All conventions checks passed.guest_math,guest_math_exact, andguest_dinkumware_internalspassed three runs each, pluspublic_headers; the pinned main passed its selected suites and header audit. Exact-head reportUnedited local command output
git merge-tree --write-tree upstream/main upstream/pr/10317git diff --check upstream/main...upstream/pr/10317exited 0 and produced no output.python3 tools/check_conventions.py --base upstream/main --head upstream/pr/10317git merge-base --is-ancestor 476bb9f96cb5f66b7bfba9de65143f5d2568d24 upstream/pr/10317exited 0.Not verified