fix(libc): compute cbrt with FreeBSD msun's algorithm, as titles' libc.prx does #10283
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10283"
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-23T16:32:00Z.
What
cbrtreturned the host'scbrt, so its last bit depended on the host. On Windows (UCRT) it differs from thelibc.prxthat titles ship on 99,933,841 of 320 million random arguments, about 31%. For example,cbrt(0x3ffa0ccfe147c94d)(about 1.628) is0x3ff2d29f09b6d6a3on the console and0x3ff2d29f09b6d6a4here.The titles' copy (NID
5ZkEP3Rq7As) is FreeBSD msun'ss_cbrt.c.cbrtnow computes it:B1/B2exponent estimate, with the 2^54 scaling for subnormals;P0–P4polynomial step;tto 23 bits;It sets no
errno, as the titles' copy does not.Tested
Refreshed onto main
5a2744c55efcedf4c5f1b190af46fccbe5df1310as26e8bc5f43e7fa8b4082ff1c06f771c53c34c3e7, one topic commit with no merge commits. The only conflict was an additive libc debt append: all current-main entries and this PR's distinct cbrt entry are preserved. The implementation andCheckCbrtConsoleBitsbodies are byte-identical to previous public head7e0150e9b0911d5af3dbb2ae859ae8bc5104e93c.Fresh Linux
libc,guest_math_testsandguest_math_exact_testsbuilds pass. Both focused CTest groups pass three times (6 passes); conventions, whitespace and merge-tree checks pass. This is rebase qualification. The original large Windows and bundled-SDK comparisons were not rerun and retain their prior head attribution, including the recorded FMA variant and exception-flag limitations.Refresh patch, preservation hashes and build/test logs — SHA256
c2816446e25860f967e9f77a750958911893cbd89189fb54c014e250e0999e56; uploaded archive downloaded and hash-verified.Independent Windows regression report on previous public head (ycbuzi): PR head
09bd784583aca366f165ef3b91245d121fcf3405was cleanly integrated onto mainfa515def85as91ba4d5371on 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.Current Linux refresh: head
7e0150e9b0911d5af3dbb2ae859ae8bc5104e93c, one topic commit directly on mainda6c581a02dbd3983ccc70fff92169acce802f77, without merge commits. Bothcbrt_nid_postfixandCheckCbrtConsoleBitsare unchanged from previous public head09bd784583aca366f165ef3b91245d121fcf3405. Newer main math implementations, regression calls, canonical public declarations and debt entries are retained. No pending math port is required: Depends on remains none.Fresh Linux x86-64 Release validation:
guest_math,guest_math_exact,guest_dinkumware_internalsandpublic_headerseach pass three consecutive runs, then all four pass three more after negative-control restoration. With only productionMath.cppreplaced by main,guest_mathaborts as expected while exact-math and Dinkumware controls pass. Restoring the candidate produces a byte-identicallibc.prx. Conventions and whitespace checks pass. The independent Windows report above and original-module comparisons below remain pinned to their measured heads; no new Windows, title, console, exception-flag or performance claim.Exact-head Linux build/tests, negative control and preservation proof (SHA-256
2f58ea7138bff280a0c9f58642a45b20b056dbd82d785d6dabcdc2145b21ddfc).Historical Windows/module measurements (previous head): the following results are retained from the original submission; “console” below refers to the bundled SDK modules executed on Windows, not a physical console measurement.
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,main15e71dbe11.Comparison: a scratch loader runs the decrypted
libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. It compared theircbrtwith this PR's code, checking result bits (NaN payloads included) anderrno, on:Results:
errnois never set.errno. The bits differ on 32 random arguments, because that copy is an FMA-contracted build.guest_math: the newCheckCbrtConsoleBitshas 25 cases with the console's results:±DBL_MAX, the infinities and NaN payloads of both signs;Each case checks that
errnostays unchanged.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: other math ports can share source, test and debt insertion anchors. This cbrt implementation does not call any pending math port; textual overlap does not require the previous series order.
Not tested: macOS, a physical console, floating-point exception flags, and
cbrtl. Windows/module sampling above remains historical; current Linux validation is listed first.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; Codex for the Linux rebase and validation).
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T05:36:47Z.
Review: COMMENTED
Checked against main
7c2400d29band FreeBSD msuns_cbrt.cat release/9.0.0, 10.0.0, 11.4.0 and 12.0.0:s_cbrt.cis the same code in all four releases (only a comment typo fix in between), and the port matches it exactly: B1/B2, the 2^54 subnormal path, the polynomial grouping, the 23-bit rounding and the Newton step. All five P constants round to the hex values in msun's comments.CheckCbrtConsoleBitsvectors through a Python emulation of the same operations in plain IEEE double, and every one matches.0xc050f6b81592ae3fis a nice case: msun gives...43fawhere the correctly rounded result is...43f9, so the test really pins msun.15e71dbe11and no longer merges into main: docs/dev/debt/libc.md conflicts because main'scoshfentry sits where thecbrtentry goes, and keeping both lines resolves it. Math.cpp and the tests merge cleanly. Could you rebase and update the "Based on current main" and "Depends on: #10274" lines? The branch doesn't seem to need #10274, which is still open.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:28:20Z.
Review: APPROVED
Reviewed the current head 09bd784583aca366f165ef3b91245d121fcf3405. The cbrt translation follows the cited FreeBSD msun operation order, including subnormal scaling, bit-based seed, polynomial grouping, 23-bit truncation and Newton correction. The added 25 bit-pattern vectors cover signed zero, subnormals, normal boundaries, finite extremes, infinities and NaN payloads, and explicitly assert that errno is unchanged. I verified the current diff against upstream/main, a clean merge-tree result, and passing convention/diff checks. The exact head also has reported focused Linux and Windows runs (guest_math; Windows additionally guest_dinkumware_internals) with a negative control showing guest_math fails when the implementation is replaced by main host cbrt. Hosted product jobs remain skipped, as documented. I found no outstanding blocking issue.