Skip to content

test(libc): compare the C exception flags in the scaled hyperbolic checks - #10907

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
imellag:test/libc-math-standard-exception-flags
Oct 27, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
imellag:test/libc-math-standard-exception-flags

Conversation

@imellag

@imellag imellag commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

What

The _FSinh and _FCosh special-value checks in guest_math read the raised flags with fetestexcept(FE_ALL_EXCEPT) and compare them with an exact set. On macOS FE_ALL_EXCEPT is 0x3f: besides the five C exception flags it holds FE_DENORMALOPERAND (0x02), the x86 flag an SSE operation raises when an input is subnormal. glibc's and FreeBSD's FE_ALL_EXCEPT leave it out (0x3d). So on macOS the check for _FSinh(0x1.fffffep+127, 0x1p-149) sees the denormal flag from its 0x1p-149 argument and fails:

_FSinh special (0x1.fffffep+127, 0x1p-149): got 7f800000, expected 7f800000, errno 34, flags 2e

The result, errno and the expected flags (FE_DIVBYZERO | FE_OVERFLOW | FE_INEXACT, 0x2c) all match. The checks now read FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT, which is FE_ALL_EXCEPT on Linux and FreeBSD. The failure message prints the same set. Nothing else changes.

Tested

Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 Release under Rosetta 2. main alone doesn't build the libc tests on macOS, so the tree is main 61fc572cee plus the open macOS build PRs and the parts of mugurc's series that #7201 also carries.

guest_math stops at the first failing check, and on macOS three things stop it. Two are in the library and already have open PRs: acosf(0.5f) is one ulp off with Apple's x86-64 libm (#9668), and fmodf(1, 0) raises no FE_INVALID there (#10345). The third is this one. With #9668 and #10345 applied:

  • without this change it aborts at the _FSinh line above;
  • with it, guest_math passes 3 runs out of 3.

With only one of the two library PRs, it stops at the other one's check, so all three are needed for the test to pass on macOS. Not run on Linux or Windows. On glibc the new set is exactly FE_ALL_EXCEPT, so the checks don't change there.

check_conventions.py --base upstream/main passes. pr_overlap.py reports no conflicting lines, and none of the pull requests it couldn't compare touches these checks.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

…ecks

The _FSinh and _FCosh special-value checks read the raised flags with
fetestexcept(FE_ALL_EXCEPT). On macOS FE_ALL_EXCEPT also holds the x86
denormal-operand flag, which an SSE operation on a subnormal input such
as 0x1p-149 raises, so the check saw 0x2e where it expects 0x2c. glibc
and FreeBSD leave that flag out of FE_ALL_EXCEPT. The checks now read
the five C exception flags.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 476b63d. The change reads the five standard C floating-point exception flags explicitly in the scaled-hyperbolic special checks and their diagnostic, avoiding macOS's extra x86 denormal flag while retaining the existing exact comparisons for invalid, divide-by-zero, overflow, underflow and inexact. On this Linux host I independently compiled and ran a C++20 static assertion that this mask equals ; and also pass. The reported M4 Pro/macOS Rosetta run exercises three times on a tree with the prerequisite macOS math fixes and passes 3/3; hosted product tests for this test-only diff are skipped. I attempted local CMake configuration in an isolated worktree, but it cannot configure because the SDL2 submodule is uninitialized there and XRandR development support is unavailable, so I did not run the full guest test locally. The diff is narrowly scoped and I found no correctness issue. AI-assisted: yes.

@MarcZX10

Copy link
Copy Markdown
Contributor

Clarification to my approval: GitHub's review body lost several inline-code terms to shell quoting. The intended statements are that the explicit five-flag mask equals FE_ALL_EXCEPT on this Linux host, git diff --check and python3 tools/check_conventions.py --base upstream/main --head refs/remotes/upstream/pr-10907 pass, and the reported guest_math run passed 3/3 on the described macOS/Rosetta tree. The full local test did not run because CMake configuration is blocked by the uninitialized SDL2 submodule and missing XRandR development support. This clarification does not change the approval or its scope.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 11203 core/libs/tests/GuestMath.cpp L54

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.

Pull request Shared files not compared
PR 6295 core/libs/tests/GuestMath.cpp
PR 10113 core/libs/tests/GuestMath.cpp
PR 10226 core/libs/tests/GuestMath.cpp
PR 10345 core/libs/tests/GuestMath.cpp

@ycbuzi

ycbuzi commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Windows check of 476b63dd45 merged onto main 63a863d3b0 (5965265bdc, clean). Windows 11 Home 10.0.26200, WinLibs MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON. guest_math builds with no warnings and passes both runs of ctest --repeat until-fail:2, so comparing the C exception flags in the scaled hyperbolic checks holds with MinGW's UCRT FE_* values as well.

Not run: a title. AI-assisted: yes (Claude Code)

@oneandonlydean oneandonlydean self-assigned this Oct 26, 2026
@oneandonlydean
oneandonlydean merged commit 1eb876b into boykopovar:main Oct 27, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants