-ffast-math and mathinlines.h
Andreas Jaeger
aj@oss.sgi.com
Mon Apr 17 11:36:00 GMT 2000
>>>>> Ulrich Drepper writes:
> I have generally no problem with this but the granularity of the patch
> is not OK. The -ffast-math flag should only enable additional
> function which really behave differently then the libm functions.
> Looking briefly through the mathinline.h file this at least excludes
> lrintf
> lrint
> lrintl
> llrintf
> llrint
> llrintl
> finite
> Perhaps
> ldexpf
> ldexp
> ldexpl
Here's a patch for mathinline and the documentation.
Jakub, could you check whether sysdeps/sparc/fpu/bits/mathinline also
needs some #ifdef __FAST_MATH__ ?
Thanks,
Andreas
2000-04-15 Andreas Jaeger <aj@suse.de>
* manual/math.texi (FP Function Optimizations): Document gcc
-ffast-math behaviour with mathinlines.
* sysdeps/i386/fpu/bits/mathinline.h: Only use save inline
functions unless -ffast-math is given to gcc.
--- libc-clean/sysdeps/i386/fpu/bits/mathinline.h Tue Mar 28 22:16:56 2000
+++ glibc-2.2/sysdeps/i386/fpu/bits/mathinline.h Sat Apr 15 20:00:22 2000
@@ -281,6 +281,8 @@
__inline_mathcode (__sgn, __x, \
return __x == 0.0 ? 0.0 : (__x > 0.0 ? 1.0 : -1.0))
+/* __FAST_MATH__ is defined by gcc -ffast-math. */
+#ifdef __FAST_MATH__
__inline_mathcode (__pow2, __x, \
register long double __value; \
register long double __exponent; \
@@ -474,7 +476,8 @@
__inline_mathopNP (sqrt, "fsqrt")
__inline_mathopNP_ (long double, __sqrtl, "fsqrt")
-
+#endif /* __FAST_MATH__ */
+
#if __GNUC_PREREQ (2, 8)
__inline_mathcodeNP_ (double, fabs, __x, return __builtin_fabs (__x))
__inline_mathcodeNP_ (float, fabsf, __x, return __builtin_fabsf (__x))
@@ -485,6 +488,7 @@
__inline_mathop_ (long double, __fabsl, "fabs")
#endif
+#ifdef __FAST_MATH__
/* The argument range of this inline version is reduced. */
__inline_mathopNP (sin, "fsin")
/* The argument range of this inline version is reduced. */
@@ -540,7 +544,8 @@
__asm __volatile ("frndint" : "=t" (__value) : "0" (__x)); \
__asm __volatile ("fldcw %0" : : "m" (__cw)); \
return __value)
-
+#endif /* __FAST_MATH__ */
+
#define __ldexp_code \
register long double __value; \
__asm __volatile__ \
@@ -557,7 +562,7 @@
/* Optimized versions for some non-standardized functions. */
#if defined __USE_ISOC99 || defined __USE_MISC
-
+#ifdef __FAST_MATH__
__inline_mathcodeNP (expm1, __x, __expm1_code)
/* We cannot rely on M_SQRT being defined. So we do it for ourself
@@ -600,11 +605,13 @@
("fxtract\n\t" \
: "=t" (__junk), "=u" (__value) : "0" (__x)); \
return __value)
-
+#endif /* __FAST_MATH__ */
#endif
#ifdef __USE_ISOC99
+#ifdef __FAST_MATH__
__inline_mathop_declNP (log2, "fld1; fxch; fyl2x", "0" (__x) : "st(1)")
+#endif /* __FAST_MATH__ */
__MATH_INLINE float
ldexpf (float __x, int __y)
@@ -618,9 +625,11 @@
__ldexp_code;
}
+#ifdef __FAST_MATH__
__inline_mathcodeNP3 (fma, __x, __y, __z, return (__x * __y) + __z)
__inline_mathopNP (rint, "frndint")
+#endif /* __FAST_MATH__ */
#define __lrint_code \
long int __lrintres; \
@@ -672,7 +681,7 @@
#ifdef __USE_MISC
-
+#ifdef __FAST_MATH__
__inline_mathcodeNP2 (drem, __x, __y, \
register double __value; \
register int __clobbered; \
@@ -683,6 +692,7 @@
"jp 1b" \
: "=t" (__value), "=&a" (__clobbered) : "0" (__x), "u" (__y) : "cc"); \
return __value)
+#endif /* __FAST_MATH__ */
/* This function is used in the `isfinite' macro. */
@@ -695,23 +705,24 @@
}
/* Miscellaneous functions */
-
+#ifdef __FAST_MATH__
__inline_mathcode (__coshm1, __x, \
register long double __exm1 = __expm1l (__fabsl (__x)); \
return 0.5 * (__exm1 / (__exm1 + 1.0)) * __exm1)
__inline_mathcode (__acosh1p, __x, \
return log1pl (__x + __sqrtl (__x) * __sqrtl (__x + 2.0)))
-
+#endif /* __FAST_MATH__ */
#endif /* __USE_MISC */
/* Undefine some of the large macros which are not used anymore. */
+#ifdef __FAST_MATH__
#undef __expm1_code
#undef __exp_code
#undef __atan2_code
#undef __sincos_code
-
-#endif /* __NO_MATH_INLINES */
+#endif /* __FAST_MATH__ */
+#endif /* __NO_MATH_INLINES && __OPTIMIZE */
/* This code is used internally in the GNU libc. */
--- libc-clean/manual/math.texi Sun Oct 31 09:19:58 1999
+++ glibc-2.2/manual/math.texi Sat Apr 15 20:09:59 2000
@@ -1770,9 +1770,10 @@
can increase the speed of generated code significantly. The drawback is
that code size will increase, and the increase is not always negligible.
-The speed increase has one drawback: the inline functions might not set
-@code{errno} and might not have the same precission as the library
-functions.
+There are two kind of inline functions: Those that give the same result
+as the library functions and others that might not set @code{errno} and
+might not have the same precission as the library functions. The latter
+are only available if the flag @code{-ffast-math} is given to GNU CC.
In cases where the inline functions and macros are not wanted the symbol
@code{__NO_MATH_INLINES} should be defined before any system header is
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.rhein-neckar.de
currently: aj@oss.sgi.com
More information about the Libc-hacker
mailing list