fix(libc): raise FE_INVALID from fdim and fdimf for equal infinities #12366
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12366"
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-28T11:20:23Z.
What
Titles'
libc.prxcomputesx - ybefore comparing it with zero infdimandfdimf. Sofdim(inf, inf)andfdim(-inf, -inf)return+0and raiseFE_INVALID, from the invalidinf - inf. The exports here forwarded to the hostfdim, which compares first and raised nothing.Both now return the host result for a NaN argument, which already matches the titles and raises nothing for a quiet NaN. Otherwise they compute the difference and return it when it is positive, else
+0. A newCheckFdimFlagscovers equal infinities (+0withFE_INVALID), ordinary and infinite differences, and NaN arguments (NaN, no flag).Tested
Current-main integration — 2026-11-04. Head
c5d31ec4d7835ddc1fcf938afa87b51447015bd8includes mainb11c7bf84f5d2f636ff60166cc3371bd071e24d5and preserves previous public commits and attribution/licence notices. Retains the fdim/fdimf result, errno and exception regressions alongside current main.Linux x86-64, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON: rebuilt actual libc/Ampr and selected executables.
guest_math,guest_math_exact,guest_dinkumware_internalseach pass 3/3 (9 runtime passes, zero skips);public_headers, conventions and whitespace checks pass. Pinned main passes all 17 selected baseline groups 3/3 (51 passes) plus headers. Before/after dependency checks agree: 34 recursive trees and 31,551 tracked blobs, zero errors; the update=none QuickJS test262 corpus is explicitly excluded from these library inputs.Source/parent/gitlink proofs, library/test hashes, raw logs/JUnit and head-leased push receipts: qualification archive, SHA-256
7c347f620951ad6f39068740750949212c6412815da094a46a96eca1d15c8bbf(download verified). Older platform, stress, negative-control and reference reports retain their original pins; no new Windows/macOS, full-suite, SDK-module, console, title/GPU or performance claim. AI-assisted: yes (Codex).Earlier dated qualifications below retain their original source/platform pins.
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON, onmain3a40945e62.guest_mathpasses in each of 3 runs.main'sMath.cppand this test,guest_mathfails.libc.prx: I loaded PPSA07923's and PPSA13934's bundledlibc.prxnatively and calledfdimandfdimfby NID, side by side with this build. That covered 441 pairs from 21 values (±0, ±1, ±2, ±0.5, ±3, ±1.5, ±inf, ±NaN, ±1e300, a subnormal, 1024, -1075), comparing result bits,errnoand raisedFE_INVALID/FE_DIVBYZERO/FE_OVERFLOW/FE_UNDERFLOW:fdim:main2 differences → 0 (the two equal-infinity pairs);fdimf: 8 → 0.errnodifferences for both.Not tested on Linux or macOS.
Overlap:
tools/pr_overlap.pyreports AlexFigas's #11260, #11262 and #11266 editingMath.cpplines 550–552. Theiracoslline is next to the twofdimlines this replaces, so it's a textual adjacency with no shared behaviour. AlexFigas agreed on #11260 that this lands first and rebased that stack to depend on it.Independent reports on this head (their runs, summarised here):
d19ce8c4c1applied tomain673fa865f4:guest_mathpasses 5/5; withMath.cppfrommainit fails 5/5 at the first newfdimcheck.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 MarcZX10 on 2026-10-28T11:21:10Z.
Review: COMMENTED
I reviewed the change and the special-value tests. Computing the subtraction before the comparison reproduces the equal-infinity invalid exception; the NaN path preserves the tested title behavior, and returning literal
0.0keeps the nonpositive result positive zero. The paired title-libc comparisons described here are useful evidence. I have not approved yet: the current head53ac55dahas only started its CI, and the first conventions run was cancelled. I will recheck after the refreshed checks complete.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T13:14:16Z.
Review: COMMENTED
macOS / clang + GCC check at head
53ac55da58(basemain3a40945e62; merges cleanly onto750cf6cf48)The body says Linux and macOS were not tested. To check it here, I built the two
fdim/fdimfbodies fromMath.cpp(head andmain) as a separate translation unit, which is howlibcis built, together with this PR'sCheckFdimFlagsunchanged. I didn't build the full libc target (its submodules aren't available here). Apple clang 21.0.0 and Homebrew GCC 16.2.0, macOS.mainSo the fix and the new test both hold on macOS and with libc++.
check_conventions --base upstream/main: passed.Mutants (separate TU, the PR test as-is):
x→ killed.: 0.0→: -0.0→ killed.difference > 0.0→difference >= 0.0SURVIVES. Withfdim(-0.0, +0.0)the difference is-0.0, so>=returns-0.0where head returns+0. Your 441-pair comparison includes the ±0 pairs and reports 0 differences, so the titles' libc returns+0there. This one line kills the mutant (I checked it against head and>=):return x > y ? x - y : 0.0;, which ismain's semantics) is killed at -O0 and under GCC -O2 (it branches withcomisd/jbebeforesubsd). It is not killed under clang -O2 on either arch. Clang turns the select into an unconditionalfsub+fcsel/maxsd, soinf - infraises anyway. This doesn't block anything: the GCC lanes do discriminate. It does mean that on clang builds the test only proves the flag, not the evaluation order.Non-blocking robustness note. If the body gets inlined into a constant-argument caller, clang folds
inf - infat compile time and the flag is lost. That happens with a single TU, and with-fltoacross TUs: head FAILS the test that way on both arches.-frounding-math(or-ffp-exception-behavior=strict) on the defining TU brings it back (head OK under LTO). GCC 16 keeps the flag even with-flto. Nothing in the tree enables IPO/LTO today, so this is latent.MathExact.cppalready gets-frounding-mathincore/libs/prx/libc/CMakeLists.txt. If more flag-sensitive exports land inMath.cpp, giving it the same treatment would make them independent of inlining.AI-assisted: yes (Claude Code)