Skip to content

fix(libc): compute erff and erfcf with fdlibm's algorithm, as titles' libc.prx does - #133

Open
Thimo188 wants to merge 70 commits into
mainfrom
upstream-pr/10226
Open

Thimo188 wants to merge 70 commits into
mainfrom
upstream-pr/10226

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#10226, originally opened by JJenkx.

Source commit: 412f172977c4c0fa2dade2935c870d6836aa28b3. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

Current public head 4296b2ca68e85c6efc42e068cea49dcc3d5bd3e9 incorporates boykopovar#10113 at f876efc0ef1c529370c6304149e3adb8443e27f4 and main at f73d791b3df4dcaa773297a93f5ae2c062ee95a3 without rewriting history. The merge retains main's scalar and fused logf paths alongside the error-function implementation. The diff against boykopovar#10113 is five files. The existing 38 erff and 38 erfcf result-bit/errno cases now live in GuestErf.cpp, registered independently as guest_erff and guest_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 erff and erfcf algorithms used by the title-bundled references, including their five argument ranges, rational approximations and split inputs to the two expf calls. This removes the host-library dependence of their last result bits and range errors.

Earlier public head ca8a86166e6fed9ca62c5b74b43b090c3afa0560 merges the earlier child 324fde3a393e4acb1b0c88a0ae1d9799852924f6 with canonical boykopovar#10113 head 86fc4fc9c2f04da5210c6cf23a69aa2f4eed05ce, without rewriting history. At that earlier head, against its actual parent, this topic changed only Math.cpp, GuestMath.cpp and the erff/erfcf debt note. The parent's MathExpf.cpp, compiler options and regression fixture are inherited unchanged.

The earlier prerequisite refresh incorporated boykopovar#10113 61549d86c2a61edbd005d9b441748b3d9bd906aa and removed the old inlined expf conflict. The child's error-function implementation, helpers and licence were preserved byte-for-byte from 5969599111d26ea3015e496655c5ff5f919f6651. Existing public commits and authorship are preserved.

The retained log1pf and expf changes are intentional prerequisites from boykopovar#10007 and boykopovar#10113. The current boykopovar#10113 head is an actual ancestor; the evidence includes this PR's topic patch against that parent.

Tested

Current public head 4296b2ca68e85c6efc42e068cea49dcc3d5bd3e9 passed 8/8 Linux x86-64 Release CTests with zero skips. The suite ran guest_erff, guest_erfcf, guest_expf_environment, guest_math, guest_math_exact, guest_math_elementary, guest_dinkumware_internals and guest_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 f03f9759b5d2bd3c3faea0074c8b9381b6c96996 on main fae9876e971fda0345aa828625389b9f2ffcd487. 7/7 CPU CTests pass, zero skips: the two new independent registrations plus guest_expf_environment, guest_math, guest_math_exact, guest_math_elementary, and guest_floating_point. With the identical guest_erf_tests executable, the exact boykopovar#10113 prerequisite 996aaa42e5f8c7d72bf09031e317b2c9e7228bcf fails both guest_erff and guest_erfcf at 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-256 149f295aa0ef8cd06ffdbd3cd2e85885cfe7711eeacb18c6d399abb3b6ef9630.

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 at 4e397fc892882d7705ab91090adb930282227fd3:

  • guest_math
  • guest_math_exact
  • guest_dinkumware_internals
  • guest_floating_point
  • guest_expf_environment (1,128 inherited parent regression checks)

Same-fixture negative control: this child's guest_math_tests executable fails with parent-only 61549d86c2a61edbd005d9b441748b3d9bd906aa at an added erff bit 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 with ldd, dependencies use LD_BIND_NOW=1, and source/bank hashes remain unchanged. Loader failures do not count as the negative control.

Earlier head 324fde3a393e4acb1b0c88a0ae1d9799852924f6 adds only the debt-note clarification after that Linux gate. Its complete core/ tree, including CMake, is identical to the tested 4e397fc89288 head. The conventions and merge-tree check against 089d2df72e4a019e37dd707a8574a1081e060fff belong 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. boykopovar#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: ca8a86166e merged onto main 87b7ef3891 as beb7e8bb0c, Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. guest_expf_environment, guest_lgamma_poles and guest_math each pass in three runs. The same three tests pass three runs on parent-only 86fc4fc9c2 merged onto that same main as c553316ef1. The comment also reports conventions passing on ca8a86166e. 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

Summary by CodeRabbit

  • Bug Fixes

    • Improved single-precision exponential, logarithm, and error-function results for edge cases and rounding modes, with more consistent floating-point exception behavior.
  • Tests

    • Added regression checks for math results, error values, exception flags, rounding modes, and preservation of floating-point environment state.
  • Documentation

    • Updated development notes on math-function behavior, reference implementations, and validation coverage.

MarcZX10 and others added 30 commits October 26, 2026 22:17
log1pf now runs the whole of FreeBSD's s_log1pf.c for finite inputs above -1 instead of mapping negative inputs to -log1p(-x/(1+x)). Compared with the pinned source over every finite float above -1 it has no differing result bit; the old mapping differed on about 82 million inputs, the first at 0xb3000001.
…duction boundaries

The expected bits come from the pinned s_log1pf.c.
log1pf now runs the whole of FreeBSD's s_log1pf.c for finite inputs above -1 instead of mapping negative inputs to -log1p(-x/(1+x)). Compared with the pinned source over every finite float above -1 it has no differing result bit; the old mapping differed on about 82 million inputs, the first at 0xb3000001.
…duction boundaries

The expected bits come from the pinned s_log1pf.c.
(cherry picked from commit 87f635c)
(cherry picked from commit 134201f)
log1pf now runs the whole of FreeBSD's s_log1pf.c for finite inputs above -1 instead of mapping negative inputs to -log1p(-x/(1+x)). Compared with the pinned source over every finite float above -1 it has no differing result bit; the old mapping differed on about 82 million inputs, the first at 0xb3000001.

(cherry picked from commit ae53b71)
…duction boundaries

The expected bits come from the pinned s_log1pf.c.

(cherry picked from commit 3fcdc09)
JJenkx and others added 29 commits November 5, 2026 04:09
# Conflicts:
#	core/libs/prx/libc/src/Math.cpp
expf follows lib/msun/src/e_expf.c and log1pf follows
lib/msun/src/s_log1pf.c, both at release/11.4.0. Add their source
line, the float-conversion credit and the Sun notice as those files
carry them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main's boykopovar#21714 set expf's ERANGE in the Math.cpp expf this branch replaces.
The branch's msun expf in MathExpf.cpp keeps the console's errno (overflow
and the underflows the console reports; guest_math pins those bits), so the
Math.cpp definition stays removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 130 core/libs/prx/libc/src/MathExpf.cpp
core/libs/prx/libc/tests/cmake/guest_expf_environment.cmake
core/libs/tests/GuestExpfEnvironment.cpp
docs/dev/debt/changes/refresh-expf-log1pf-msun-20261117.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants