Skip to content

test(libc): read only the standard exception flags in the tiny asin and atan check - #24311

Open
Jazeupoi wants to merge 1 commit into
boykopovar:mainfrom
Jazeupoi:test/guest-math-tiny-trig-standard-flags
Open

Jazeupoi wants to merge 1 commit into
boykopovar:mainfrom
Jazeupoi:test/guest-math-tiny-trig-standard-flags

Conversation

@Jazeupoi

Copy link
Copy Markdown
Contributor

What

guest_math fails on macOS since #23972 added CheckTinyInverseTrigFlags:

core/libs/tests/GuestMath.cpp:4794: requirement failed

The check compares std::fetestexcept(FE_ALL_EXCEPT) with FE_INEXACT. On x86_64 macOS, FE_ALL_EXCEPT is 0x3f and includes FE_DENORMALOPERAND (0x02). An SSE operation on a subnormal input sets that flag, so for ±denorm_min the test reads 0x22 where it expects 0x20. With temporary logging, the four failing cases are asin and atan of 0x1p-1074 and -0x1p-1074: the result bits and errno are as expected, the flags are 0x22. glibc's FE_ALL_EXCEPT has no such flag, so Linux passes.

The file already defines StandardExceptions, the five C exception flags, for this. The check now uses it, as #20503 did for two other tests. The library is unchanged, and the check still requires exactly FE_INEXACT for nonzero inputs and no flag for zeros.

Tested

Apple M4, macOS 27.0.1, Apple clang (Command Line Tools), x86_64 Release build under Rosetta 2. main 0a025bd3c6 with #17425 and #11049, which the macOS build needs.

Tree guest_math
main fails 3 of 3 at GuestMath.cpp:4794
this PR passes 3 of 3

Not run on Linux or Windows. The change only drops non-standard flags from the comparison, so a platform whose FE_ALL_EXCEPT is the five standard flags reads the same value as before.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 (Claude Code)

@PrivacyOnion PrivacyOnion 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.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against dc3734b0c5:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_math_tests built cleanly.
  • CTest (guest_math):
    1/1 Test #1216: guest_math .......................   Passed    0.04 sec
    100% tests passed, 0 tests failed out of 1
    
  • Code reading:
    • Verified GuestMath.cpp line 4794 uses StandardExceptions instead of FE_ALL_EXCEPT in CheckTinyInverseTrigFlags, correctly masking out platform-specific non-standard FP exception flags like FE_DENORMALOPERAND (0x02 on x86_64 macOS/Darwin)
    • Verified StandardExceptions definition in GuestMath.cpp encompasses the five standard IEEE 754 / C99 floating-point exception flags (FE_DIVBYZERO, FE_INEXACT, FE_INVALID, FE_OVERFLOW, FE_UNDERFLOW)
    • Confirmed errno, result bits, and clear-exception preconditions remain intact and uncompromised across all tested tiny asin and atan inputs
    • Checked AGENTS.md compliance: no comments added, conventions and git diff checks pass, and tests execute cleanly

Looks Good To Me

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head dc3734b0c5, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#17478, #21223, #24030, #24201, #14202, #18889, #19531, #21641, #21773, #22468, #22471, #23239, #23255, #23484, #23869, #23992, #18425, #21195, #21255, #22989, #23507, #23886, #14582, #17878, #19666, #19899, #20138, #21656, #21746). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
guest_math, guest_math_elementary, guest_math_exact (3 tests, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6522 tests) on the RTX 3080 has 4 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. The 2125 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@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 — looks good

The change limits the tiny inverse-trig test to the five standard floating-point exception flags, matching its stated cross-platform intent; I found no blocking defect.

What I ran

Reviewed head dc3734b0c5f55b8a0ebad2a9d5fa59d7e096d7db. I read the prepared description, commit list, manifest, diff, and the changed source at the relevant ranges using repo_read.py. I did not run tests or a build.

Results

Check Result Note
Diff and changed code passed The comparison uses the existing standard-flags mask.
Build and tests not run No local execution.

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports macOS results; I did not independently run them. Linux and Windows behavior was not tested. The only changed file, core/libs/tests/GuestMath.cpp, was read at the changed function and the existing mask definition and usage sites. No files were excluded from review according to the manifest.

To get this to a good state

Nothing is required.

@Helldiverr

Copy link
Copy Markdown
Contributor

Tested dc3734b0c5 on Windows, merged onto main 1f2e77165a: guest_math passes on main and on the merge (3 of 3). On MinGW the old mask and the new one have the same value, so the macOS failure cannot happen here. I emulated it by also counting the denormal-operand flag, and the check still passes: asin and atan built with GCC raise no such flag for ±denorm_min.

Existing runs. kiwe147 ran guest_math at this head on Windows 11 as one of a 30-PR batch, and it passed. PrivacyOnion ran it on Linux, and it passed. Neither run includes a negative control or mutations. MarcZX10 read the code and ran nothing.

What this run adds. A run on this PR alone, on current main. A check of the old mask's value on MinGW. A detector check for the denormal-operand flag. Mutations of the mask and of the asin and atan tiny paths.

Code.

  • The PR changes one line: core/libs/tests/GuestMath.cpp:4794 now reads std::fetestexcept(StandardExceptions) where it read std::fetestexcept(FE_ALL_EXCEPT). StandardExceptions (:61) is the five C flags. It is already used at :3352 and :3388.
  • The check still requires FE_INEXACT alone for the four nonzero inputs and no flag for the two zeros (:4790). The library is unchanged. asin_nid_postfix (core/libs/prx/libc/src/Math.cpp:1311-1313 on main) and atan_nid_postfix (:1799-1801) return x and raise FE_INEXACT for nonzero inputs without any floating-point arithmetic on it.
  • MinGW defines FE_ALL_EXCEPT as (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) (WinLibs GCC 15.2, fenv.h:18). That is the same set as StandardExceptions, so on Windows the change does not alter the value compared.

PR body.

  • The body says that a platform whose FE_ALL_EXCEPT is the five standard flags reads the same value as before. That is confirmed for MinGW: with the old mask put back, the check passes (c1).
  • The body also says that an SSE operation on a subnormal input sets FE_DENORMALOPERAND. That holds for an explicit SSE add here (c2s). With GCC, though, the asin and atan calls themselves set no such flag (c2). So the four macOS failures depend on how that build runs those calls, and Windows cannot reproduce them.

Suggestion. No pin. The change is a no-op on this platform, and the mutations below show that the narrowed mask still catches wrong flags from the library.

Negative control and mutations. Each change was made on the merge and run once with guest_math.

change where result
c1: old mask, std::fetestexcept(FE_ALL_EXCEPT) GuestMath.cpp:4794 Passed (same value on MinGW)
c2: macOS emulation: clear x87 and MXCSR flags before the call, then compare fetestexcept(FE_ALL_EXCEPT) combined with the denormal-operand bit (0x02) of the x87 status word and MXCSR :4792-4794 Passed (neither function sets the bit for ±denorm_min)
c2s: c2 plus probe = input + 0.0 on a volatile double before the call (detector check) :4792-4794 fails at the Require: the SSE add sets the bit for the subnormal inputs
c3: mask StandardExceptions & ~FE_INEXACT :4794 fails at :4794
c4: mask FE_INEXACT only :4794 Passed (weaker check)
l1: asin tiny path raises FE_INEXACT | FE_UNDERFLOW Math.cpp:1312 fails at :4794
l2: atan tiny path raises nothing Math.cpp:1800 fails at :4794
l3: asin tiny path raises FE_INEXACT for zeros too Math.cpp:1312 fails at :4794
c4 with l1 both Passed (the FE_INEXACT-only mask misses the extra underflow, which the PR's mask catches)

Tests.

test main merge 1 merge 2 merge 3
guest_math Passed Passed Passed Passed

On the merge, tools/check_conventions.py --base upstream/main passes with no findings, and tools/debt_fold.py --check exits 0.

Host:

  • CPU: Ryzen 9 9950X3D
  • OS: Windows 11 Pro 26300
  • Toolchain: WinLibs GCC 15.2, Release
  • Commits: head dc3734b0c5, merged onto main 1f2e77165a as 9a36a6536d

AI-assisted: yes

@LODIBIDO

Copy link
Copy Markdown
Contributor

Confirmed on a native Intel Mac (i5-8259U, x86_64, no Rosetta, macOS 15.7.8, Apple clang 17.0.0), on main 81ff76a0c0 plus #27201:

Tree guest_math
base fails 3 of 3 at GuestMath.cpp:4919
this PR passes 5 of 5

AI-assisted: yes

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ran the submitted tiny inverse-trigonometric fixture by itself on Linux with the pinned project libraries. It passed its result-bit, errno and standard floating-point flag checks on the tiny asin and atan cases. In the broader mixed-library fixture, execution stopped earlier at an expm1l case, so the result here is for the changed check.

AI-assisted: yes.

This branch has not been deployed

No deployments
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.

7 participants