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 1/3] Cleanup __ieee754_sqrt(f/l)


This patch series cleans up the many uses of  __ieee754_sqrt(f/l) in GLIBC.
The goal is to enable GCC to do the inlining, and if this fails call the
__ieee754_sqrt function.  This is done by internally declaring sqrt with asm
redirects.  The compat symbols and sqrt wrappers need to disable the redirect.

This means targets are no longer forced to add a special inline for sqrt.

All math functions (but not math tests) are built with -fno-math-errno which
means GCC will inline sqrt as a single instruction.


ChangeLog:
2017-09-25  Wilco Dijkstra  <wdijkstr@arm.com>

        * include/math.h (sqrt): Declare with asm redirect.
        (sqrtf): Likewise.
        (sqrtl): Likewise.
        * math/Makefile: Add -fno-math-errno, but build tests
        with -fmath-errno.
        * math/w_sqrt_compat.c: Define NO_SQRT_REDIRECT.
        * math/w_sqrt_template.c: Likewise.
        * math/w_sqrtf_compat.c: Likewise.
        * math/w_sqrtl_compat.c: Likewise.
--
diff --git a/include/math.h b/include/math.h
index fe3ed1378d19faf572b48347b41501d9ec0925b5..e176b090caa9f07c226aff0f9c6c5bf34740f2ec 100644
--- a/include/math.h
+++ b/include/math.h
@@ -55,5 +55,15 @@ libm_hidden_proto (__expf128)
 libm_hidden_proto (__expm1f128)
 # endif
 
+# ifndef NO_SQRT_REDIRECT
+/* Declare sqrt for use within GLIBC.  Sqrt will typically inline into a
+   single instruction.  Use an asm to avoid use of PLTs if it doesn't.  */
+float sqrtf (float) asm ("__ieee754_sqrtf");
+double sqrt (double) asm ("__ieee754_sqrt");
+#  ifndef __NO_LONG_DOUBLE_MATH
+long double sqrtl (long double) asm ("__ieee754_sqrtl");
+#  endif
+# endif
+
 #endif
 #endif
diff --git a/math/Makefile b/math/Makefile
index 04586156f8050222b2aedcebc30dab7153a1b6b1..ad65dd7677dd3c6a91fb2f393e5ca43769f3ddec 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -500,6 +500,12 @@ endef
 object-suffixes-left := $(types)
 include $(o-iterator)
 
+define o-iterator-doit
+$(objpfx)$(o).o: CFLAGS += -fmath-errno
+endef
+object-suffixes-left := $(tests) $(tests-internal)
+include $(o-iterator)
+
 # Run the math programs to automatically generate ULPs files.
 .PHONY: regen-ulps
 
@@ -547,6 +553,8 @@ include $(o-iterator)
 # only the fdlibm code.
 math-CPPFLAGS += -D__NO_MATH_INLINES -D__LIBC_INTERNAL_MATH_INLINES
 
+config-extra-cflags += -fno-math-errno
+
 ifneq ($(long-double-fcts),yes)
 # The `double' and `long double' types are the same on this machine.
 # We won't compile the `long double' code at all.  Tell the `double' code
diff --git a/math/w_sqrt_compat.c b/math/w_sqrt_compat.c
index 3280d2fbb86af2aeaf6e686fd38579b209c901aa..fe068af9597ffb0f15b32cd454b4c34ba8bc060e 100644
--- a/math/w_sqrt_compat.c
+++ b/math/w_sqrt_compat.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define NO_SQRT_REDIRECT
 #include <math.h>
 #include <math_private.h>
 #include <math-svid-compat.h>
diff --git a/math/w_sqrt_template.c b/math/w_sqrt_template.c
index 5fae302382d10e9b05df2665c9cb05126cd62f02..235c263e60c85422e41bca7c817148b66030438f 100644
--- a/math/w_sqrt_template.c
+++ b/math/w_sqrt_template.c
@@ -21,6 +21,7 @@
    for each floating-point type.  */
 #if __USE_WRAPPER_TEMPLATE
 
+#define NO_SQRT_REDIRECT
 # include <errno.h>
 # include <fenv.h>
 # include <math.h>
diff --git a/math/w_sqrtf_compat.c b/math/w_sqrtf_compat.c
index 6c8c7e3857c7dacf52de6b575a2386095688b5dc..880be0936d9a20f9aa75cf2d66000f0c621f090f 100644
--- a/math/w_sqrtf_compat.c
+++ b/math/w_sqrtf_compat.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define NO_SQRT_REDIRECT
 #include <math.h>
 #include <math_private.h>
 #include <math-svid-compat.h>
diff --git a/math/w_sqrtl_compat.c b/math/w_sqrtl_compat.c
index 0590f6d155fee27d41bfd42c1dbdf19c381ba1c8..bff77fd31bf2c62394e0d54e6b2e7bc9296226d6 100644
--- a/math/w_sqrtl_compat.c
+++ b/math/w_sqrtl_compat.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define NO_SQRT_REDIRECT
 #include <math.h>
 #include <math_private.h>
 #include <math-svid-compat.h>


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