diff options
author | das <das@FreeBSD.org> | 2004-07-09 03:31:09 +0000 |
---|---|---|
committer | das <das@FreeBSD.org> | 2004-07-09 03:31:09 +0000 |
commit | 5ef7c3d0ff72cc97a9a5ed0935c3a12630e46b1b (patch) | |
tree | 2311c766ba494bef231b5ec04144f485e361a912 | |
parent | 84763ddc9b3b7797533208d1b8039e002036c017 (diff) | |
download | FreeBSD-src-5ef7c3d0ff72cc97a9a5ed0935c3a12630e46b1b.zip FreeBSD-src-5ef7c3d0ff72cc97a9a5ed0935c3a12630e46b1b.tar.gz |
Define the following macros in terms of [gi]cc builtins when the
builtins are available: HUGE_VAL, HUGE_VALF, HUGE_VALL, INFINITY,
and NAN. These macros now expand to floating-point constant
expressions rather than external references, as required by C99.
Other compilers will retain the historical behavior. Note that
it is not possible say, e.g.
#define HUGE_VAL 1.0e9999
because the above may result in diagnostics at translation time
and spurious exceptions at runtime. Hence the need for compiler
support for these features.
Also use builtins to implement the macros isgreater(),
isgreaterequal(), isless(), islessequal(), islessgreater(),
and isunordered() when such builtins are available.
Although the old macros are correct, the builtin versions
are much faster, and they avoid double-expansion problems.
-rw-r--r-- | lib/msun/src/math.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h index 2da3de7..754599e 100644 --- a/lib/msun/src/math.h +++ b/lib/msun/src/math.h @@ -34,15 +34,35 @@ extern const union __nan_un { float __uf; } __nan; +#if (defined(__GNUC__) && __GNUC__ >= 3) || defined(__INTEL_COMPILER) +#define __MATH_BUILTIN_CONSTANTS +#endif + +#if (defined(__GNUC__) && __GNUC__ >= 3) +#define __MATH_BUILTIN_RELOPS +#endif + +#ifdef __MATH_BUILTIN_CONSTANTS +#define HUGE_VAL __builtin_huge_val() +#else #define HUGE_VAL (__infinity.__ud) +#endif #if __ISO_C_VISIBLE >= 1999 #define FP_ILOGB0 (-__INT_MAX) #define FP_ILOGBNAN __INT_MAX + +#ifdef __MATH_BUILTIN_CONSTANTS +#define HUGE_VALF __builtin_huge_valf() +#define HUGE_VALL __builtin_huge_vall() +#define INFINITY __builtin_inf() +#define NAN __builtin_nan("") +#else #define HUGE_VALF (float)HUGE_VAL #define HUGE_VALL (long double)HUGE_VAL #define INFINITY HUGE_VALF #define NAN (__nan.__uf) +#endif /* __MATH_BUILTIN_CONSTANTS */ #define MATH_ERRNO 1 #define MATH_ERREXCEPT 2 @@ -64,6 +84,14 @@ extern const union __nan_un { #define isnan(x) (fpclassify(x) == FP_NAN) #define isnormal(x) (fpclassify(x) == FP_NORMAL) +#ifdef __MATH_BUILTIN_RELOPS +#define isgreater(x, y) __builtin_isgreater((x), (y)) +#define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y)) +#define isless(x, y) __builtin_isless((x), (y)) +#define islessequal(x, y) __builtin_islessequal((x), (y)) +#define islessgreater(x, y) __builtin_islessgreater((x), (y)) +#define isunordered(x, y) __builtin_isunordered((x), (y)) +#else #define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) #define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) #define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) @@ -71,6 +99,7 @@ extern const union __nan_un { #define islessgreater(x, y) (!isunordered((x), (y)) && \ ((x) > (y) || (y) > (x))) #define isunordered(x, y) (isnan(x) || isnan(y)) +#endif /* __MATH_BUILTIN_RELOPS */ #define signbit(x) __signbit(x) |