From dda1013cdb4781c4d2625a45ff9d84983e9eec86 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 4 Jan 2020 20:09:24 -0500 Subject: [PATCH] posix/math: Use the GCC built-ins when possible for isnan(), etc. glibc does the same. Technically, some of these builtins did not exist / did not work before GCC 4.4, but the source tree cannot be compiled with a version that old anyway. x86_64 and _x86 need to keep the old functions for now, of course; but all other architectures can probably feel free to drop the s_isnan, etc. functions from their glibc. This will make upcoming patches easier... Change-Id: Ifb76ea74076553228c9741a8ee3ecb0e1cf736a3 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2076 Reviewed-by: waddlesplash --- headers/posix/math.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/headers/posix/math.h b/headers/posix/math.h index d094d0e970..a4bb33ef1f 100644 --- a/headers/posix/math.h +++ b/headers/posix/math.h @@ -338,7 +338,15 @@ extern float y1f(float x); extern float ynf(int x, float y); extern float lgammaf_r(float x, int *y); - +#if __GNUC__ >= 7 || defined(__clang__) +#define fpclassify(value) \ + __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, (value)) +#define signbit(value) __builtin_signbit((value)) +#define isfinite(value) __builtin_isfinite((value)) +#define isnormal(value) __builtin_isnormal((value)) +#define isnan(value) __builtin_isnan((value)) +#define isinf(value) __builtin_isinf_sign((value)) +#else /* prototypes for functions used in the macros below */ extern int __fpclassifyf(float value); extern int __signbitf(float value); @@ -391,6 +399,7 @@ extern int __isinf(double value); (sizeof(value) == sizeof(float) ? __isinff(value) \ : sizeof(value) == sizeof(double) ? __isinf(value) \ : __isinfl(value)) +#endif #if __GNUC__ >= 4 #define isgreater(x, y) __builtin_isgreater((x), (y))