fix(libc): raise the flags of the unselected value in roundl and fdiml #23401
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23401"
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 DerKarussellbremser on 2026-11-19T00:25:54Z.
What
The two flag-only rows of #22838. In the
libc.prxbundled with PPSA10122 01.101.000 (SDK 5.00),roundl(0x4cd80) andfdiml(0x47cc0) have the shape of FreeBSD msun'ss_roundl.cands_fdim.c, compiled so that both candidate results are computed and one is selected afterwards. The arithmetic of the candidate that is not returned still raises its flags:roundltakest = floorl(|x|)and always formst + 1, then returnstort + 1. For|x|of 2^64 and more,t + 1is inexact, soFE_INEXACTis raised although the result isx. This libc used the hostround, which raises nothing there.fdimlalways formsx - yand returns it or+0. Whenx <= y, that subtraction can still raiseFE_INEXACT, andfdiml(inf, inf)returns+0withFE_INVALID. This libc only subtracted whenx > y.Both now compute the unselected value as well. It is held in a
volatileso the compiler keeps the operation; GCC otherwise moves it into the branch that uses it.Two smaller things the measurement showed, both fixed here:
std::isfiniteandstd::isnanraisedFE_INVALIDon it, so both functions now classify from the bits.roundldiffered from the module in the result bits for 21 of 200,000 arguments; with the module's sequence it no longer does.No constant or table from the module is involved.
Tested
Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT, Release, on
main9ffa95e7d9.guest_math_exactaborts (exit code 0xc0000409) on the baseMathExact.cppand passes with the change.ctest -R "^guest_(math|dinkumware|bessel|sce_v2|floating)": 61 of 61 pass, with the 33 test targets behind them brought up to date at this source.fdiml) of the #22838 table at each of the control words 0x37f, 0x27f, 0x7f, 0x77f, 0xb7f and 0xf7f, comparing result bits, the union of the x87 and MXCSR exception flags anderrno:roundl: 0 differences in all six modes. Before: 49,686 flag differences at 0x37f, and 21 in bits plus 49,700 in flags at 0x27f.fdiml: 0 differences in all six modes. Before: 97,898 flag differences at 0x37f and 100,224 at 0x27f.roundlon 500,000 more arguments at 0x37f, 0x27f and 0x77f: 0 differences for arguments in an encoding the x87 produces. A fifth of those arguments are raw 80-bit patterns; 59,612 of the ones that are not a valid encoding differ, which I have not looked into (floorlhere is the host's).tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branch fix/roundl-fdiml-flags: no overlap with the 2,002 open pull requests.volatilehas to do the same job for GCC 13 and Clang; a console; other SDK versions.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)roundlandfdimlrows of #22838)🤖 Generated with Claude Code
https://claude.ai/code/session_011TXsSW8zeAgKgHLCFsYwM3
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T00:27:08Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
430dba2c90:tools/check_conventions.pypassed.guest_math_exact_testsbuilt cleanly.guest_math_exact):core/libs/prx/libc/src/MathExact.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.x - yin a volatile long double to ensure exception flags (such as FE_INEXACT and FE_INVALID on inf - inf) are raised per FreeBSD msun semantics, and returns the expected result.!(x >= 0.0L)to correctly preserve -0.0L, computest + 1in a volatile long double to raise FE_INEXACT on large finite values (|x| >= 2^64), and selects correctly based on-0.5L < difference.Looks Good To Me