[1/3] Cleanup __ieee754_sqrt(f/l)
Commit Message
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.
--
Comments
On Tue, 26 Sep 2017, Wilco Dijkstra wrote:
> 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.
I don't think these patches are reviewable without each patch including a
description of how it was tested. Appropriate testing might be a full
build-many-glibcs.py run for each patch in the series (but at least, you
need to include testing for at least one configuration where these
functions are not inlined, and at least one configuration with float128
support).
> * math/Makefile: Add -fno-math-errno, but build tests
> with -fmath-errno.
This seems extremely fragile. It looks like it's relying on options added
with one variable coming after options added with another, which is a
matter of implementation details of how the compilation commands are built
up from different variables.
I think there should be a single variable variable that adds the required
option in every case - always at most one of -fmath-errno and
-fno-math-errno, with no file ever getting both - probably based on
$(in-module), and that should then be used at top level alongside
-frounding-math, rather than only in the math/ directory.
@@ -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
@@ -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
@@ -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>
@@ -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>
@@ -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>
@@ -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>