Repository navigation
fix(libc): preserve nextafter exception flags and denormal modes - #10468
Conversation
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Linux run at this PR's exact head Arch Linux, kernel 7.2.9, Ryzen 9 7950X, g++ (GCC) 16.2.1 20260810, glibc 2.44, x86-64. Release,
This is the focused test only; no title or console was checked. AI-assisted: yes (Claude Code). |
harisibrar1
left a comment
There was a problem hiding this comment.
Checked against main 6c52b64 and FreeBSD release/11.4.0 lib/msun/src/s_nextafter.c / s_nextafterf.c:
- This still merges cleanly onto current main, and main still forwards to
std::nextafterat Math.cpp:739-740. - The representation-ordered direction (
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. - The zero step, the
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. - Nothing forces MXCSR, so DAZ/FTZ and rounding stay the guest's. The DAZ/upward-rounding rows in the new test (no errno for
1ulp*1ulp == 1ulp) follow from that.
Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
aad4324 to
23d3b36
Compare
|
Rebased onto main |
|
Windows run of 23d3b36 merged onto Built The library's answer is right there: for With that line comparing against the Require(exceptions == (((expectedFlags & 0x01u) ? FE_INVALID : 0) | ((expectedFlags & 0x04u) ? FE_DIVBYZERO : 0) | ((expectedFlags & 0x08u) ? FE_OVERFLOW : 0) | ((expectedFlags & 0x10u) ? FE_UNDERFLOW : 0) | ((expectedFlags & 0x20u) ? FE_INEXACT : 0)));On glibc x86 the |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed exact head 23d3b36dd9f2c9ef429043b143bfd5beff49b382.
Blocking test portability failure: CheckNextafterEnvironment compares std::fetestexcept(FE_ALL_EXCEPT) directly with expectedFlags & FE_ALL_EXCEPT, but expectedFlags is 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) reports guest_math aborting at this assertion for nextafterf(0, 1): the operation and MXCSR flags match the expectation, but UCRT's FE_* constants use a different bit assignment, so fetestexcept() 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, and FE_INEXACT mask before comparing to fetestexcept, while retaining the separate raw-MXCSR assertion. Then rerun guest_math on 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.
23d3b36 to
5cc53a5
Compare
|
Corrected the test's MXCSR/fenv mask conversion on fresh main Linux libc/focused build passes; The requested exact-head Windows rerun is still needed. Our Windows machine is user-paused and I have not resumed it. The description distinguishes this remaining coverage from the Linux result. |
5cc53a5 to
946149e
Compare
|
Refreshed as Fresh Linux: four focused groups pass3/3 before and after the expected main-Math negative failure; exact/Dinkumware controls pass and restored libc is byte-identical. Conventions/whitespace and merge-tree pass. No new Windows/title/original-module/performance claim. Evidence (SHA-256 |
946149e to
ebf162f
Compare
ebf162f to
ef0afbb
Compare
|
@MarcZX10 The requested native Windows rerun for the portable raw-MXCSR-to-FE mask correction is complete on exact published head Windows 11 Enterprise22621, supported WinLibs GCC15.2.0 UCRT r7, Release: libc and all three math executables build; guest_math, guest_math_exact, guest_dinkumware_internals and the public_headers manifest audit each pass three runs before and after restoration (12 passes per phase, no skips). The production-only control restores pinned pre-change main Math.cpp with the PR fixtures retained and forces recompilation: guest_math aborts ( Actual loaded private libc/runtime paths and hashes were verified, with positive GDB inferiors exiting normally. Restored PE hashes differ from initial hashes; binary identity is not claimed. The plain-abort fixture does not identify an exact assertion in this evidence, so this is scoped to the recorded production-only differential. A separate bounded negative-stack diagnostic is pending. Windows logs, JUnit, exact pins, source/runtime hashes and accepted/rejected harness attempts, SHA-256 AI-assisted: yes (GPT-6.1 Sol, medium effort); native Windows commands executed on the established Windows host via its separate FIFO. |
|
The bounded Windows GDB follow-up now attributes the production-only negative control to This identifies the failing fixture; the later unwind contains unknown frames, so it does not establish an assertion line or a complete stack. The GDB process-exit field was unavailable and is not used as success evidence. The original primary qualification archive remains unchanged. Diagnostic logs, module paths, source/library hashes, script and terminal FIFO receipt, SHA-256 AI-assisted: yes. |
Dismissing a stale review: the requested changes were addressed after it (new head) and the merge queue blocks on it. Please request changes again if anything is still open.
|
Checked the step direction and the underflow/overflow arithmetic against msun |
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)