fix(libc): preserve nextafter exception flags and denormal modes #10468
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10468"
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-24T02:04:34Z.
What
Follow-up to #10354: preserve the floating-point environment behavior of
nextafterandnextafterf. The branch contains a rebased copy of that prerequisite, the environment fix, and its portable test correction: three linear commits on mainf26434afa36e58778a9ff4b948aea52dff19eb0c. The prerequisite PR itself remains separate and open.With gradual underflow, a step from zero must raise underflow/inexact while preserving errno. Under DAZ, floating-point comparisons in the current step-direction calculation can choose the wrong adjacent value; a step from zero can also return zero after the library's actual arithmetic. Use representation ordering for the direction, retain the underflow-producing operations, and use the existing
_Feraisehelper for conditional underflow and overflow reporting. Keep #10354's NaN payload behavior.The contract comes from FAR: Changing Tides PPSA03766's bundled
sce_module/libc.prx:nextafterVA0x51b30,nextafterfVA0x51c80,_FeraiseVA0x11da0. The CPU probe executes the converted module; the compared mathematical function bytes are identical to the input module, with hashes in the evidence. This is a Linux execution of original library code, not a physical-console measurement. FreeBSD's double and float sources corroborate the integer direction and underflow arithmetic; the bundled library supplies the errno/helper behavior. No third-party implementation was copied into this follow-up.FAR already loads its own bundled math implementation. This corrects the host fallback; it does not claim to unblock FAR or improve title FPS. Unmasked exceptions and physical-console behavior remain unverified in the debt entry.
Overlap: #10354 is the explicit prerequisite. #6295 changes the long-double/nexttoward family, not these two functions. The overlap tool also reports additive test/debt conflicts and lists older branches it cannot compare against main; those are retained in the attached report. Live nextafter PR search found no separate implementation of this environment fix.
Tested
Exact published-head Windows validation:
ef0afbb7319bbbfeb5fd8ced320cde189fa2fd50, Windows 11 Enterprise 10.0.22621, WinLibs GCC 15.2.0 UCRT r7, Release. Native in-tree libc plus guest_math, guest_math_exact and guest_dinkumware_internals built successfully. All three suites plus the public_headers manifest audit pass three executions each before and after the valid production-only negative (12 passes per phase, no skips). Restoring only pinned pre-change main Math.cpp while retaining the exact PR fixtures forces a real recompilation and different DLL hash; guest_math aborts (0xc0000409), while exact-math, Dinkumware and public-header controls pass. Original source is restored and matches the published head. Actual private libc and compiler-runtime DLL paths/hashes are verified; positive GDB inferiors exit normally. Restored PE binaries are not byte-identical to initial binaries, and no cause or binary-identity claim is inferred. Full logs, JUnit, exact pins, source/runtime hashes and rejected harness attempts, SHA-25681b1db8d50d2885246612fca02f837d3df42a4e740845f62c0c4c941d0cec19d. These are Windows CPU checks, without a new bundled-library differential matrix, physical-console or title run. Earlier results below retain their original source pins.Current Linux refresh:
946149edde2932f7c23797ebd8424874bb6cd316is refreshed onto maina5a780eaaa7f187fe8f5c7f2ef244f6a6dab2762, with prerequisite authorship retained and no merge commits. The original production and regression function bodies are preserved, along with main's log1p implementation, regression calls and current public declarations.Fresh Linux x86-64 Release:
guest_math,guest_math_exact,guest_dinkumware_internalsandpublic_headerseach pass3/3 before and after the production-only main-Math negative control. The negative aborts as expected while exact-math/Dinkumware controls pass. Restored libc is byte-identical and sources clean. Conventions, whitespace and merge-tree checks pass.Exact-head logs, negative/restoration results and preservation proof (SHA-256
f107a42be1dabc4ef72ffddcc6274d35e65ebd40146c811214558b28d4952a90). No fresh original-module matrix, Windows/macOS/title/console or performance measurement is claimed by this refresh. Earlier reports below retain their measured source pins.Previous qualification (historical source pins)
Fresh Linux x86-64, GNU C++ 16.2.1, Release: exact head
5cc53a56c94d2b874a33019adcc26e11bb5a9343on mainf26434afa36e58778a9ff4b948aea52dff19eb0c. Independent libc and focused test-target builds pass.guest_math,guest_dinkumware_internalsandpublic_headerseach pass 3/3.FE_INVALID/FE_DIVBYZERO/FE_OVERFLOW/FE_UNDERFLOW/FE_INEXACT, retaining the independent raw-MXCSR assertion. The shared template covers float and double. No assumption remains that host FE constants equal MXCSR bits._Feraiseinto the public libc API header. Removed the now-duplicate.cppdeclaration; the header audit passes. An intermediate rebased head passed math but failed this audit; its logs remain labeled intermediate in the archive.23d3b36dd9f2c9ef429043b143bfd5beff49b382; source extraction hashes are included. Other main math/header changes are retained. SDK-reference calls and the production negative control were not rerun in this refresh.Exact pins, patch/range diff, builds, all nine focused invocations/JUnit, header compatibility correction and production preservation (23,888 bytes; SHA-256
506174e69e07c92fe617332fd846d0b7d997371d33a7d864116c2184978d8561). No SDK binaries, game assets, saves or code dumps are attached.Historical evidence: previous exact-head module comparisons reported all 480 targeted and 16,384 expanded rows matching FAR's original library on Linux, while the prerequisite retained 208/480 and 4,080/16,384 differences. Earlier same-test negative control is likewise historical, not rerun on this head.
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)Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T04:57:51Z.
Review: APPROVED
Checked against main
6c52b649e7and FreeBSD release/11.4.0lib/msun/src/s_nextafter.c/s_nextafterf.c:std::nextafterat Math.cpp:739-740.signs differ || ux > uy) agrees with msun's signed-word branches: a Python model of both gave 0 mismatches over ~3M random and edge-case bit pairs.x+xoverflow and thex*xunderflow probe use the same arithmetic and conditions as msun. The extra_Feraisecalls add flags the arithmetic already raises, plus ERANGE, which matches what the description says the bundled module does.1ulp*1ulp == 1ulp) follow from that.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T21:55:52Z.
Review: DISMISSED
Reviewed exact head
23d3b36dd9f2c9ef429043b143bfd5beff49b382.Blocking test portability failure:
CheckNextafterEnvironmentcomparesstd::fetestexcept(FE_ALL_EXCEPT)directly withexpectedFlags & FE_ALL_EXCEPT, butexpectedFlagsis expressed in the raw MXCSR status-bit layout (_mm_getcsr() & 0x3f). Those masks are not portable equivalents. The current Windows run on this exact head (MinGW-w64/UCRT) reportsguest_mathaborting at this assertion fornextafterf(0, 1): the operation and MXCSR flags match the expectation, but UCRT'sFE_*constants use a different bit assignment, sofetestexcept()returns a different abstract mask. The reported mapping identifies the discrepancy, and the failure reproduces for both float and double environment cases.Please convert the expected MXCSR status bits to the corresponding
FE_INVALID,FE_DIVBYZERO,FE_OVERFLOW,FE_UNDERFLOW, andFE_INEXACTmask before comparing tofetestexcept, while retaining the separate raw-MXCSR assertion. Then rerunguest_mathon Windows and Linux for the exact head. The focused tests reported on Linux do not cover this platform-specific mismatch.The implementation change itself is not implicated by this finding: the independent Windows report says the result, raw MXCSR flags, and errno match, and the failure is at the test's mixed-representation assertion. I did not run the Windows test locally.