This is the mail archive of the libc-hacker@sourceware.cygnus.com 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]

-ffast-math and mathinlines.h



<bits/mathinlines.h> on ix86 contains a number of inline functions
which are either inaccurate or don't set errno.  gcc has a special
flag for this case, it's called -ffast-math.  The documentation is:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@item -ffast-math
This option allows GCC to violate some ANSI or IEEE rules and/or
specifications in the interest of optimizing code for speed.  For
example, it allows the compiler to assume arguments to the @code{sqrt}
function are non-negative numbers and that no floating-point values
are NaNs.

This option should never be turned on by any @samp{-O} option since
it can result in incorrect output for programs which depend on
an exact implementation of IEEE or ANSI rules/specifications for
math functions.

@item -fno-math-errno
Do not set ERRNO after calling math functions that are executed
with a single instruction, e.g., sqrt.  A program that relies on
IEEE exceptions for math error handling may want to use this flag
for speed while maintaining IEEE arithmetic compatibility.

The default is @samp{-fmath-errno}.  The @samp{-ffast-math} option
sets @samp{-fno-math-errno}.
@end table
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

gcc defines __FAST_MATH__ if -ffast-math is set.  IMO we should add a
check in <bits/mathinline.h> and only enable the inline instructions
if __FAST_MATH__ is set.

Here's a patch for glibc 2.2 - the patch shouldn't go into glibc 2.1
since we're changing the behaviour.  I'm not sure it the patch is
correct with regard of my change of __LIBC_INTERNAL_MATH_INLINES

I don't know what kind of inline functions other architectures use -
if those are violating IEEE/ISO C, we should use __FAST_MATH__ there
also.

Andreas

2000-04-12  Andreas Jaeger  <aj@suse.de>

	* sysdeps/i386/fpu/bits/mathinline.h: Define inline functions only
	if -ffast-math is given.

============================================================
Index: sysdeps/i386/fpu/bits/mathinline.h
--- sysdeps/i386/fpu/bits/mathinline.h	2000/03/29 03:45:53	1.38
+++ sysdeps/i386/fpu/bits/mathinline.h	2000/04/12 21:06:18
@@ -141,7 +141,7 @@
 #if __GNUC_PREREQ (2, 8)
 
 #if ((!defined __NO_MATH_INLINES || defined __LIBC_INTERNAL_MATH_INLINES) \
-     && defined __OPTIMIZE__)
+     && defined __OPTIMIZE__  && defined __FAST_MATH__)
 
 /* A macro to define float, double, and long double versions of various
    math functions for the ix87 FPU.  FUNC is the function name (which will
@@ -275,7 +275,7 @@
 #endif
 
 
-#if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
+#if !defined __NO_MATH_INLINES && defined __OPTIMIZE__ && defined __FAST_MATH__
 /* Miscellaneous functions */
 
 __inline_mathcode (__sgn, __x, \
@@ -711,11 +711,11 @@
 #undef __atan2_code
 #undef __sincos_code
 
-#endif /* __NO_MATH_INLINES  */
+#endif /* __NO_MATH_INLINES  && __OPTIMIZE && __FAST_MATH__  */
 
 
 /* This code is used internally in the GNU libc.  */
-#ifdef __LIBC_INTERNAL_MATH_INLINES
+#if defined __LIBC_INTERNAL_MATH_INLINES  && defined __FAST_MATH__
 __inline_mathop (__ieee754_sqrt, "fsqrt")
 __inline_mathcode2 (__ieee754_atan2, __y, __x,
 		    register long double __value;
-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.rhein-neckar.de
    currently: aj@oss.sgi.com

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