fix(libc): compute asin and acos with FreeBSD msun's algorithm, as titles' libc.prx does #10253
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10253"
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-23T15:52:41Z.
What
asinandacosreturned the host's functions, so their last bit and theirerrnodepended on the host. For example,asin(0x3fef4102aaf38ef0)is0x3ff5abc7e3600d9don the console and0x3ff5abc7e3600d9con Windows (UCRT). Likewiseacos(0x3fde7903ac7bb90a)is0x3ff13151a8ce8628there and0x3ff13151a8ce8629here.For arguments outside [-1, 1],
main'sasinreturns a negative NaN and raisesFE_INVALID, but leaveserrnoalone (#3605, which followed FreeBSD's source). The titles' copy setsEDOMthere.acosonmainis the host's.The titles' copies (NIDs
7Ly52zaL44QandJBcgYuW8lPU) are FreeBSD msun'se_asin.cande_acos.c. Both now compute them:|x| == 1and|x| > 1cases;pS/qSrational, written once asAsinRationalbecause both files use the same coefficients;|x| < 0.5,0.5 <= |x| < 0.975and|x| >= 0.975paths ofasin, and thex < -0.5andx > 0.5paths ofacos, with theirsqrtsplit at the low word;acos'spio2_lo, read at run time as msun'svolatileread does.errno: msun sets none, but the titles' copies setEDOMfor every argument outside [-1, 1]: finite ones, the infinities, and every NaN. That is exactly msun's(x - x) / (x - x)return, which both ports now take. It gives the default negative NaN for non-NaN arguments, asmain'sasintests expect, keeps a NaN argument's payload, and raisesFE_INVALIDitself. Arguments in [-1, 1] never set it.Tested
Current-main refresh — 2026-11-04. Head
3135ae25861c85b24139896b133e7cbca68c9718merges main9ab6a281ea61c9e62a7eb07eb4cef8f19ede1c5cwhile retaining the prior public head as an ancestor. Main’s newer code, regression fixtures and debt entries are preserved alongside this topic.Linux x86-64, GCC16.2.1, Ninja Release: actual libc, libkernel and libSceAmpr CMake owners rebuilt coherently.
guest_math,guest_math_exact,guest_dinkumware_internalseach pass three consecutive runs (9 passes, zero skips). The same groups pass three times on pinned main. Public-header audit and conventions pass. Original licence-notice trailing whitespace is retained where present. The scoped recipe reuses frozen ZArchive/zstd providers; this is not a whole-project build. No new Windows, bundled-SDK, physical-console, title/GPU or FPS measurement is claimed; earlier reports retain their original pins.Exact source/parent proofs, per-branch patches/input manifests, build and CTest logs/JUnit, library/executable hashes and scoped CMake recipe, SHA-256
97a2377bc996be1690e8853e1ea090a98b5ed808bcc37a15a5cdada5c2e00845(download verified). AI-assisted: yes (Codex).Review follow-up —
7e375f18d465586d4e50d2893d4d2a9a840702e2. Restored main's float-trig debt wording: the existingTrigfKernelRemPio2remains a separate one-word/precision-0 port, not shared with the new double reduction. Movedtan_nid_postfixand its complete s_tan.c notice together above the e_sinh.c notice, which again directly precedessinh_nid_postfix. Trimmed the four notice-line trailing spaces. Executable tokens are unchanged except for the order of the tan definition; notice wording is retained.Linux x86-64/GCC16.2.1 Release: rebuilt actual libc,
guest_math_tests, andguest_math_exact_tests; both test groups pass three repetitions each (6 passes, zero skips). Conventions andgit diff --check 4f41f4c375fpass. No new Windows, console, title or performance run is claimed. Review-fix patch, logs and source hashes, SHA-2564ce442ee8617e329d8e5f1e6c36e628e65e921bf84421dcc4c15e50c88da1f2b(GitHub asset digest verified).Current-main integration — 2026-11-03. Head
af6e9e83fa50bfe3bff146f2560120f11b9f1d0aincludes main4f41f4c375f5abb487dbd184fbc150f31994d762and retains the prior public history and attribution/licence notices. Main’s newer math implementations and fixtures remain alongside this topic. Main’s float argument-reduction tables, helper andTrigfRemPio2remain byte-identical and separate from the retained topic double-trig implementation. Actual open prerequisite #10250 head5c054e6b5e48aef1bde87b7f6c31b70a9e00d563is 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. The four notice-line trailing spaces from this integration are removed in the follow-up below; no claim that main uses them remains.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):
2181a5edab48e035145cff5825c79240a87e8181includes 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 #10250 head
5c054e6b5e48aef1bde87b7f6c31b70a9e00d563is an ancestor of refreshed headaf6e9e83fa50bfe3bff146f2560120f11b9f1d0a.Main conflict refresh, 2026-10-27 10:18 UTC pass: exact head
57b6d204b0f7856c66cd6b997330c02dc9e5b83eon 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,main4be3da2c6f.Comparison: a scratch loader runs the decrypted
libc.prxof PPSA07923, PPSA05916 and PPSA13934 natively and supplies__error. It compared theirasinandacoswith this PR's code, checking result bits (NaN payloads included) anderrno, on:Results:
errnoon all of them.errno. The bits differ on 5,576asinand 1,823acosarguments, because that copy is an FMA-contracted build.errnorule: the console setsEDOMon exactly the arguments outside [-1, 1].guest_math: the newCheckAsinConsoleBitshas 25 arguments, each with the console'sasinandacosand itserrno:inf;main's existingasinchecks still pass, except one. The check from #3605 thatasin(2.0)leaveserrnoat 0 now expectsEDOM, because both PPSA07923's and PPSA05916'sasin(2.0)set it (and every other argument outside [-1, 1] does too). ItsFE_INVALIDchecks, raised for 2.0 and not for a quiet NaN, are unchanged and pass. cc @CouchRiv: the NaN bits and flags from #3605 are kept; only theerrnofollows the console instead of FreeBSD's source.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: #9771 (
asinf), #10222, #10229, #10234, #10245, #10247 and #10250, all mine, replace one-line host wrappers nearasin's andacos'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 → #10250 → #10253 → thepowPR, with #10226 after #10222, #9857 before #10250 and #9771 before #10253. A combined preview of all twelve heads (5d16b438db, including #9857 and #9771) 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.Not tested: Linux and macOS (the result no longer depends on the host's functions), a console, the floating-point exception flags, and
asinl/acosl.Current Linux qualification (2026-10-28)
Rebased onto
main2227f1366188cda5699dd20e2e756a18006a5d4b. Linux CPU validation on 2026-10-28 at5b96a875888056c5bd758270593be17d1a3f5542(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 Linux qualification — 2026-10-29
Refreshed against main
5454cd2e455994d992aca39335ce60507eeda1eb.Linux qualification at
ec98fb890ddb084b3a597798521e2c24260fb344(Arch Linux 7.2.9, Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON):guest_math,guest_math_exact,guest_dinkumware_internalseach pass three consecutive runs (9/9, no skips). Thepublic_headersaudit passes at this exact head. All tracked public-header files match the pinned main; the affected test targets rebuild against those headers. Conventions and whitespace checks pass. The same focused groups passed three times on the pinned main.Evidence: immutable Linux qualification bundle. Its SHA-256 is
53b095da2f67f55b8aa56ba273681e0330fb39739be844458038dde410fb8cc4. No fresh Windows runtime execution is claimed; older measurements retain their recorded source pins.AI-assisted: yes (Codex).
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 did5c054e6b5e48aef1bde87b7f6c31b70a9e00d563)Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:47:40Z.
Review: APPROVED
Checked against main
39a36bbec8and FreeBSD release/11.4.0 lib/msun/src/e_asin.c and e_acos.c:asin/acos(Math.cpp:359-366) haven't changed since your base.sqrtsplit and acos's volatilepio2_loall match, andAsinRationalis exactly msun'sp/q.CheckAsinConsoleBits. It gives the expected asin and acos bits for every one, including the three UCRT-differing arguments. So the expectations agree with the cited source, not only with the port.CheckExpm1ConsoleBits), so they conflict textually and whichever lands second needs a trivial rebase. You've already listed the order.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T09:15:17Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
This pull request does not merge cleanly into
main(4f41f4c375): head096332ca54conflicts incore/libs/tests/GuestMath.cppPlease rebase it onto current
main. I will review the change once it merges cleanly.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T14:21:47Z.
Review: CHANGES_REQUESTED
Re-checked — changes still requested
The new commits (
f7a1526101cb…af6e9e83fa50) bring in currentmainand #10250's head, and they add msun source and licence notices. The conflict is gone, but thesinf/cosf/tanfdebt entry now claims ak_rem_pio2.cport that the code does not share.What changed since my last review
The text of my previous review is not available to me, so I reviewed the whole change again. According to the author's last comment, that review asked for a conflict with current
mainto be resolved. Since then:main4f41f4c375f5and #10250's head5c054e6b5e48, which is an ancestor of this head.3c88fb4e8ca8,096332ca5449).5c054e6b5e48keepsmain's float argument reduction (TrigfIpio2,TrigfKernelRemPio2,TrigfRemPio2) apart from the doubleKernelRemPio2.What I ran
Head
af6e9e83fa50bfe3bff146f2560120f11b9f1d0a,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree134c2613b7dea84a648bd57658eb5b41b8344220. The worktree was already built (Release, GCC 14.2.0, Ninja, BUILD_TESTING=ON) on Debian 13, 32 vCPU Xeon Gold 6136.mainlibsmaintoo.guest_net_ctlskip is known onmainguest_math,guest_math_exact,guest_dinkumware_internalscheck_conventions.pygit diff --checkguest_mathaborts withmain'sMath.cppgit status --porcelainempty,guest_mathpasses againgit diff --check
Negative control
Line 975 is the
asinbit check inCheckAsinConsoleBits.Previous findings
main— Resolved. The head merges cleanly into4f41f4c375f5with--no-ff, it builds, and the focused tests pass.New findings
Blocking
sinf/cosf/tanfdebt entry contradicts the code (docs/dev/debt/libc.md:160).k_rem_pio2.cis "shared withsin,cosandtan".5c054e6b5e48, the float functions still use their own one-word,prec0TrigfKernelRemPio2(Math.cpp:1415, called at L1549).RemPio2calls the newKernelRemPio2(…, nx, 1)(L1785).main's wording ("ported only for one input word andprec0") is still the accurate one, and debt entries have to describe what the code does.main's sentence for that entry; orKernelRemPio2(tx, ty, e0, 1, 0)and removeTrigfIpio2/TrigfKernelRemPio2.Non-blocking
tan_nid_postfix, not bysinh_nid_postfix.tan, andsinhloses its notice.tan_nid_postfix) above line 2008, for example right aftercos_nid_postfix.k_rem_pio2.cnow exist twice.RemPio2Ipio2(L1269) andTrigfIpio2(L1401) are the same 66-entry table, andKernelRemPio2generalisesTrigfKernelRemPio2. This is fine for now, but it is the duplication that blocking finding 1's second option would remove.git diff --checkfails on four notice lines (731, 1694, 1803, 1831).mainkeeps such trailing spaces for the other SunSoft notices in this file. On4f41f4c375f5, no line ofMath.cppends inthis noticewith a trailing space.asin/acos code review (whole change):
asin_nid_postfixandacos_nid_postfixbranch by branch with msun 11.4 e_asin.c/e_acos.c: thresholds, the low-wordsqrtsplit, thepS/qSrational and acos's volatilepio2_lo. They match.RemPio2/KernelRemPio2also match msun's structure.-ffp-contract=off, so the bit expectations do not depend on contraction.errno/FE_INVALIDchange toCheckAsinfollows the titles'libc.prx, as the author reports, and it is covered by the debt entry.Not verified
libc.prxcomparisons (16M/64,303 arguments, 320M trig arguments) and the Windows runs are author-reported. I did not reproduce them.To get this to a good state
sinf, cosf, tanf and sincosfdebt entry match the code: restoremain's wording, or really shareKernelRemPio2.tan_nid_postfixand its s_tan.c notice out from between e_sinh.c's notice andsinh_nid_postfix.main.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T15:22:16Z.
Review: APPROVED
Re-checked — approved
Commit
7e375f18d465fixes all three of my earlier requests: it restoresmain'ssinf/cosf/tanfdebt wording, moves the s_tan.c notice andtanback above e_sinh.c's notice, and trims the four trailing spaces in the notices. The checks, the focused tests and the negative control all pass.What changed since my last review
7e375f18d465, on top ofaf6e9e83fa50. The range-diff shows commits 1–7 unchanged. The new commit changes onlyMath.cpp(notice lines and the order oftan) anddocs/dev/debt/libc.md.Math.cppthe only code change is the position oftan_nid_postfix. The tokens of the function itself are unchanged.mainkeeps trailing spaces in its notices.What I ran
Head
7e375f18d465586d4e50d2893d4d2a9a840702e2,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree0542f4a6156d2c2a1533e9c1d741e1f7ea843454. Release build with GCC 14.2.0 and Ninja, on Debian 13 (32 vCPU Xeon Gold 6136).mainlibs(build.json)main. Theguest_net_ctlskip is known onmaingit diff --checkcheck_conventions.pyguest_math,guest_math_exact,guest_dinkumware_internals,public_headersguest_mathaborts (Subprocess aborted) withmain'sMath.cppguest_mathpasses,git status --porcelainis emptyPrevious findings
sinf/cosf/tanfdebt entry contradicted the code: Resolved. docs/dev/debt/libc.md:160 again says "ported only for one input word andprec0". The merged diff againstmainno longer changes that line. This matches the separateTrigfKernelRemPio2.tan_nid_postfix(Math.cpp:2008–2034). The SunSoft notice and the e_sinh.c line now come directly beforesinh_nid_postfix(Math.cpp:2038-2050).k_rem_pio2.ctable and kernel exist twice (RemPio2Ipio2/KernelRemPio2andTrigfIpio2/TrigfKernelRemPio2): Still open. The author deliberately keeps the float reduction separate, and the debt entry now says so. This is not a blocker.main: Resolved.git diff --checkis clean, and the description and comment no longer make the claim.New findings
Blocking
None.
Non-blocking
None.
Not verified
libc.prxcopies (asin/acos: 16 million random and 64,303 structured arguments; trig: 320 million) and the Windows runs are reported by the author. I did not reproduce them.