fix(libc): compute atan2f with FreeBSD msun's algorithm, as titles' libc.prx does #9784
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9784"
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-22T14:46:50Z.
What
Based directly on main
3a930342d5a2189b78643818f04b8948fc4c3dc9ase54e3569f38e815640fe0861734a1a1fd399448b, one topic commit. #9777 is already merged: its atanf implementation is inherited unchanged from main, and no local export declaration is added. This PR adds only atan2f’s implementation, bit regressions and debt entry.atan2freturned the host'satan2, so its last bit depended on the host. On Windows (UCRT) it differs from thelibc.prxthat titles ship on 7,126,466 of the 200,001,024 argument pairs I compared (3.6%). Examples, console thenmain:atan2f(0x3d6f53e1, 0x3fb6a73e)→0x3d279f68;atan2f(0xbe51a574, 0xbdf4773f)→0xc006505a.The titles'
atan2f(NIDEH-x713A99c) is FreeBSD msun'se_atan2f.c, which calls msun'satanf.atan2fnow uses that code with theatanfport already merged in main (#9777):x == 1cases;|y/x| > 2^26and< 2^-26shortcuts;pi_lo;tinyandpi_loread at run time, as msun'svolatilereads do.msun's NaN case is
return x + y. The titles' binaries returny's NaN when both arguments are NaN (atan2f(0x7fc00000, 0xffc00001)is0x7fc00000). So this returnsy + ywhenyis NaN andx + xotherwise, which does not depend on how the compiler orders the commutative add. None of the copies checked setserrno, and neither does this.atan2fis imported by 21 of the 22 titles whose relinker registries I audited, for example PPSA01528, PPSA02630 and PPSA09614.Tested
Current Linux refresh (2026-10-25): exact head
e54e3569f38e815640fe0861734a1a1fd399448bdirectly on main3a930342d5a2189b78643818f04b8948fc4c3dc9, without merge commits. The complete production file equals that main plus the original atan2f port in its original position after atanf; the original regression body is unchanged and called once. The documentation conflict preserves every current-main row and inserts only the atan2f debt entry, retaining newer rename/nan descriptions.Fresh Linux x86-64 Release libc and all three math targets built.
guest_math,guest_math_exact,guest_dinkumware_internalsandpublic_headerseach pass three runs (12 passes). Keeping candidate tests and substituting only exact main productionMath.cppmakesguest_mathabort as expected; the other three groups pass 9/9. Restored candidate gives 12 passes and a byte-identical rawlibc.prx. Conventions, whitespace and merge-tree checks pass.Exact-head logs, main negative control and full-file preservation proof (SHA-256
9561cce663daccfb7abdd7e2c185f5ac2f079c7d0418d3053262d4cfb6f9f590). The earlier module/Windows figures below stay pinned to their original revisions. No new large reference matrix, Windows, macOS, physical-console, exception-matrix, game/GPU or performance result is claimed. Depends on remains none.Earlier Linux qualification (historical source pins)
Fresh Linux x86-64 Release qualification on
e51eb4eeb9482d94a9851983a31d3194fa284345against main8b426927d7d91c137e6f4704acc860f060a2798a: rebuilt libc and all three focused math targets.guest_math,guest_math_exact,guest_dinkumware_internalsandpublic_headerseach pass three repeats. Retaining final tests and substituting only main’s production Math.cpp makes guest math abort while exact-math and Dinkumware pass. Restored candidate passes all four groups three times and produces byte-identical libc. Conventions and whitespace checks pass.Source proof confirms the complete production file equals current main plus the original atan2f implementation at its original topic placement; atanf remains main’s already-merged body. The original atan2f bit regression function is unchanged, public libc header includes remain intact, and no local atanf declaration is added. No large reference matrix, Windows, title or performance test was repeated in this refresh.
Fresh regression/negative/restoration logs, source proof, exact pins and patch, SHA-256
d6266456e70e7ace08d07d7ecbe989834e954e70bcbe0b7f1bcc16fd6dc2ca48.Earlier qualification (historical source pins)
Rebased-head check (2026-10-22): on Windows, the retained build log for
bc78074cc859cd4e9a1e0d9d259de4d34e7f044ecompletes successfully. The retained controller summary reports eight focused tests passing in each of three runs and conventions passing on that head; raw per-run CTest output was not retained in that summary. This is focused regression evidence on base3bbd2321de, not a new 200,001,024-pair comparison or a claim that the base is the latest upstream revision. See the rebase report.Original implementation validation: the sampled comparison and negative control below were performed on the original base, not rerun exhaustively on the rebased head.
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,main8b3e39832a+ #9777.Sampled comparison: a scratch loader runs the decrypted
libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. It compared theiratan2fwith this build'satan2f_nid_postfixon 200,001,024 pairs:atanfrange edges,2^26-scale values, infinities, quiet and signalling NaNs);xnear ±1;ya third of the time.All give the same bits, and no copy sets
errno. Pairs outside the sample are unverified, because 2^64 pairs can't be run exhaustively.guest_math: the newCheckAtan2fConsoleBitshas 23 cases with the console's outputs: random pairs in all four quadrants where UCRT differs, the special cases, and both NaN orders.guest_mathand the libc tests (8) pass in three runs out of three. With #9777'sMath.cpp(portedatanf, hostatan2f) and this test,guest_mathaborts in aRequire.python tools/check_conventions.pyandgit diff --checkpass.Independent Linux review: Dom3005's report tested head
bc78074ccmerged cleanly ontomainfcd455870: Ubuntu 26.04 in Docker on Windows, GCC 15, glibc 2.43, WSL2 kernel 6.6, Release,BUILD_TESTING=ON. The reviewer reports five passingguest_mathruns (--repeat until-fail:5). Keeping this PR's test while restoring main's changed production sources makes the test fail on Linux as well. This supplies a Linux regression comparison in addition to the Windows evidence above; it is reviewer-supplied evidence for those revisions, not a local rerun or a latest-main claim.Not tested: macOS, a console.
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 MarcZX10 on 2026-10-22T16:31:59Z.
Review: DISMISSED
I reviewed the incremental second commit (
cc3e30485f) separately from its prerequisite #9777. The implementation follows the cited FreeBSD msun quadrant/special-case algorithm, and the addedguest_mathvectors cover the reported UCRT mismatches, signed zeros, infinities and NaN ordering. Current-maincheck_conventions.pyandgit diff --checkpass. I did not runguest_mathlocally. The PR reports three Windows runs and a 200,001,024-pair comparison against three title libc.prx copies; the upstream PR’s automated relinker/register-context checks pass, while full Linux and Windows product jobs are skipped.This stack is 19 commits behind live
main(8499ea52e571b0edfc1feecfd3f6b9944012b359). CONTRIBUTING.md requires branches to be based on and kept up to date withmain. Please refresh the #9777/#9784 stack against current main and rerunguest_mathon the final head before merge.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T16:56:31Z.
Review: COMMENTED
I reviewed the incremental #9784 change separately from prerequisite #9777. The updated stack
#9777→#9784has reported three repeated Windowsguest_math/libc suite runs and the 200,001,024-pair comparison against title libc.prx implementations. Upstream relinker/register-context checks pass; full product jobs are skipped. The current #9784 head merges cleanly andgit diff --checkpasses, but the stack base is still499b1cf9fc, eight commits behind currentmain(11f976b27c16ed91633f00039dba5dfd97dd7cc1). Please refresh both commits and rerunguest_mathon the final stack head before merge. I did not run the math tests locally.