5f7b84
commit 4997e8f31e7415652c3dedec672c0e9bf8caa9ca
5f7b84
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
5f7b84
Date:   Fri Feb 1 10:39:57 2019 -0200
5f7b84
5f7b84
    math: Enable some math builtins for clang
5f7b84
    
5f7b84
    This patch enable the builtin usage for clang for the C99 functions
5f7b84
    fpclassify, isfinite, isnormal, isnan, isinf, and sigbit.  This allows
5f7b84
    clang optimize the calls on frontend instead of call the appropriate
5f7b84
    glibc symbols.
5f7b84
    
5f7b84
    Checked on aarch64-linux-gnu and x86_64-linux-gnu. I checked the supported
5f7b84
    version for each builtin based on released version from clang/llvm.
5f7b84
    
5f7b84
            * math/math.h (fpclassify, isfinite, isnormal, isnan): Use builtin for
5f7b84
            clang 2.8.
5f7b84
            (signbit): Use builtin for clang 3.3.
5f7b84
            (isinf): Use builtin for clang 3.7.
5f7b84
5f7b84
diff --git a/math/math.h b/math/math.h
5f7b84
index ddee4e408389722f..b3b414f3678e91f7 100644
5f7b84
--- a/math/math.h
5f7b84
+++ b/math/math.h
5f7b84
@@ -874,7 +874,8 @@ enum
5f7b84
    the __SUPPORT_SNAN__ check may be skipped for those versions.  */
5f7b84
 
5f7b84
 /* Return number of classification appropriate for X.  */
5f7b84
-# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__			      \
5f7b84
+# if ((__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__)		      \
5f7b84
+      || __glibc_clang_prereq (2,8))					      \
5f7b84
      && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus)
5f7b84
      /* The check for __cplusplus allows the use of the builtin, even
5f7b84
 	when optimization for size is on.  This is provided for
5f7b84
@@ -889,7 +890,7 @@ enum
5f7b84
 # endif
5f7b84
 
5f7b84
 /* Return nonzero value if sign of X is negative.  */
5f7b84
-# if __GNUC_PREREQ (6,0)
5f7b84
+# if __GNUC_PREREQ (6,0) || __glibc_clang_prereq (3,3)
5f7b84
 #  define signbit(x) __builtin_signbit (x)
5f7b84
 # elif defined __cplusplus
5f7b84
   /* In C++ mode, __MATH_TG cannot be used, because it relies on
5f7b84
@@ -907,14 +908,16 @@ enum
5f7b84
 # endif
5f7b84
 
5f7b84
 /* Return nonzero value if X is not +-Inf or NaN.  */
5f7b84
-# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
5f7b84
+# if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
5f7b84
+     || __glibc_clang_prereq (2,8)
5f7b84
 #  define isfinite(x) __builtin_isfinite (x)
5f7b84
 # else
5f7b84
 #  define isfinite(x) __MATH_TG ((x), __finite, (x))
5f7b84
 # endif
5f7b84
 
5f7b84
 /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN.  */
5f7b84
-# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
5f7b84
+# if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
5f7b84
+     || __glibc_clang_prereq (2,8)
5f7b84
 #  define isnormal(x) __builtin_isnormal (x)
5f7b84
 # else
5f7b84
 #  define isnormal(x) (fpclassify (x) == FP_NORMAL)
5f7b84
@@ -922,7 +925,8 @@ enum
5f7b84
 
5f7b84
 /* Return nonzero value if X is a NaN.  We could use `fpclassify' but
5f7b84
    we already have this functions `__isnan' and it is faster.  */
5f7b84
-# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
5f7b84
+# if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
5f7b84
+     || __glibc_clang_prereq (2,8)
5f7b84
 #  define isnan(x) __builtin_isnan (x)
5f7b84
 # else
5f7b84
 #  define isnan(x) __MATH_TG ((x), __isnan, (x))
5f7b84
@@ -939,7 +943,8 @@ enum
5f7b84
 #  define isinf(x) \
5f7b84
     (__builtin_types_compatible_p (__typeof (x), _Float128) \
5f7b84
      ? __isinff128 (x) : __builtin_isinf_sign (x))
5f7b84
-# elif __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
5f7b84
+# elif (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
5f7b84
+       || __glibc_clang_prereq (3,7)
5f7b84
 #  define isinf(x) __builtin_isinf_sign (x)
5f7b84
 # else
5f7b84
 #  define isinf(x) __MATH_TG ((x), __isinf, (x))