[v3,2/3] math: let architectures classify without comparing

Message ID 20260911233517.2113403-2-mattst88@gmail.com (mailing list archive)
State Under Review
Delegated to: Adhemerval Zanella Netto
Headers
Series [v3,1/3] math: move the classification macros to bits/fpclassify.h |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed

Commit Message

Matt Turner Sept. 11, 2026, 11:35 p.m. UTC
  A <bits/fpclassify.h> that defines __MATH_CLASSIFY_NO_COMPARE to 1 says that
comparisons cannot classify a value on this machine.  The generic header
defines it to 0.  iszero is the one classification macro not defined in that
header, since it needs no compiler builtin, so define it in terms of
fpclassify there, as is already done for -fsignaling-nans.
---
v3: Define __MATH_CLASSIFY_NO_COMPARE to 0 in the generic header and test
    its value, rather than testing whether it is defined.

 bits/fpclassify.h | 5 +++++
 math/math.h       | 7 ++++---
 2 files changed, 9 insertions(+), 3 deletions(-)
  

Patch

diff --git ./bits/fpclassify.h ./bits/fpclassify.h
index 939bbb8a81..5ccad0ee9d 100644
--- ./bits/fpclassify.h
+++ ./bits/fpclassify.h
@@ -20,6 +20,11 @@ 
 # error "Never use <bits/fpclassify.h> directly; include <math.h> instead."
 #endif
 
+/* Machines where a floating-point comparison cannot classify a value
+   define this to 1 in their own <bits/fpclassify.h> and define the
+   classification macros without comparing.  */
+#define __MATH_CLASSIFY_NO_COMPARE 0
+
 /* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan,
    so disable builtins if this is enabled.  When fixed in a newer GCC,
    the __SUPPORT_SNAN__ check may be skipped for those versions.  */
diff --git ./math/math.h ./math/math.h
index 0926b418a5..7d52735ced 100644
--- ./math/math.h
+++ ./math/math.h
@@ -1162,16 +1162,17 @@  inline int issignaling (_Float128 __val) { return __issignalingf128 (__val); }
 /* Return nonzero value if X is subnormal.  */
 # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
 
-/* Return nonzero value if X is zero.  */
+/* Return nonzero value if X is zero.  Machines that define
+   __MATH_CLASSIFY_NO_COMPARE to 1 cannot classify by comparing.  */
 # ifndef __cplusplus
-#  ifdef __SUPPORT_SNAN__
+#  if defined __SUPPORT_SNAN__ || __MATH_CLASSIFY_NO_COMPARE
 #   define iszero(x) (fpclassify (x) == FP_ZERO)
 #  else
 #   define iszero(x) (((__typeof (x)) (x)) == 0)
 #  endif
 # else	/* __cplusplus */
 extern "C++" {
-#  ifdef __SUPPORT_SNAN__
+#  if defined __SUPPORT_SNAN__ || __MATH_CLASSIFY_NO_COMPARE
 inline int
 iszero (float __val)
 {