fix(libc): preserve expf rounding and exception behavior #10113
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10113"
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-23T09:57:14Z.
What
expfnow preserves the scalar bundled-libc algorithm's results and floating-point side effects across caller rounding modes. It uses the existing msun-derived reduction and polynomial, with the native range branches, evaluation order and fixed binary32 constants._Feraise(8)and returns positive infinity. The explicit underflow branch calls_Feraise(16)before the final multiplication; the general subnormal path leaves errno unchanged.huge + xinexact trigger.1 + (x - ratio)order. Exact hexadecimal float constants avoid runtime double-to-float conversion under directed rounding.MathExpf.cppretains the existing Sun/msun licence and attribution, with source-scoped-frounding-mathand-ffp-contract=off.The
log1pfprerequisite from #10007 and its authored history remain intentionally retained. This updates the existing PR; no duplicate expf implementation PR is created.Tested
Current-head Linux validation (2026-11-27):
f876efc0ef1c529370c6304149e3adb8443e27f4merges mainf73d791b3df4dcaa773297a93f5ae2c062ee95a3and retains main's scalar and fusedlogfpaths alongside this PR's dedicatedMathExpf.cpp. All six targeted Linux x86-64 Release CTests passed with zero skips. Theguest_expf_environmentsuite passed all 1,128 checks, and the dedicated source retained-frounding-math -ffp-contract=off. Exact-head Linux report.Historical CMake maintenance (2026-11-26): head
996aaa42e5f8c7d72bf09031e317b2c9e7228bcfmerges main79e4f35199fa93b44e4689f391f603dec5b702cb. The maintenance commit changes only CMake placement: the expf source/flag blocks avoid the gamma insertion points, andguest_expf_environmentmoves into an independent test fragment with its originalBUILD_TESTINGguard.MathExpf.cppandGuestExpfEnvironment.cppremain byte-identical to public head86fc4fc9c2f0.A fresh Linux x86-64 / GCC 16.2.1 / Release Ninja build of raw libc/kernel and four focused executables passes.
guest_expf_environment,guest_math,guest_math_elementaryandguest_floating_pointpass, 4/4, zero skips. The CTest backtrace confirms registration from the new fragment; Ninja retains-frounding-mathand-ffp-contract=off; actual raw-provider loading and unchanged input hashes are verified. Conventions, debt-fold and whitespace checks pass. Full Git pair merges with #10226 (ca8a86166e6f), #24306 (0fbd95fdc9d6) and #24360 (53137577143a) are clean; the gamma pairs conflicted in CMake before this maintenance. These are merge checks, not new gamma runtime tests.Maintenance patch, build/test helpers, compiler flags, registration/loader receipts, logs and JUnit — anonymous download and all 20 payload hashes verified; SHA-256
8bd6922de236eda39482f5021367095aca6bfebed52f2d09464650455e5c2ce8. This maintenance validation did not rerun the full patched SDK, Windows, original-module differential, console, title/GPU or performance checks. Earlier mathematical validation remains pinned to the revisions below.Earlier refresh: merged upstream
786bc3afa1c874f98ec2990eb58179a99eeb425cas86fc4fc9c2f04da5210c6cf23a69aa2f4eed05ce. The CMake conflict keeps both this PR'sguest_expf_environmentregistration and main'sguest_lgamma_polesregistration, including their separate Windows environment blocks. The productionMathExpf.cpp, golden fixture and debt fragment are byte-identical to the corrected prior head61549d86.At that earlier pin on Linux 7.3.5-arch1-1, the complete patched/raw SDK and relinker build pass. All five focused CPU groups pass:
guest_math,guest_math_exact,guest_dinkumware_internals,guest_floating_point,guest_expf_environment. Source, configuration and submodules were restored. Current-main patch, build provenance, frozen SDK hashes and verbose test logs, SHA-256811511ebd9c391badddb43bf75489f38728e09bbf92f8ebe24bf11134a634ee8; downloaded again and verified all 19 payload hashes plus the manifest. Hosted CI was pending when that refreshed-pin report was written. The Windows owner also reports the earlier public head86fc4fc9c2f0merged onto main87b7ef3891asc553316ef1:guest_expf_environment,guest_lgamma_polesandguest_mathall pass in each of three runs on Windows 11 Enterprise 22621 / WinLibs GCC 15.2 UCRT Release. This is a three-group Windows check, not a claim that the whole Windows suite ran. Owner report.The original differential and trap measurements below remain historical evidence at their named pins.
Arch Linux x86-64, GCC 16.2.1, Release. Main
7fa48cd1c6cda62b4ebe86575085199a33e08c1d; old public #10113ea1052637d616b6ec43ed9fd0ec4ed90f971f2a6; corrected head61549d86c2a61edbd005d9b441748b3d9bd906aa. Comparisons use frozen private merges of the public branches onto that main. The old-PR composition and the corrected head's pre-fix parent have identical source trees.Full SDK
libs, relinker and four existing CPU groups built and passed on main, main plus old #10113, and main plus #21714. The correction also passes the newguest_expf_environmenttest: 1,128 result/flag/errno/control checks, including a pending divide-by-zero flag. All five groups pass. The exact same new executable fails against both main and old #10113 raw test libraries, then passes with the correction; loader paths are verified and loader failures are excluded.Actual patched SDK versus the original converted PPSA21564 libc export (
ab860676108827e0983eefbde3a711b5ce8e20f0b24b492498b6e04cb23c6130): 6,906 inputs × three x87 precisions × four rounding modes × four DAZ/FTZ states × two pending states = 662,976 comparisons per bank. Both function owners are checked by device/inode, reference outcomes are identical across providers, and banks/modules/probe hashes remain unchanged.Caller control differences: zero for every bank. The SDK's
__erroraliases host errno on this Linux machine, so the two logged errno columns are one channel, not independent measurements.A separate Linux child-process comparison enables exception traps in both x87 and SSE: 144 reference/SDK pairs, checking first-trap signal, flags, errno, result and controls. Old #10113 has 96 mismatches; the correction has zero. Original-module dependencies, including
_Feraise, still come from each SDK, so this does not independently establish console/helper conformance.Complete evidence, source patches and reproducers — SHA-256
eb013afbaf76b1a234a17402ee3c0afc5befd14cf1543813613bdcbe88903bf1, 166 payloads; downloaded and every payload verified. Original binaries, original assembly, game assets, SDK binaries and caches are excluded.Conventions pass; the merge-tree check against current main is clean. The official overlap scan and pinned manual comparisons are included. #10226 is the dependent erff/erfcf child; #21714 is a tested alternative, not a dependency; #19434 forwards a separate library surface; #24322 splits source files. The gamma PRs share independent additive CMake registrations. All fifteen fail-closed primary patches match previously reviewed pins, and the two additional shared test hunks concern nextafter/nexttoward and double lgamma only.
These are sampled Linux CPU measurements, not a new exhaustive all-float result. Prior Windows/macOS reports on the old public head remain historical. The separate Windows owner report above covers three focused groups on the refreshed head composed with its named main; it does not reproduce the original-module differential or trap comparisons. No new macOS qualification is available. FMA-contracted title variants can retain different last bits, as documented in debt. No console execution, game unblock, GPU, loading-time or FPS improvement is claimed.
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
expfresults across normal and very small inputs, including overflow, underflow, and subnormal cases.expfbehavior across rounding modes and floating-point exception conditions.log1pfresults for finite inputs within its valid range, while retaining handling for values outside that range.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T10:20:52Z.
Review: CHANGES_REQUESTED
I reviewed exact head 1977b6b65df827e4d963ae7964dd59676c120f9a. The msun port and test additions look carefully scoped; the exhaustive comparisons against three shipped libc.prx copies are strong evidence, including the documented FMA-contracted exception. The current-main sync check is a clean merge (1 ahead/25 behind), and exact-head
git diff --checkplustools/check_conventions.py --base upstream/mainpass.I found one merge blocker required by the repository overlap rule: combining this exact head with open #10007 produces a content conflict in
core/libs/tests/GuestMath.cpp(git merge-tree --write-treereports conflict). The changes are separate functions, but both insert at the same test location. Please agree with #10007’s author which lands first, record the resultingDepends on: #Non the checklist line, and rebase/resolve the second branch. Then rerunguest_mathon the resolved head. I attempted a local full-build configure for the focused test, but it stops because SDL2 development files are unavailable here; I did not run a local runtime test. Hosted policy/conventions/intake checks and relinker/register-context/write-watch matrices pass; full Linux/Windows jobs are skipped by path policy.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T10:37:29Z.
Review: CHANGES_REQUESTED
Thanks for resolving #10007 first. I verified this exact head is stacked on
89b9820fee, the pairwise merge with #10007 is clean, the checklist now namesDepends on: #10007, and the reportedguest_math3/3 rerun covers the resolved stack. The exact-head diff check passes; conventions reports 0 errors (with an existing/updated debt-length warning on the 1,265-characterexpfentry). The published exhaustiveexpfcomparisons remain strong evidence for the implementation.The remaining declared dependencies are still open: #9771, #9841 and #9844. Pairwise merges of this head with them still conflict (respectively in the debt file,
GuestMath.cpp, andMath.cpp). The branch is also 3 commits ahead/238 behind currentmain, withdocs/dev/debt/libc.mdchanged on both sides. Since your checklist already says to rebase after those three land, please do that, resolve the shared hunks, then rerunguest_mathand conventions on the final integrated head before approval. The current clean merge withmaindoes not include those dependent PRs.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T22:49:15Z.
Review: APPROVED
Reviewed — looks good
The corrected FreeBSD msun implementation, resolved dependency stack, and exact-head qualification evidence address the earlier blockers; I found no remaining blocking defect.
What I ran
Reviewed head
e46591956d0814430a5217575d4569d086c78279against currentmain7a5d9bf02af636382aec927593b1a5867899ed0f; the merge preview completed cleanly (tree9d6e0f49ea728695ba28ac92c9fb9e34e6fa56e6). 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.
Sources
e_expf.cat commit8c639945a44588f6cfdddfb057bb5aad88735da0.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-14T09:06:23Z.
Review: COMMENTED
Reviewed — comments
The reviewed math implementation and focused regression changes show no concrete defect, but I did not run the reported checks or read every line of each changed file, so approval is not justified.
What I ran
No commands were run. The pinned head is
b29bd75e61ae0b190b4ed8105e6f90f3a94423c1; no merged preview was checked. I read the prepared description, commit list, manifest, diff, and targeted changed-file ranges throughrepo_read.py.Results
Findings
Blocking
None identified in the inspected ranges.
Non-blocking
None.
Sources
The reviewed diff is pinned to
b29bd75e61ae0b190b4ed8105e6f90f3a94423c1. Changed lines inspected includecore/libs/prx/libc/src/Math.cpp:1799and:3880,core/libs/tests/GuestMath.cpp:3005and:3760, anddocs/dev/debt/libc.md:256and:379.Not verified
I did not run builds or tests, verify the author's attached evidence, inspect every line of the changed files, or qualify Windows, macOS, console, title, GPU, or floating-point exception behavior. The description reports Linux checks and identifies a shared
public_headersfailure on this head and pinned main. I read targeted ranges in all three changed files; the prepared diff and manifest were read. No changed files were excluded from the bundle.To get this to a good state
Nothing is required. Optional: complete a full-file review and rerun the required checks on this exact head before seeking approval.
Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-17T04:45:49Z.
Review: COMMENTED
Tested on an Apple M4 (macOS 27.2, Apple clang 21.0.0, x86-64 build under Rosetta).
GitHub marks this PR as conflicting, but it merged cleanly onto
mainata72186d3cfplus #22056 and #22074 (two build fixes thatmainneeds on macOS), so I tested it there. Each binary was run 3 times.guest_math_exactguest_mathGuestMathExact.cpp:687(expf(89.0f):errno == ERANGE)GuestMath.cpp:4971(unrelated, see #22081)expfcases this PR addsOn macOS, the msun algorithm sets ERANGE itself instead of relying on the host libm, which never sets
errno.Overlap: the newer #21714 fixes the same
guest_math_exactfailure here by settingerrnoaroundstd::exp.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T20:52:22Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional. The change ports
expfandlog1pfto FreeBSD msun's algorithms, and I found no defect in the code I read.Head reviewed:
ea1052637d616b6ec43ed9fd0ec4ed90f971f2a6(basemain).What I ran
diff.patchand the matching head code viarepo_read.py(includes anderrnosetup incore/libs/prx/libc/src/Math.cpp).Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libc/src/Math.cpp:17: the added Sun copyright block repeats the one that already follows it. Keeping one copy with both attributions would be tidier. Optional.Sources
docs/dev/debt/changes/refresh-expf-log1pf-msun-20261117.md. I did not check the linked FreeBSD permalinks.Not verified
libc.prx(the 2^32-argument claims in the PR description and the debt fragment). These rest on the author's runs and on the external archive, which I did not open.#10007prerequisite for thelog1pfchanges: I did not confirm its merge state.diff.patch.To get this to a good state
Nothing is required. Optionally, merge the two copyright blocks in
core/libs/prx/libc/src/Math.cpp.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T00:20:26Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the author’s Linux evidence reports that the corrected implementation passed the stated CPU comparisons and builds.
What I ran
Reviewed head
61549d86c2a61edbd005d9b441748b3d9bd906aa. I read the prepared description, commits, diff and manifest, then inspected all six changed files at the pinned head usingrepo_read.py. No build or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run the reported Linux builds, fixture comparisons, negative controls, or console/Windows checks. The reported results and external evidence archive were not independently verified. The changed files read were
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, anddocs/dev/debt/changes/refresh-expf-log1pf-msun-20261117.md; all six files markedreviewedin the manifest were read.files.jsonwas not available through the reader.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T07:30:35Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
86fc4fc9c2f04da5210c6cf23a69aa2f4eed05ce. I did not run build or test commands; the build and test results below are author-reported. I read all six changed files listed in the manifest and the prepared description, commit list, manifest, and diff throughrepo_read.py. No files were excluded by the manifest.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not independently reproduce the reported Linux or Windows builds and focused tests, the pinned differential/trap measurements, or hosted CI. Console execution and helper conformance remain unverified, as the change description and debt note state.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T12:23:57Z.
Review: APPROVED
Reviewed — looks good
Nothing in the inspected changes blocks merging; the focused checks reported for this head pass, with broader platform and console checks still unverified.
What I ran
996aaa42e5f8c7d72bf09031e317b2c9e7228bcf. The description reports a Linux x86-64/GCC 16.2.1 Release Ninja build and four focused tests passing at this head; those are author-reported results, not runs performed here.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I 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_expf_environment.cmake,core/libs/tests/GuestExpfEnvironment.cpp,core/libs/tests/GuestMath.cpp, anddocs/dev/debt/changes/refresh-expf-log1pf-msun-20261117.md. All seven changed files listed in the manifest were included and read. I did not run the build or tests, or verify Windows, macOS, console, or title behavior. The review folder’sdescription.md,commits.md,manifest.json, anddiff.patchwere read; no files were excluded by the prepared manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T11:34:34Z.
Review: COMMENTED
Reviewed — no blocking findings
The exact head reviewed is
f876efc0ef1c529370c6304149e3adb8443e27f4; the changed production implementation and its CMake registration appear consistent with the stated goal, and no concrete blocking defect was found in the code inspected.What I ran
No build or tests were run in this review. I read the prepared description, commit list, manifest, diff, the full
MathExpf.cpp, its CMake source and compile-option registrations, and the test CMake fragment. The changed test source,Math.cpp, and other changed hunks were not read in full.Results
Findings
Blocking
None in the code inspected.
Non-blocking
None.
Not verified
I did not read
core/libs/tests/GuestExpfEnvironment.cpp, the changed portions ofcore/libs/prx/libc/src/Math.cpporcore/libs/tests/GuestMath.cpp, ordocs/dev/debt/changes/refresh-expf-log1pf-msun-20261117.md. I also did not run build or tests, or independently verify the validation reports in the PR description. These changed files were included in the review manifest; the listed production and test files were included in the prepared review bundle. I did not inspectfiles.json.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T22:08:42Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
244f4b5b65b972f7c16eb2a34a7ff2feff304beefrom the prepared diff and pinned repository reader. No build or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author reports Linux tests and differential checks at earlier named revisions; those results were not reproduced here. Windows, console, and full patched SDK behavior at this exact head were not verified. The full text of all seven changed files was available and read; 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-30T22:31:15Z.
Review: APPROVED
Reviewed — looks good
The changed
expfimplementation and its regression coverage support the stated rounding and exception behavior at9a339843cfb400226067217d2c7058846705bde0.What I ran
Inspected the prepared diff and changed source context at the pinned head; no executable checks were run.
The description reports Linux test results from earlier heads; those are author-reported and were not reproduced for this review.
Results
Negative control
Not run; no tests were executed in this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
MathExpf.cppat the reviewed headGuestExpfEnvironment.cppat the reviewed headMath.cppat the reviewed headNot verified
No tests were run at this head. Windows, macOS, console behavior, and title-specific behavior were not verified. The Linux, Windows, and differential results in the PR description are author-reported results for earlier revisions.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:25:08Z.
Review: COMMENTED
Built the focused checks against the existing Linux runtime.
GuestExpfEnvironmentandGuestMathpassed.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.