fix(libc): compute exp2 with FreeBSD msun's algorithm, as titles' libc.prx does #10274
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10274"
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:15:29Z.
What
exp2returned the host'sexp2, so its last bit depended on the host. On Windows (UCRT) it differs from thelibc.prxthat titles ship on 57,412,184 of 320 million random arguments, about 18%. For example,exp2(0x401c2caf278dc3f3)is0x40607dc899331269on the console and0x40607dc899331268here, andexp2(0x404ac26689a8dc7a)is0x4346ec6938394318there and0x4346ec6938394317here.The titles' copy (NID
dnaeGXbjP6E) is FreeBSD msun'ss_exp2.c.exp2now computes it:x + reduxreduction into a 1/256 step and its table index;tblofexp2(z + eps)andeps, taken verbatim from the source;P1–P5polynomial;2^kscaling with thek == 1024and subnormal paths;hugeandtwom1000read at run time.errno: msun sets none. The titles' copy setsERANGEin exactly msun's overflow (x >= 1024) and underflow (x <= -1075) branches. All three titles do so forexp2(1024),exp2(1100),exp2(-1075)andexp2(-1100), withFE_OVERFLOWorFE_UNDERFLOWraised.exp2(1023)andexp2(-1074)leaveerrnoalone, and so do NaN and the infinities. This port sets it there.Change to an existing check: #3599 made
exp2keeperrnounchanged, following FreeBSD's source, and addedCheckExp2Errno, which expectsexp2(1024)to leaveerrnoat 0. This PR changes only that expectation, toERANGE, because the titles' copies set it. The same check'sFE_OVERFLOW | FE_INEXACTtest is unchanged and still passes. cc @CouchRiv, the same point as theasinchange in #10253.Tested
Current-main integration — 2026-11-09 UTC. Head
d1b49ecc308cbd4e954c04e9eb40eeaec8b706bbpreserves public head624d14c732bf72e25a44d2c9d1706471c8d4e56fand integrates pinned main7259cce11195f360698772da8c0b3af756bf7c8f. Conflict resolution retains both the topic and main's newer source/test/debt changes; maintainer commits and attribution remain intact.Linux x86-64, GCC 16.2.1, Ninja Release: actual libc/libkernel and focused fixture owners rebuilt. 12/12 CPU executions pass, zero skips (4 groups × three repetitions):
guest_math,guest_math_elementary,guest_math_exact,guest_dinkumware_internals.public_headers, conventions and whitespace checks pass. The matching plain-main control passed 102 selected CPU executions and its header audit. CPU fixtures execute unpatched production libraries; this is not a full SDK or patched-title runtime qualification.No new Windows/macOS, console, GPU, title or performance result is claimed. Source checks preserve the existing production topic; historical reports below retain their original pins.
Build/test logs, exact heads, source/ancestry checks and provider pins, SHA-256
52727be6594b9c15bf9a5535fef374b985e9526aabe5f3ef5cf5857dfeeb1a0d. The public archive and all 178 manifest files were download/hash verified.Current-main integration — 2026-11-03. Head
aa78a9ecd819e714b60604b4929c5c8818a1163dincludes main4f41f4c375f5abb487dbd184fbc150f31994d762and retains the prior public history and attribution/licence notices. Main’s newer math implementations and fixtures remain alongside this topic. Actual open prerequisite #10265 head3bf30fd4920e751df3825b9abb75f7a0832ecf37is an ancestor.Linux x86-64 Release, GCC 16.2.1, Ninja, BUILD_TESTING=ON: rebuilt actual libc and math executables.
guest_math,guest_math_exact, andguest_dinkumware_internalseach pass 3/3 (9 passes, zero skips);public_headersand conventions pass. The same three groups pass 3/3 plus headers on pinned main. All 34 recursive dependency trees and 31,551 tracked blobs verify with zero errors; the update=none QuickJS test262 corpus is excluded from these library inputs. Whitespace check passes.Source/parent/gitlink proofs, exact library/test hashes, raw logs/JUnit, and head-leased push receipts: qualification archive, SHA-256
e6a50522bc28e30871fdc2c12a88d2537515914239e8166f6237f48895126a06(download verified). Older platform/reference reports retain their original pins; no new Windows/macOS, SDK-module, console, title/GPU or performance claim. AI-assisted: yes (Codex).Earlier dated qualifications below retain their recorded source/platform pins.
Current-main integration (2026-11-02):
f105d143c56cf6e4e0255a342b4f470720e97d43includes maina4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8and retains the existing public commits. Conflicts preserve main’s math implementations, regression checks and debt entries alongside this topic. Linux x86-64 Release, GCC 16.2.1: rebuilt libc and the three math executables;guest_math,guest_math_exactandguest_dinkumware_internalseach pass three times (9 passes, zero skips), andpublic_headerspasses. The same baseline groups pass on main; conventions and whitespace pass. Source and dependency blobs, executable/library hashes, raw logs and JUnit are retained. This refresh adds no new console, Windows, title, GPU or numerical-reference measurement. Qualification evidence, SHA-25622866bd2a060ba69cd4387d471605afe20ed644e3257174b2d1488635f8c9b52(download verified).The current prerequisite #10265 head
3bf30fd4920e751df3825b9abb75f7a0832ecf37is an ancestor of refreshed headaa78a9ecd819e714b60604b4929c5c8818a1163d.Main conflict refresh, 2026-10-27 10:18 UTC pass: exact head
26ea9fdf6abedd3c11cc4d8c8b601cd51dacc102on 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,main15e71dbe11.Comparison: a scratch loader runs the decrypted
libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. It compared theirexp2with this PR's code, checking result bits (NaN payloads included) anderrno, on:Results:
errnoon all of them.errno. The bits differ on 30,671 random arguments, because that copy is an FMA-contracted build.ERANGEon exactly the arguments in msun's overflow and underflow branches.guest_math: the newCheckExp2ConsoleBitshas 31 cases with the console's results anderrno:±DBL_MAX, the infinities 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: #9850, #10222, #10229, #10234, #10247, #10317, #10253 and #10265, all mine, replace one-line host wrappers near
exp2's or add tests and debt entries at the same anchors, so they conflict textually. This PR lands last: #9777 → #9784 → #10222 → #9850 → #10229 → #10234 → #10245 → #10247 → #10317 → #10250 → #10253 → #10265 → this PR, with #10226 after #10222, #9857 before #10250 and #9771 before #10253. It merges cleanly with #9844 (exp2f). A combined preview of all fifteen heads (f1c3cf72af) resolves every conflict by keeping each port and dropping each host wrapper; each ported function is defined once and each console test is called once, andguest_mathandguest_dinkumware_internalspass in three runs out of three on it. This is the historical fifteen-head preview and did not include #10317. The new order declaration does not extend that historical test claim.Not tested: Linux and macOS (the result no longer depends on the host's
exp2), a console, the floating-point exception flags beyond the existing check, andexp2l.Review follow-up (2026-10-26): private pair
53817b0358f81e7eec203f08f59bf109270dfe73combines current #10317 and this PR, with one definition and regression call per topic. After rebuilding libc and the three executables, guest_math, guest_math_exact, guest_dinkumware_internals and the public_headers manifest audit each pass three repetitions (12 passes, no skips). This is pair integration at the pinned main ancestry, not complete-series or newest-main qualification. Pins, source retention and CPU logs, SHA-25671cdbc1d4d45522c328ccf80b51393626b7b0438d1805397608e8c081d1b9f69.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 did3bf30fd4920e751df3825b9abb75f7a0832ecf37)Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:08:46Z.
Review: COMMENTED
Checked against main
99feaf0eb8and FreeBSDrelease/11.4.0lib/msun/src/s_exp2.c:s_exp2.cline by line.redux, P1–P5, the filter thresholds and the scaling paths are the same, and all 512tblentries are bit-identical to the source when compared as packed doubles.errnovalues inCheckExp2ConsoleBits.exp2only on hosts that misround those inputs, and the negative control was Windows-only. Adding an input where msun itself is not correctly rounded would make it host-independent. Candidates from my reference port, worth confirming against the bundled prx first:0xc0321ba29677ea92→0x3ecdb167a3cd19aa(correctly rounded:...ab)0x40310f6e2ae38766→0x4100aec0c9ca9cd0(correctly rounded:...d1)MakeExtended/CheckExpm1ConsoleBitsanchors inGuestMath.cpp.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.