fix(libc): classify signaling NaNs without raising exceptions #21161
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21161"
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 AlexWhitehouse on 2026-11-15T21:53:36Z.
What
libc's classification exports were implemented with
std::isfinite,std::isnan,std::isnormalandstd::isinf. GCC compiles those toucomisd/ucomisscompares, which raiseFE_INVALIDwhen the argument is a signaling NaN. The result was right, but the call set the invalid-operation flag. FreeBSD 11.4, which the PS5 libc follows, classifies by reading the exponent and fraction bits, so it raises nothing. This PR does the same for:__isfinitedhK16CKwhQg__isfinitefQ8pvJimUWis__isnanGfxAp9Xyiqs__isnanflA94ZgT+vMM__isnormalfGPRa6T+Cu8__isnormalfWkYnBHFsmW4__isinfV02oFv+-JzA__isinffrDMyAf1JhugThe existing
isnan,isnanfandisinfwrappers forward to these, so they're fixed too.Code reaches these exports through
math.h: in FreeBSD 11.4'smath.hlines 111–115,isfinite,isinfandisnormalcompile to calls to__isfinite(f),__isinf(f)and__isnormal(f). Onlyisnanis inline.Sources: FreeBSD releng/11.4 (d1060029):
s_isfinite.clines 33–49,s_isnan.clines 33–59 ands_isnormal.clines 33–49;gen/isinf.clines 42–58.The code is written in the repository's style with
std::bit_castand masks, not copied, so it carries no BSD notice.Behaviour: results, signatures and return values are unchanged for every input. Only the exception flags differ: none is raised, and flags already set stay set. errno is untouched.
Debt: a debt fragment records that the classifiers follow FreeBSD and that console exception-flag behaviour is unmeasured. No inventory count changes.
Tested
Test: the existing
guest_mathtest now has two tables, binary64 and binary32. Each covers signaling and quiet NaNs, ±0, the smallest and largest subnormals, the smallest normal, the largest finite value and ±∞, with both signs. For every export and wrapper, the test:FE_DIVBYZEROalready raised;fetestexcept(FE_ALL_EXCEPT)is unchanged and that errno is unchanged.Inputs are built from bits through
volatile, so the test itself raises nothing. Existing assertions are unchanged.Linux x86-64 (Ubuntu 26.04, GCC 15, Release):
main,guest_mathfails at the flag assertion:__isnanexecutesucomisd %xmm0,%xmm0;guest_mathpasses.Windows 11 (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release):
guest_mathpasses at 2ea572c68a, so the classifiers raise no flags under MinGW's UCRTfenveither, with no compiler warnings in the changed files. The branch was then rebased onto currentmain, and the focused tests pass again on Linux.Mutation checks: putting back
std::isnanin__isnan, orstd::isinfin__isinf, fails the flag assertion.python3 tools/check_conventions.py --base origin/main: all checks passed.python3 tools/debt_fold.py --check: passed.python3 tools/pr_overlap.py: no open PR changes these function bodies or their NIDs. It couldn't compare someMath.cppPRs automatically, so I read their diffs:nextafter/nexttoward;lgamma/signgam.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-16T00:22:31Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
93934ef9f1:tools/check_conventions.pypassed;git diff --checkclean.guest_math_testsbuilt cleanly.guest_math):core/libs/prx/libc/src/Math.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-16T05:59:24Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reviewed code and tests support merging.
What I ran
Reviewed head
93934ef9f14dd94c9b197f69a8b2ac640f5966d4. No commands or tests were run;repo_read.pywas unavailable as an executable tool in this session. Read the prepared description, commit summary, manifest and diff, plus the full text of all three changed files:core/libs/prx/libc/src/Math.cpp,core/libs/tests/GuestMath.cpp, anddocs/dev/debt/changes/fix-libc-classify-signaling-nan.md. No changed files were excluded by the manifest.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not execute tests, inspect CI output, or measure behavior on a PS5 console. The author reports Linux and Windows test passes and mutation checks in the PR description; these were not run in this review.
To get this to a good state
Nothing is required.