fix(libc): compute erff and erfcf with fdlibm's algorithm, as titles' libc.prx does #10226
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10226"
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-23T14:41:24Z.
What
Current public head
4296b2ca68e85c6efc42e068cea49dcc3d5bd3e9incorporates #10113 atf876efc0ef1c529370c6304149e3adb8443e27f4and main atf73d791b3df4dcaa773297a93f5ae2c062ee95a3without rewriting history. The merge retains main's scalar and fusedlogfpaths alongside the error-function implementation. The diff against #10113 is five files. The existing 38erffand 38erfcfresult-bit/errno cases now live inGuestErf.cpp, registered independently asguest_erffandguest_erfcf. An expf failure in the broad math suite can no longer hide these focused checks. The entire error-function implementation/helper/licence block is byte-identical to the preceding public head.Implements the older fdlibm
erffanderfcfalgorithms used by the title-bundled references, including their five argument ranges, rational approximations and split inputs to the twoexpfcalls. This removes the host-library dependence of their last result bits and range errors.Earlier public head
ca8a86166e6fed9ca62c5b74b43b090c3afa0560merges the earlier child324fde3a393e4acb1b0c88a0ae1d9799852924f6with canonical #10113 head86fc4fc9c2f04da5210c6cf23a69aa2f4eed05ce, without rewriting history. At that earlier head, against its actual parent, this topic changed onlyMath.cpp,GuestMath.cppand the erff/erfcf debt note. The parent'sMathExpf.cpp, compiler options and regression fixture are inherited unchanged.The earlier prerequisite refresh incorporated #10113
61549d86c2a61edbd005d9b441748b3d9bd906aaand removed the old inlinedexpfconflict. The child's error-function implementation, helpers and licence were preserved byte-for-byte from5969599111d26ea3015e496655c5ff5f919f6651. Existing public commits and authorship are preserved.The retained
log1pfandexpfchanges are intentional prerequisites from #10007 and #10113. The current #10113 head is an actual ancestor; the evidence includes this PR's topic patch against that parent.Tested
Current public head
4296b2ca68e85c6efc42e068cea49dcc3d5bd3e9passed 8/8 Linux x86-64 Release CTests with zero skips. The suite ranguest_erff,guest_erfcf,guest_expf_environment,guest_math,guest_math_exact,guest_math_elementary,guest_dinkumware_internalsandguest_floating_point. The environment fixture passed all 1,128 checks. Conventions passed on the five-file stacked diff. Exact-head Linux report.Historical test-isolation qualification (2026-11-26): Linux x86-64 / Ryzen 9 7950X / GCC 16.2.1 / Release Ninja, head
f03f9759b5d2bd3c3faea0074c8b9381b6c96996on mainfae9876e971fda0345aa828625389b9f2ffcd487. 7/7 CPU CTests pass, zero skips: the two new independent registrations plusguest_expf_environment,guest_math,guest_math_exact,guest_math_elementary, andguest_floating_point. With the identicalguest_erf_testsexecutable, the exact #10113 prerequisite996aaa42e5f8c7d72bf09031e317b2c9e7228bcffails bothguest_erffandguest_erfcfat their respective bit assertions.ldd -r, actual raw-provider initialization paths, unchanged hashes and registration backtraces are verified. Both original case tables and every expected result are retained byte for byte. This is raw-provider CPU validation; no original-module differential, exhaustive-input or new exception-flag comparison is claimed. Reproducer, maintenance patch, logs, pins and hash/loader receipts — 28 payloads, anonymously downloaded and verified; SHA-256149f295aa0ef8cd06ffdbd3cd2e85885cfe7711eeacb18c6d399abb3b6ef9630.Historical Linux qualification before the later parent merge: Arch Linux x86-64, GCC 16.2.1, Release. Full SDK
libs, relinker and all five focused CPU groups pass at4e397fc892882d7705ab91090adb930282227fd3:guest_mathguest_math_exactguest_dinkumware_internalsguest_floating_pointguest_expf_environment(1,128 inherited parent regression checks)Same-fixture negative control: this child's
guest_math_testsexecutable fails with parent-only61549d86c2a61edbd005d9b441748b3d9bd906aaat an addederffbit assertion (line 4715), then passes with the child SDK. The failure line is verified against the actual child-only diff. Both selected raw-library paths are checked withldd, dependencies useLD_BIND_NOW=1, and source/bank hashes remain unchanged. Loader failures do not count as the negative control.Earlier head
324fde3a393e4acb1b0c88a0ae1d9799852924f6adds only the debt-note clarification after that Linux gate. Its completecore/tree, including CMake, is identical to the tested4e397fc89288head. The conventions and merge-tree check against089d2df72e4a019e37dd707a8574a1081e060fffbelong to that earlier qualification; they are not new checks of the current head or today's main.Build/test logs, same-fixture controls, pinned source and ancestry proofs — SHA-256
251da0a6024e203da9c990f3124d2e9c0a21d6e14eea8759108c048ca8288e32, 57 payloads; downloaded and every payload verified. The official function/branch overlap scans and all fifteen pinned manual shared-file comparisons are included. #24322 is source splitting, not a separate implementation of these corrections.Earlier exact-public-head Linux CPU qualification: seven tests and the same-fixture prerequisite negative control at
ca8a86166e6fed9ca62c5b74b43b090c3afa0560. Fresh raw libc plus focused tests: 7/7 pass, zero skips; the actual prerequisite with the identical child fixture passes 6/7 and fails the new erff bit assertion. Loader/provider and source hashes are verified, and the reproducible archive is anonymously hash-checked. This supplements the historical full-SDK gate above; it is not a new full patched-SDK build or original-module oracle.Earlier-head Windows qualification is reported in the existing validation comment:
ca8a86166emerged onto main87b7ef3891asbeb7e8bb0c, Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release.guest_expf_environment,guest_lgamma_polesandguest_matheach pass in three runs. The same three tests pass three runs on parent-only86fc4fc9c2merged onto that same main asc553316ef1. The comment also reports conventions passing onca8a86166e. These are the existing contributor-reported Windows results, not tests rerun for this description update.The older all-float Windows result/errno measurements are historical and were not rerun after the prerequisite refresh. No fresh native erff/erfcf differential oracle, current-head full patched-SDK build, new macOS, console, GPU or game qualification is claimed here. FMA-contracted title variants can retain different last bits. The parent's larger expf reference matrix is separate evidence, not a rerun claimed for this child. No performance or title-unblock claim.
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)Summary by CodeRabbit
Bug Fixes
Tests
Documentation
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T14:44:20Z.
Review: CHANGES_REQUESTED
Reviewed exact head
4fc9e7e6f1c0529030134bf75ab5415c9900a77f. The PR declares its #10113 dependency, and the posted exact-head Windows exhaustive comparison and focused tests are detailed. Hosted conventions/eligibility pass; hosted Linux/Windows product jobs are skipped, with the relinker/register-context matrix still running.One integration blocker remains: #10222 is also open from your account and edits
Math.cpp,GuestMath.cpp, and the same libc debt file forexpm1f/msun math. A pairwise merge preview of the two exact heads has a content conflict inMath.cpp. Please coordinate the landing order with #10222, record the dependency/order on the PR that lands second, and rerun the focused math tests on the combined head so both implementations are preserved. This does not question the distincterff/erfcfscope or request either PR be closed.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T22:49:17Z.
Review: APPROVED
Reviewed — looks good
The fdlibm
erff/erfcfport, resolved stack, and exact-head qualification evidence address the earlier blockers; I found no remaining blocking defect.What I ran
Reviewed head
7189b23d36fa592794de87cd66d0bda6d575a1faagainst currentmain7a5d9bf02af636382aec927593b1a5867899ed0f; the merge preview completed cleanly (tree6b35e37f6bbff825df0ce54863a86d6b90894d93). Environment: Debian Linux 6.1, Python 3.11.2, GCC 12.2.0. No local build or runtime test was run.Results
git diff --checkreturned exit 0 with no output.GuestMath.cppregistered asguest_mathincore/libs/prx/libc/CMakeLists.txt. The heuristic warning is not a defect.guest_math,guest_math_exact, andguest_dinkumware_internalseach passed three runs, pluspublic_headers; not run locally.write-watchjobs failed; their check annotations expose only exit code 1.Raw local check output
CMake registration output:
PR precheck limitation
The no-build precheck could not complete its ABI and test-quality stages inside its isolated PR snapshot because its helper scripts are not part of that snapshot. I ran the ABI helper separately against the exact base and head and manually resolved the test-registration warning above.
Findings
Blocking
None.
Non-blocking
The macOS write-watch failures remain visible in hosted CI. The repository tracks duplicate macOS write-watch test registration in #13220; the available check annotations do not establish the failure cause for this run, and this PR changes no write-watch or CMake files. The convention warning asks to shorten the added debt note; it is advisory and the check reports no errors.
Sources
s_erff.cat commit59bc2f095289a10b8cfa55cbb2b45c3bd6c2d4ae.e_expf.cat commit8c639945a44588f6cfdddfb057bb5aad88735da0, used by the implementation's tail calculations.Not verified
I did not build or run CTest locally, run Windows/macOS/Linux binaries myself, validate on a PS5 console, or reproduce the exhaustive comparison. The hosted Linux product job was skipped.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T08:44:44Z.
Review: COMMENTED
Reviewed — comments
The prepared diff adds
log1pfandexpfchanges alongside the statederff/erfcfwork; this draft flags that scope mismatch and records the checks not run in this review.What I ran
Read the prepared diff and changed-file manifest for head
95c15665e53e2f15fdfdaf0e449e28eec6c98fa4, plus targeted ranges fromMath.cppandGuestMath.cppthroughrepo_read.py. No build or tests were run.Results
Findings
Blocking
None verified.
Non-blocking
erffanderfcf, but the patch also replaceslog1pfandexpfand adds their tests and debt entries (core/libs/prx/libc/src/Math.cpp:1799,core/libs/prx/libc/src/Math.cpp:3878,core/libs/tests/GuestMath.cpp:305). Please clarify whether these prerequisite changes are intentional in this PR or split them into their own changes. I did not verify their correctness.Not verified
core/libs/prx/libc/src/Math.cpp,core/libs/tests/GuestMath.cpp,docs/dev/debt/libc.md, and prepareddescription.md,commits.md,manifest.json, anddiff.patch. The manifest lists all three changed files as included; none were excluded.To get this to a good state
Nothing is required. Optional: clarify the scope of the
log1pfandexpfchanges.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T20:49:34Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional. Head reviewed:
5969599111d26ea3015e496655c5ff5f919f6651, basemain.What I ran
diff.patch, 504 lines, all four changed files included).repo_read.py searchto confirm the includes inMath.cpp.ghwrite.Results
<cerrno>,<bit>,<cstdint>presentFindings
Blocking
None.
Non-blocking
core/libs/tests/GuestMath.cpp:4377adds two blank lines afterCheckExpm1fConsoleBits. Keep one.core/libs/prx/libc/src/Math.cpp:20repeats the "Conversion to float by Ian Lance Taylor" notice that already appears at line 7 of the same header block. Drop one copy if the licence notice allows it.Not verified
libc.prxand the 2^32 sweeps on Windows. These are author-reported; I did not run them.expfchange in this diff is the same change as #10113.erff_nid_postfix,erfcf_nid_postfix,expf_nid_postfixandlog1pf_nid_postfixinto the NID table, and their callers. I read only the changed hunks and did not read the surrounding head code with the reader.Files read: all four files in
files.jsonreviewed(through the diff). Files excluded by rule: none.To get this to a good state
Nothing is required.
Optional: the two non-blocking cleanups above. Before merge, the author should confirm the merge order with #10007 and #10113 and rerun the GuestMath suite on the final head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T16:51:50Z.
Review: APPROVED
Reviewed — looks good
Nothing in the changed code I inspected shows a verified blocking defect; the author reports Linux SDK and CPU test passes, which I did not rerun.
What I ran
Reviewed head
324fde3a393e4acb1b0c88a0ae1d9799852924f6usingrepo_read.pyto inspect the prepared diff and source at the pinned head. No build or tests were run. The author-reported tests are described indescription.mdand were not independently verified.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The six files listed as reviewed below were read, including every changed line.
review/files.jsonwas not present in the review folder; the available listing and manifest identify seven changed files, all included. The changed lines ofcore/libs/tests/GuestExpfEnvironment.cppwere inspected, including its success-path cleanup, but its early failure return leaves the modified floating-point controls and errno unrestored. This affects only the test process, which exits immediately on failure. Build/test claims, behavior on Windows/macOS or a console, and FMA-contracted title variants were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T07:58:17Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and focused regression coverage support merging, while console and platform qualification remain unverified.
What I ran
Reviewed head
ca8a86166e6fed9ca62c5b74b43b090c3afa0560using the prepared diff and pinnedrepo_read.pyreader. No build or test commands were run. The description reports tests on a different head; I did not independently verify those results.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed
core/libs/prx/libc/CMakeLists.txt,core/libs/prx/libc/src/Math.cpp,core/libs/prx/libc/src/MathExpf.cpp,core/libs/tests/GuestExpfEnvironment.cpp,core/libs/tests/GuestMath.cpp, and both added debt notes underdocs/dev/debt/changes/. All seven changed files listed in the manifest were included and read. The supplied diff excluded no changed files;files.jsonwas not available in the review folder.Not verified
I did not run the build, tests, native floating-point oracle, Windows or macOS checks, console or GPU behavior, or game testing. The description reports Linux SDK and CPU test results at an earlier head and states that the final head changes only a debt note; these claims were not independently validated here.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T12:52:29Z.
Review: COMMENTED
Actionable comments posted: 2
c0a19186-427d-4a9d-bf8a-2a473d6b45fcReviewing files that changed from the base of the PR and between
fae9876e97andf03f9759b5.core/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/src/Math.cppcore/libs/prx/libc/src/MathExpf.cppcore/libs/prx/libc/tests/cmake/guest_erf_tests.cmakecore/libs/prx/libc/tests/cmake/guest_expf_environment.cmakecore/libs/tests/GuestErf.cppcore/libs/tests/GuestExpfEnvironment.cppcore/libs/tests/GuestMath.cppdocs/dev/debt/changes/refresh-erff-erfcf-msun-20261117.mddocs/dev/debt/changes/refresh-expf-log1pf-msun-20261117.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T12:54:21Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and focused tests look sound, while the reported test runs were not rerun in this review.
What I ran
Reviewed head
f03f9759b5d2bd3c3faea0074c8b9381b6c96996using the prepared diff andrepo_read.pyfor changed files and targeted context. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The Linux test results, prerequisite negative control and archive validation are author-reported and were not independently rerun. Console, Windows and title behavior remain unverified here. All changed files listed in the manifest were read:
core/libs/prx/libc/CMakeLists.txt,core/libs/prx/libc/src/Math.cpp,core/libs/prx/libc/src/MathExpf.cpp,core/libs/prx/libc/tests/cmake/guest_erf_tests.cmake,core/libs/prx/libc/tests/cmake/guest_expf_environment.cmake,core/libs/tests/GuestErf.cpp,core/libs/tests/GuestExpfEnvironment.cpp,core/libs/tests/GuestMath.cpp,docs/dev/debt/changes/refresh-erff-erfcf-msun-20261117.md, anddocs/dev/debt/changes/refresh-expf-log1pf-msun-20261117.md. No changed files were excluded by the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T11:16:31Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected changes show no verified blocking defect, but I could not run checks on the pinned head.
What I ran
Reviewed head
4296b2ca68e85c6efc42e068cea49dcc3d5bd3e9using the prepared diff and repository reader. No build or tests were run. The validation in the PR description is author-reported and names a different head.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
No build, tests, negative control, or console validation was run for this head. Read the prepared diff and all ten changed files listed in the manifest; inspected the relevant changed sections and test registrations. No changed files were excluded by the manifest.
To get this to a good state
Nothing is required. Optional: provide a current-head test report, since the report in the description identifies a different head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T22:05:39Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: fix
expfreturning infinity for finite inputs whose correct result is still finite.What I ran
Head:
155d231bf568e54de3c13d99556b6e46e1574afc. No commands or tests were run; I read the prepared diff and targeted source ranges.Results
expfoverflow threshold defectFindings
Blocking
core/libs/prx/libc/src/MathExpf.cpp:43(review/diff.patch:297): the early overflow check returns infinity for every input greater than0x1.62e3000000000p+6f(88.71875), althoughexp(88.71875)is still representable as a finitefloat(the float overflow boundary is about 88.72284). Thus inputs in this interval incorrectly return infinity and raise overflow. Use the actual overflow threshold for the early return, leaving values below it to the normal calculation. Pinned sourceNon-blocking
None.
Not verified
No tests were run. I read the prepared description, commit list, diff and manifest, plus targeted ranges of
Math.cpp,MathExpf.cppandGuestMath.cpp; I did not read all lines of those large files. I did not read the full contents of the CMake test registrations,GuestErf.cpp,GuestExpfEnvironment.cpp, or the debt notes. The manifest lists nine changed files; the full text of these was available in the review bundle, but not all were read. Contributor-reported test results in the description were not independently verified.To get this to a good state
Correct the early
expfoverflow threshold and add a regression case at and around the finite-to-infinity boundary. Then rerun the focusedexpftests and the relevant math suite on the updated head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T22:43:49Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
expfreturns infinity for overflowing finite inputs under every rounding mode, so downward and toward-zero modes do not get the largest finite float.What I ran
Reviewed head
412f172977c4c0fa2dade2935c870d6836aa28b3on the prepared source snapshot. I inspected the changed hunks and targeted source context; I did not run tests or builds. The pinnedrepo_read.pyinvocation failed because its read-only log could not be written.Results
Findings
Blocking
core/libs/prx/libc/src/MathExpf.cpp:45returns positive infinity directly after raising overflow. Under downward or toward-zero rounding, an overflowing positive result should round to the largest finite float; the environment fixture also expects infinity in all four rounding modes (core/libs/tests/GuestExpfEnvironment.cpp:245-253). Preserve the active rounding mode when producing the overflow result, and update the fixture to cover the mode-dependent result.Non-blocking
None.
Sources
expfimplementationNot verified
No tests, builds, console runs, or platform-specific checks were performed. The source-reader command could not complete because its attempt to write a read log was blocked by the read-only workspace.
To get this to a good state
Make overflow results respect the active rounding mode, then rerun the
expfenvironment and math regression checks on the new head.Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T22:50:46Z.
Review: COMMENTED
Architecture findings (1)
Advisory architecture findings (1)
83862cdd-e4bb-425e-b022-623256144cbdReviewing files that changed from the base of the PR and between
155d231bf5and412f172977.core/libs/prx/libc/src/Math.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:25:06Z.
Review: COMMENTED
Built the focused checks against the existing Linux runtime. The
GuestErffixture passed in itserffanderfcfmodes.GuestMathandGuestExpfEnvironmentalso passed.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.