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

Merged
imellag merged 1 commit from upstream-pr/10907 into main 2026-10-27 05:28:31 +00:00
imellag commented 2026-10-25 09:19:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-25T09:19:28Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5003432315 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10907). Originally posted by [imellag](https://github.com/imellag) on 2026-10-25T09:19:28Z. --- ### 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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 09:23:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T09:23:14Z.

Review: APPROVED


Reviewed head 476b63dd45. 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5642452695 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10907#pullrequestreview-5642452695). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T09:23:14Z. **Review:** APPROVED --- Reviewed head 476b63dd458109b78aff0035e627689ce3775f15. 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10907
No description provided.