fix(libc): compute tanh with FreeBSD msun's algorithm, as titles' libc.prx does #10316
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10316"
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:29:53Z.
What
tanhreturned the host'stanh, so its last bit depended on the host. For example,tanh(0x3f927ed0db8370b1)is0x3f927e4d1092a580in the bundledlibc.prxand0x3f927e4d1092a57fon Windows (UCRT). On 20 million random arguments, UCRT'stanhdiffers from the titles' copy on 1,428,804.The titles' copy (NID
JM4EBvWT9rc) is FreeBSD msun'ss_tanh.c, computed through msun'sexpm1.tanhnow computes it over the staticExpm1from #10306, which is now merged on main:2^-28shortcut;|x| >= 1form1 - 2 / (expm1(2|x|) + 2);|x| < 1form-t / (t + 2)witht = expm1(-2|x|);1 - tinyfrom 22 up, withtinyread at run time.It calls
Expm1directly, not the exportedexpm1, so noerrnocan come from the inner call. Its arguments never exceed 44 in magnitude anyway. The titles' copy sets noerrnofor any argument, and neither does this port.Tested
Current Linux refresh: head
a5b452fa493d91a14fbb3e708f618171a9b3dcb4, directly on main50a4f824fc3ee23177d8e1effbe306e50150187f. The merged #10306 commit is no longer duplicated in this stack. Production added/removed lines are byte-identical to the previous reviewed head. Fresh independent libc/math build; guest_math and guest_dinkumware_internals each pass three consecutive runs. With only Math.cpp reverted to the direct parent's production code and the new fixture retained, guest_math aborts; restoration returns both groups to passing and reproduces the original libc library hash. Conventions/whitespace pass.Read-only merge-tree against fetched main
dc15ed65375228a0f69c41d7770c4c118adb38f2is clean; the checks above are on the explicitly stated tested base, not a build of that merge tree. Windows remains user-paused and has not been rerun on this head.Exact-head Linux build, JUnit, negative/restoration controls and rebase proof, SHA-256
1087c9bf4d5bd4e0a9c5e54b5d18e710c1e576d7de607f0adc30d41d23af67a2.Historical previous-head evidence (not rerun on the current head):
Independent Windows regression report on the refreshed head (ycbuzi): PR head
e2c058c1ff4eea220f3b1aba3f3d35d339ba82b7was cleanly integrated onto mainfa515def85asb3c835692con 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
171b98173f536676ab8c8c3aba0a443ff060fb16; Windows was not rerun on the refreshed commit. Results described as 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 #10306's head.Comparison: a scratch loader runs the decrypted
libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. It compared theirtanhwith this PR's code, checking result bits (NaN payloads included) anderrno, on 16,068,211 arguments per title:Results:
errnois never set.errnoeither. The bits differ on 1,054 arguments, because that copy is an FMA-contracted build.guest_math: the newCheckTanhConsoleBitshas 24 cases with the bundled library's results:DBL_MAX, ±infand NaN payloads of both signs;Each case also checks that
errnostays unchanged.guest_mathandguest_dinkumware_internalspass in three runs out of three on the exact head.Negative control: with #10306's
Math.cppand these tests,guest_mathaborts in aRequire, whileguest_dinkumware_internalsstill passes.python tools/check_conventions.py --base#10306's head, andgit diff --check, pass.Order: Standalone tanh change on main, which now contains the required internal Expm1 implementation from merged #10306.
Not tested: macOS, a physical console, floating-point exception flags, and
tanhl. The original module comparison and negative control were Windows-only; the new Linux build and regression checks are scoped separately above.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:41Z.
Review: APPROVED
Checked against main
39a36bbec8and FreeBSD release/11.4.0 lib/msun/src/s_tanh.c and s_expm1.c:std::tanh, and its staticExpm1(from #10306) never touches errno, so the "no errno" claim holds.s_tanh.cexactly: the thresholds, thehuge+x>oneshortcut, both expm1 forms, and1-tinyat |x| >= 22.s_tanh.cands_expm1.creproduces all 24 expected values inCheckTanhConsoleBits, so the table agrees with the reference algorithm.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:36Z.
Review: CHANGES_REQUESTED
The earlier source-level review and the reported Linux/Windows exact-head tests provide good coverage of the algorithm. The remaining integration evidence is stale: this branch is based on
6c52b64, 6,887 commits behind currentmain, while the hosted Linux and Windows product jobs are skipped. Please refresh the branch onto currentmainas required by CONTRIBUTING.md, then rerunguest_mathandguest_dinkumware_internalson the final head on Linux and Windows. Keep the negative control clearly tied to the final head.