fix(libc): keep __isnan and __isnanf integer bit tests under Apple clang #22081
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22081"
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 kurexw on 2026-11-17T04:39:30Z.
What
#21161 rewrote
__isnanand__isnanf(core/libs/prx/libc/src/Math.cpp) as bit tests, so that classifying a value never raises floating-point exceptions. Apple clang 21.0.0 (clang-2100.4.1.1) at-O3sees that the two-part test (exponent all ones, mantissa nonzero) means "is NaN" and compiles it back into a floating-point compare. Inlibc.prx(otool -tvV):ucomisdraisesFE_INVALIDfor a signaling NaN, and the x87/SSE denormal flag for a subnormal input. Soguest_mathfails atGuestMath.cpp:4971(actualFlags == flags) on macOS, for__isnanand forisnan, which forwards to it.__isinf,__isfiniteand__isnormalwere already compiled to integer code.This PR writes both tests as one unsigned compare of the magnitude bits against infinity,
(bits & 0x7fff...) > 0x7ff0..., which is the same test musl uses. For every input this is equivalent to the old two-part test: the magnitude is above infinity's bit pattern exactly when the exponent is all ones and the mantissa is nonzero. Apple clang keeps it as integer code:isnanandisnanfforward to these and compile the same way. Noucomis*is left in any of the four.Tested
macOS 27.2 on an Apple M4, with Apple clang 21.0.0 for an x86-64 build under Rosetta.
guest_math: main ata72186d3cffails atGuestMath.cpp:4971. With this PR it passed in three runs out of three.guest_math_elementarypasses with this PR.guest_math_exactfails atGuestMathExact.cpp:687(expf(89)errno) on both main and this PR. That's a separate issue.otool -tvVon the rebuiltlibc.prxshows the integer code above for__isnan,__isnanf,isnanandisnanf.guest_mathwould catch that.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)🤖 Generated with Claude Code