fix(libc): match large lgammal values and exceptions #24306
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24306"
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-11-20T13:43:34Z.
What
Use the bundled library's scaled Stirling expansion for finite
x >= 130, and sine/log reflection for negative non-integers below −130. The existing host wrapper can return different last bits and exception flags at caller-selected x87 precision. Put the implementation inMathGamma.cppcompiled with-frounding-math, and reuse_LLog,_LSin,_LDunscaleand_LDscale; reciprocal Bernoulli corrections and scaling avoid an intermediate overflowing product.Volatile temporaries preserve reciprocal → logarithm → reduced argument → reciprocal-square evaluation. Matching result bits with masked exceptions was insufficient: the early-square prototype changed the first trap/flags in 8 of 54 enabled-exception comparisons; ordered evaluation matches all 54.
The pole correction from merged #24272 is already in main. The additional topic is the large-argument arithmetic and its regression coverage. Other finite inputs continue using host math and retain known differences; this does not complete
lgammal, add an export or establish a title unblock.Tested
CMake integration maintenance (2026-11-26): head
b7431903610f169c9b109ecd2a9f2095234e2e03incorporates main37749b6cd5670e4183753d13efb4865792358f4d; 5/5 focused Linux raw-provider CPU CTests pass, zero skips. The large registrations now use libc test fragments with the originalBUILD_TESTING, Linux trap and Windows PATH behavior retained. Numerical implementation and fixture bytes match the preceding public head. The five selected full branches also merge without resolutions and pass 15/15 CPU CTests. Logs, pins, maintenance patches and loader/hash receipts (SHA-25693f3e19a0c6c81d4473bd0964fd01158956aaa30b03a0e6676d89e77bacb8eea, 60 payloads, anonymously downloaded and verified). No new full-SDK, original-module differential, Windows, console, title/GPU or performance run is claimed.The committed numeric fixture at
0fbd95fdc9d6includes 10 finite negative non-integers below −130, each checked under four rounding modes and three x87 precision modes: 120 of its 360 result/flag/control expectations. Of those, 29 expect the documented NaN/invalid behavior. The execution loop asserts the result bits, standard exception flags and preserved x87 control word for every entry. These negative-reflection checks are part of the repository fixture, separately from the supplementary reference matrices.Linux x86-64, Ryzen 9 7950X, CPU-only on the same machine:
2ae55b02ed626433ff0f25dcb392218b22eb65d3: full SDK/relinker build passes; the new 360-case numeric regression fails as expected. First-trap, poles and three existing math/FPU groups pass (five pass, one expected failure).fab4bc0f32290667f21adbcd0dd35be00a66a3c0: full SDK/relinker build and all six CPU groups pass: 360 measured result/standard-flag/control cases, three precision modes of the first-inexact-trap regression,240 pole cases and non-pole controls, plus existing math/exact-math/FPU groups.libc.prx, original SHA-256ab860676108827e0983eefbde3a711b5ce8e20f0b24b492498b6e04cb23c6130, executed in a native CPU fixture with valid process metadata.#guestreference and plain-NID SDK function ownership are checked bydladdrand device/inode, with unchanged module/source/bank hashes. This is not console execution; no original module, asset or disassembly is distributed.0a025bd3c6a8f744d26cfc1066866c40e303fa43is clean.Downloaded and hash-verified 93-payload evidence bundle; SHA-256
f7800e01568147a5b88c83fc7c9245696a3c30af6da5440601588c7dab808e22. Includes incremental source patch, golden fixture, full build/test logs, actual SDK differential observations, source/owner/hash receipts, enabled-exception comparison and overlap/conventions reports.No game, GPU or FPS run was performed for this CPU math change. The 360-case repository fixture checks standard
FE_ALL_EXCEPT; the supplementary 3,204-case actual-SDK matrix also includes the x87 denormal-operand bit.Independent Linux validation: PrivacyOnion reported Ubuntu 24.04 / GCC 13.3 / Ninja Release at
fab4bc0f32: conventions and both test targets built cleanly, and all three focused CTests passed. Reverting the implementation to main while retaining the fixtures made the numeric and pole tests fail; restoring the change made all three pass. This is contributor-reported testing; their trap test also passed on the negative control, so that test alone does not distinguish the implementations.Windows follow-up: the completed run reports head
4ab55716e27f72f7ec4d4932c314f8d59126ff47merged onto main23e0eeebdeasf2f364823e, on Windows 11 Enterprise 22621 / WinLibs GCC 15.2 UCRT / Release. After the guest-fenv fixture fixes,guest_lgamma_largeandguest_lgamma_poleseach passed all three runs, with none skipped.guest_lgamma_large_trap_inexactis registered only on Linux and was not run on Windows. This summarizes the linked existing report; it is not a new execution or a Windows repetition of the supplementary SDK/reference matrix.Reviewer follow-up: Helldiverr reports Windows 11 Pro 26300 / Ryzen 9 9950X3D / WinLibs GCC 15.2 Release, head
4ab55716e2merged onto main9126826858asd7683af666: both numeric and pole tests passed three runs. Restoring hostlgammalfailed the numeric fixture; nine of eleven source mutations were detected, while two had no observable effect in the tested large-argument domain. The Linux-only trap test was not registered there. The debt note now records the reference-compatible finite-negative NaN/invalid results under some directed-rounding modes. Documentation-only follow-up0fbd95fdc9d6leaves implementation and test blobs unchanged; conventions and debt-fold checks passed. This attributes the linked report rather than claiming another execution.Earlier exact-head Linux fixture check (2026-11-24): the published result records head
0fbd95fdc9d6on Arch Linux 7.3.5 / Ryzen 9 7950X / GCC 16.2.1 / Release Ninja.guest_lgamma_large,guest_lgamma_large_trap_inexact,guest_lgamma_poleseach passed all three runs (9/9 executions). This covers the then-committed fixtures after the guest-fenv test corrections. It is the existing CPU-only run, not a new execution or a repeat of the original-module comparison matrix; the historical matrix and Windows results retain their stated source pins.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
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T13:51:10Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
fab4bc0f32:tools/check_conventions.pypassed.guest_lgamma_large_tests,guest_lgamma_poles_testsbuilt cleanly.guest_lgamma_large,guest_lgamma_large_trap_inexact,guest_lgamma_poles):core/libs/prx/libc/src/Math.cpp,core/libs/prx/libc/src/MathGamma.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T14:05:37Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed code at head
fab4bc0f32290667f21adbcd0dd35be00a66a3c0shows no verified defect, but the reported build and regression runs were not performed in this review.What I ran
Read the prepared diff and changed-file content, plus targeted implementation context, using
repo_read.py. No build or test command was run.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
I did not run the claimed SDK build, CPU fixtures, differential comparisons, or negative-control baseline. Console behavior is not verified. I read all seven changed files listed in the manifest:
CMakeLists.txt,Math.cpp(the changed line is a deletion; nearby implementation context was read),MathGamma.cpp,GuestLgammaLarge.cpp,GuestLgammaPoles.cpp, and bothlgammaldebt notes. No changed files were excluded in the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T20:53:06Z.
Review: APPROVED
Reviewed — looks good
The reviewed change implements large-argument
lgammalhandling and adds regression coverage; the inspected code shows no verified blocking defect.What I ran
Reviewed head
4ab55716e27f72f7ec4d4932c314f8d59126ff47usingrepo_read.pyto inspect the prepared diff, changed files, and relevant helper implementations. I ran no build or tests.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build and test results in the description were not independently verified. No console execution was performed, as the description also notes. Read all changed files:
core/libs/prx/libc/CMakeLists.txt,core/libs/prx/libc/src/Math.cpp,core/libs/prx/libc/src/MathGamma.cpp,core/libs/tests/GuestLgammaLarge.cpp,core/libs/tests/GuestLgammaPoles.cpp,docs/dev/debt/changes/lgammal-large-arguments.md, anddocs/dev/debt/changes/lgammal-pole-flags.md. Excluded files: none reported in the prepared bundle.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T08:44:41Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
0fbd95fdc9d64647d8d35e62d8cf46926382f684. I readreview/description.md,review/commits.md,review/manifest.json,review/diff.patch,core/libs/prx/libc/CMakeLists.txt,core/libs/prx/libc/src/MathGamma.cpp,core/libs/tests/GuestLgammaLarge.cpp, anddocs/dev/debt/changes/lgammal-large-arguments.md.repo_read.pywas unavailable as a shell command in this environment; I used the provided reader tools. No build or tests were run by me. All changed files listed in the manifest were included, though I did not read the full 539-line test source or the full existing Math.cpp source.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libc/src/MathGamma.cpp:42-46).Not verified
I did not run the build, CTest, console execution, or the supplementary SDK/reference comparisons. Contributor-reported test outcomes in the description were not independently verified. I did not read all of
GuestLgammaLarge.cpp,Math.cpp, or the complete CMakeLists.txt; the manifest lists four changed repository files and the debt note, all included in the prepared bundle.To get this to a good state
Nothing is required. Optional: add fixture coverage for negative non-integers below -130.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T12:41:44Z.
Review: COMMENTED
Actionable comments posted: 1
4aeeb41d-b0d1-4914-9ffd-d9b371b70a36Reviewing files that changed from the base of the PR and between
37749b6cd5andb743190361.core/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/src/Math.cppcore/libs/prx/libc/src/MathGamma.cppcore/libs/prx/libc/tests/cmake/guest_lgamma_large.cmakecore/libs/tests/GuestLgammaLarge.cppdocs/dev/debt/changes/lgammal-large-arguments.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T13:00:46Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
b7431903610f169c9b109ecd2a9f2095234e2e03. I read the prepared description, commits, manifest and diff, then checked the new implementation, test fixture, CMake fragment and debt note at the pinned head. No build or test commands were run.Results
Findings
Blocking
None.
Non-blocking
core/libs/tests/GuestLgammaLarge.cpp:506-507saves the caller’s x87 and SSE control state, butstd::abort()on a failed expectation prevents restoration. This is confined to the test process; consider restoring the state before reporting failure if this fixture is reused in-process.Not verified
I did not independently verify the contributor-reported Linux, Windows, reference-module, or merge-preview results, and did not run a build or tests. I read all six files listed in the manifest; none were excluded by the manifest. The repository reader did not expose a separate
files.jsonin its review namespace.To get this to a good state
Nothing is required. The optional test-state cleanup is noted above.