This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Bypass math wrappers with -fno-math-errno


Several math functions have wrappers which handle errno.  They are
bypassed if __FINITE_MATH_ONLY__ is set.  Given the wrappers impose
a significant overhead, bypassing them is worthwhile (and it is best
to remove them completely in the future).

Since the only purpose of the wrappers is to set errno, we can bypass
them if __NO_MATH_ERRNO__ is set as well.  There are a few target specific
functions which define finite variants of math functions and those do not
set exceptions.  In those cases it would be incorrect to bypass the wrapper
unless __FINITE_MATH_ONLY__ is set.  To support this add a define that
allows targets to disable this.  It's currently set for x86 and x86_64 
due to defining several x87 math functions which only support finite math.

OK for commit?

ChangeLog:
2017-11-08  Wilco Dijkstra  <wdijkstr@arm.com>

	* math/math.h (math_errhandling): Bypass errno wrappers if
	__NO_MATH_ERRNO__ is defined, unless HAS_FINITE_MATH_FUNCTIONS is defined.
	* sysdeps/x86/fpu/bits/mathinline.h (HAS_FINITE_MATH_FUNCTIONS): Define.
--

diff --git a/math/math.h b/math/math.h
index d46c26533eff01dfbcee8f59d022febdbdb8d769..26a985728ec86fa4302455a98bf3326afc901b37 100644
--- a/math/math.h
+++ b/math/math.h
@@ -709,8 +709,9 @@ iszero (__T __val)
 #endif
 
 /* Define special entry points to use when the compiler got told to
-   only expect finite results.  */
-#if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
+   only expect finite results or errno is not used.  */
+#if (defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0) \
+    || (defined __NO_MATH_ERRNO__ && !defined HAS_FINITE_MATH_FUNCTIONS)
 
 /* Include bits/math-finite.h for double.  */
 # define _Mdouble_ double
diff --git a/sysdeps/x86/fpu/bits/mathinline.h b/sysdeps/x86/fpu/bits/mathinline.h
index cf29751a2781d11cd835b2e8213443b52d84f10f..973a3603240a37459baf49f341c5c294377c3bf7 100644
--- a/sysdeps/x86/fpu/bits/mathinline.h
+++ b/sysdeps/x86/fpu/bits/mathinline.h
@@ -20,6 +20,10 @@
 # error "Never use <bits/mathinline.h> directly; include <math.h> instead."
 #endif
 
+/* Some math functions have finite variants which do not support exceptions,
+   so we may use the finite variant only with __FINITE_MATH_ONLY__.  */
+#define HAS_FINITE_MATH_FUNCTIONS 1
+
 #ifndef __extern_always_inline
 # define __MATH_INLINE __inline
 #else


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