Skip to content

Commit 367716f

Browse files
fo40225mr-c
authored andcommitted
math: use fpclassify for isinf on PowerPC to avoid QEMU xststdcsp bug
On PowerPC, avoid __builtin_isinf/__builtin_isinff — QEMU incorrectly emulates the xststdcsp instruction used by GCC 15+ for these builtins, causing subnormal floats to be misclassified as infinity. fpclassify() is immune to this bug on all GCC/QEMU versions.
1 parent c7e9883 commit 367716f

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

simde/simde-math.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ SIMDE_DISABLE_UNWANTED_DIAGNOSTICS
286286
/*** Classification macros from C99 ***/
287287

288288
#if !defined(simde_math_isinf)
289-
#if SIMDE_MATH_BUILTIN_LIBM(isinf)
289+
#if defined(SIMDE_ARCH_POWER) && defined(FP_INFINITE)
290+
#define simde_math_isinf(v) (fpclassify(v) == FP_INFINITE)
291+
#elif defined(SIMDE_ARCH_POWER) && defined(SIMDE_MATH_HAVE_CMATH)
292+
#define simde_math_isinf(v) (std::fpclassify(v) == FP_INFINITE)
293+
#elif SIMDE_MATH_BUILTIN_LIBM(isinf)
290294
#define simde_math_isinf(v) __builtin_isinf(v)
291295
#elif defined(isinf) || defined(SIMDE_MATH_HAVE_MATH_H)
292296
#define simde_math_isinf(v) isinf(v)
@@ -296,7 +300,11 @@ SIMDE_DISABLE_UNWANTED_DIAGNOSTICS
296300
#endif
297301

298302
#if !defined(simde_math_isinff)
299-
#if HEDLEY_HAS_BUILTIN(__builtin_isinff) || \
303+
#if defined(SIMDE_ARCH_POWER) && defined(FP_INFINITE)
304+
#define simde_math_isinff(v) (fpclassify(v) == FP_INFINITE)
305+
#elif defined(SIMDE_ARCH_POWER) && defined(SIMDE_MATH_HAVE_CMATH)
306+
#define simde_math_isinff(v) (std::fpclassify(v) == FP_INFINITE)
307+
#elif HEDLEY_HAS_BUILTIN(__builtin_isinff) || \
300308
HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
301309
HEDLEY_ARM_VERSION_CHECK(4,1,0)
302310
#define simde_math_isinff(v) __builtin_isinff(v)

0 commit comments

Comments
 (0)