This is the mail archive of the mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Updated mathinline.h patch

Here's an updated patch for -ffast-math and mathinline.h.  

I'd like to test all inline functions.  We could either add
-ffast-math or -D__FAST_MATH__ for the inline test files.  I've tried
first -ffast-math and seemed to got an endless loop with the long
double functions and therefore added __FAST_MATH__ to enable all

glibc passes the testsuite with gcc 2.96 CVS current on i686.  I was
also successful with gcc 2.95.2.  The testsuite passed - but if you
run the tests with -v3, you get the segmentation fault I reported
today in printf.

Jakub, could you add some #ifdef __FAST_MATH__ to the sparc mathinline
files, please?  It seems that the sqrt functions need it.

Uli, is it ok to install this?


2000-05-22  Andreas Jaeger  <>

	* math/Makefile: Add -D__FAST_MATH__ to CFLAGS-test-ifloat.c,
	CFLAGS-test-idouble.c, CFLAGS-test-ildoubl.c.

	* 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.

Index: manual/math.texi
--- manual/math.texi	2000/04/24 01:36:42	1.60
+++ manual/math.texi	2000/05/22 18:18:17
@@ -1770,9 +1770,11 @@
 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
+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 have a reduced precision and/or argument range in comparison with
+the library functions.  The latter inline functions 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
Index: sysdeps/i386/fpu/bits/mathinline.h
--- sysdeps/i386/fpu/bits/mathinline.h	2000/05/06 07:46:06	1.39
+++ sysdeps/i386/fpu/bits/mathinline.h	2000/05/22 18:18:18
@@ -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,6 +476,7 @@
 __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))
@@ -485,6 +488,7 @@
 __inline_mathop_ (long double, __fabsl, "fabs")
+#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.  */
@@ -517,6 +521,7 @@
 __inline_mathcodeNP (tanh, __x, \
   register long double __exm1 = __expm1l (-__fabsl (__x + __x));	      \
   return __exm1 / (__exm1 + 2.0) * __sgn1l (-__x))
+#endif /* __FAST_MATH__ */
 __inline_mathcodeNP (floor, __x, \
@@ -558,6 +563,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
@@ -601,6 +607,7 @@
      : "=t" (__junk), "=u" (__value) : "0" (__x));			      \
   return __value)
+#endif /* __FAST_MATH__ */
 #ifdef __USE_ISOC99
@@ -711,10 +718,12 @@
 #endif /* __USE_MISC  */
 /* Undefine some of the large macros which are not used anymore.  */
-#undef __expm1_code
-#undef __exp_code
-#undef __atan2_code
-#undef __sincos_code
+#ifdef __FAST_MATH__
+# undef __expm1_code
+# undef __exp_code
+# undef __atan2_code
+# undef __sincos_code
+#endif /* __FAST_MATH__ */
 #endif /* __NO_MATH_INLINES  */
Index: math/Makefile
--- math/Makefile	2000/05/02 13:52:36	1.95
+++ math/Makefile	2000/05/22 18:18:18
@@ -116,9 +116,9 @@
 CFLAGS-test-float.c = -fno-inline -ffloat-store
 CFLAGS-test-double.c = -fno-inline -ffloat-store
 CFLAGS-test-ldouble.c = -fno-inline -ffloat-store
 LDLIBS-test-ifloat = math/libm
 LDLIBS-test-idouble = math/libm
 LDLIBS-test-ildoubl = math/libm

 Andreas Jaeger
  SuSE Labs

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]