This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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] aarch64: fabs and sqrt implementation with inline asm


the c code for fabs and sqrt are inefficient and aarch64
always has the single instructions available for them.

(this fix is useful when c code is compiled with -fno-builtin
like newlib itself).

2015-05-20  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* libm/machine/aarch64/e_sqrt.c: New file.
	* libm/machine/aarch64/ef_sqrt.c: New file.
	* libm/machine/aarch64/s_fabs.c: New file.
	* libm/machine/aarch64/sf_fabs.c: New file.
	* libm/machine/aarch64/Makefile.in: Add new source files.
	* libm/machine/aarch64/Makefile.am: Regenerate.
diff --git a/newlib/libm/machine/aarch64/Makefile.am b/newlib/libm/machine/aarch64/Makefile.am
index 22706a9..752f65d 100644
--- a/newlib/libm/machine/aarch64/Makefile.am
+++ b/newlib/libm/machine/aarch64/Makefile.am
@@ -6,7 +6,10 @@ INCLUDES = -I $(newlib_basedir)/../newlib/libm/common $(NEWLIB_CFLAGS) \
 	$(CROSS_CFLAGS) $(TARGET_CFLAGS)
 
 LIB_SOURCES = \
+	e_sqrt.c \
+	ef_sqrt.c \
 	s_ceil.c \
+	s_fabs.c \
 	s_floor.c \
 	s_fma.c \
 	s_fmax.c \
@@ -20,6 +23,7 @@ LIB_SOURCES = \
 	s_round.c \
 	s_trunc.c \
 	sf_ceil.c \
+	sf_fabs.c \
 	sf_floor.c \
 	sf_fma.c \
 	sf_fmax.c \
diff --git a/newlib/libm/machine/aarch64/Makefile.in b/newlib/libm/machine/aarch64/Makefile.in
index 0e74c75..6b5c360 100644
--- a/newlib/libm/machine/aarch64/Makefile.in
+++ b/newlib/libm/machine/aarch64/Makefile.in
@@ -70,13 +70,15 @@ LIBRARIES = $(noinst_LIBRARIES)
 ARFLAGS = cru
 lib_a_AR = $(AR) $(ARFLAGS)
 lib_a_LIBADD =
-am__objects_1 = lib_a-s_ceil.$(OBJEXT) lib_a-s_floor.$(OBJEXT) \
-	lib_a-s_fma.$(OBJEXT) lib_a-s_fmax.$(OBJEXT) \
-	lib_a-s_fmin.$(OBJEXT) lib_a-s_llrint.$(OBJEXT) \
-	lib_a-s_llround.$(OBJEXT) lib_a-s_lrint.$(OBJEXT) \
-	lib_a-s_lround.$(OBJEXT) lib_a-s_nearbyint.$(OBJEXT) \
-	lib_a-s_rint.$(OBJEXT) lib_a-s_round.$(OBJEXT) \
-	lib_a-s_trunc.$(OBJEXT) lib_a-sf_ceil.$(OBJEXT) \
+am__objects_1 = lib_a-e_sqrt.$(OBJEXT) lib_a-ef_sqrt.$(OBJEXT) \
+	lib_a-s_ceil.$(OBJEXT) lib_a-s_fabs.$(OBJEXT) \
+	lib_a-s_floor.$(OBJEXT) lib_a-s_fma.$(OBJEXT) \
+	lib_a-s_fmax.$(OBJEXT) lib_a-s_fmin.$(OBJEXT) \
+	lib_a-s_llrint.$(OBJEXT) lib_a-s_llround.$(OBJEXT) \
+	lib_a-s_lrint.$(OBJEXT) lib_a-s_lround.$(OBJEXT) \
+	lib_a-s_nearbyint.$(OBJEXT) lib_a-s_rint.$(OBJEXT) \
+	lib_a-s_round.$(OBJEXT) lib_a-s_trunc.$(OBJEXT) \
+	lib_a-sf_ceil.$(OBJEXT) lib_a-sf_fabs.$(OBJEXT) \
 	lib_a-sf_floor.$(OBJEXT) lib_a-sf_fma.$(OBJEXT) \
 	lib_a-sf_fmax.$(OBJEXT) lib_a-sf_fmin.$(OBJEXT) \
 	lib_a-sf_llrint.$(OBJEXT) lib_a-sf_llround.$(OBJEXT) \
@@ -209,7 +211,10 @@ INCLUDES = -I $(newlib_basedir)/../newlib/libm/common $(NEWLIB_CFLAGS) \
 	$(CROSS_CFLAGS) $(TARGET_CFLAGS)
 
 LIB_SOURCES = \
+	e_sqrt.c \
+	ef_sqrt.c \
 	s_ceil.c \
+	s_fabs.c \
 	s_floor.c \
 	s_fma.c \
 	s_fmax.c \
@@ -223,6 +228,7 @@ LIB_SOURCES = \
 	s_round.c \
 	s_trunc.c \
 	sf_ceil.c \
+	sf_fabs.c \
 	sf_floor.c \
 	sf_fma.c \
 	sf_fmax.c \
@@ -302,12 +308,30 @@ distclean-compile:
 .c.obj:
 	$(COMPILE) -c `$(CYGPATH_W) '$<'`
 
+lib_a-e_sqrt.o: e_sqrt.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-e_sqrt.o `test -f 'e_sqrt.c' || echo '$(srcdir)/'`e_sqrt.c
+
+lib_a-e_sqrt.obj: e_sqrt.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-e_sqrt.obj `if test -f 'e_sqrt.c'; then $(CYGPATH_W) 'e_sqrt.c'; else $(CYGPATH_W) '$(srcdir)/e_sqrt.c'; fi`
+
+lib_a-ef_sqrt.o: ef_sqrt.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ef_sqrt.o `test -f 'ef_sqrt.c' || echo '$(srcdir)/'`ef_sqrt.c
+
+lib_a-ef_sqrt.obj: ef_sqrt.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ef_sqrt.obj `if test -f 'ef_sqrt.c'; then $(CYGPATH_W) 'ef_sqrt.c'; else $(CYGPATH_W) '$(srcdir)/ef_sqrt.c'; fi`
+
 lib_a-s_ceil.o: s_ceil.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_ceil.o `test -f 's_ceil.c' || echo '$(srcdir)/'`s_ceil.c
 
 lib_a-s_ceil.obj: s_ceil.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_ceil.obj `if test -f 's_ceil.c'; then $(CYGPATH_W) 's_ceil.c'; else $(CYGPATH_W) '$(srcdir)/s_ceil.c'; fi`
 
+lib_a-s_fabs.o: s_fabs.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fabs.o `test -f 's_fabs.c' || echo '$(srcdir)/'`s_fabs.c
+
+lib_a-s_fabs.obj: s_fabs.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fabs.obj `if test -f 's_fabs.c'; then $(CYGPATH_W) 's_fabs.c'; else $(CYGPATH_W) '$(srcdir)/s_fabs.c'; fi`
+
 lib_a-s_floor.o: s_floor.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_floor.o `test -f 's_floor.c' || echo '$(srcdir)/'`s_floor.c
 
@@ -386,6 +410,12 @@ lib_a-sf_ceil.o: sf_ceil.c
 lib_a-sf_ceil.obj: sf_ceil.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_ceil.obj `if test -f 'sf_ceil.c'; then $(CYGPATH_W) 'sf_ceil.c'; else $(CYGPATH_W) '$(srcdir)/sf_ceil.c'; fi`
 
+lib_a-sf_fabs.o: sf_fabs.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_fabs.o `test -f 'sf_fabs.c' || echo '$(srcdir)/'`sf_fabs.c
+
+lib_a-sf_fabs.obj: sf_fabs.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_fabs.obj `if test -f 'sf_fabs.c'; then $(CYGPATH_W) 'sf_fabs.c'; else $(CYGPATH_W) '$(srcdir)/sf_fabs.c'; fi`
+
 lib_a-sf_floor.o: sf_floor.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sf_floor.o `test -f 'sf_floor.c' || echo '$(srcdir)/'`sf_floor.c
 
diff --git a/newlib/libm/machine/aarch64/e_sqrt.c b/newlib/libm/machine/aarch64/e_sqrt.c
new file mode 100644
index 0000000..e4b7554
--- /dev/null
+++ b/newlib/libm/machine/aarch64/e_sqrt.c
@@ -0,0 +1,35 @@
+/* e_sqrt.c -- define __ieee754_sqrt
+   Copyright (c) 2015 ARM Ltd.  All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   1. Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+   2. Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+   3. The name of the company may not be used to endorse or promote
+      products derived from this software without specific prior written
+      permission.
+
+   THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+   IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <math.h>
+
+double
+__ieee754_sqrt (double x)
+{
+  double result;
+  asm ("fsqrt\t%d0, %d1" : "=w" (result) : "w" (x));
+  return result;
+}
diff --git a/newlib/libm/machine/aarch64/ef_sqrt.c b/newlib/libm/machine/aarch64/ef_sqrt.c
new file mode 100644
index 0000000..19fec95
--- /dev/null
+++ b/newlib/libm/machine/aarch64/ef_sqrt.c
@@ -0,0 +1,35 @@
+/* ef_sqrt.c -- define __ieee754_sqrtf
+   Copyright (c) 2015 ARM Ltd.  All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   1. Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+   2. Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+   3. The name of the company may not be used to endorse or promote
+      products derived from this software without specific prior written
+      permission.
+
+   THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+   IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <math.h>
+
+float
+__ieee754_sqrtf (float x)
+{
+  float result;
+  asm ("fsqrt\t%s0, %s1" : "=w" (result) : "w" (x));
+  return result;
+}
diff --git a/newlib/libm/machine/aarch64/s_fabs.c b/newlib/libm/machine/aarch64/s_fabs.c
new file mode 100644
index 0000000..60e95ce
--- /dev/null
+++ b/newlib/libm/machine/aarch64/s_fabs.c
@@ -0,0 +1,35 @@
+/* s_fabs.c -- define fabs
+   Copyright (c) 2015 ARM Ltd.  All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   1. Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+   2. Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+   3. The name of the company may not be used to endorse or promote
+      products derived from this software without specific prior written
+      permission.
+
+   THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+   IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <math.h>
+
+double
+fabs (double x)
+{
+  double result;
+  asm ("fabs\t%d0, %d1" : "=w" (result) : "w" (x));
+  return result;
+}
diff --git a/newlib/libm/machine/aarch64/sf_fabs.c b/newlib/libm/machine/aarch64/sf_fabs.c
new file mode 100644
index 0000000..2b92546
--- /dev/null
+++ b/newlib/libm/machine/aarch64/sf_fabs.c
@@ -0,0 +1,35 @@
+/* sf_fabs.c -- define fabsf
+   Copyright (c) 2015 ARM Ltd.  All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   1. Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+   2. Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+   3. The name of the company may not be used to endorse or promote
+      products derived from this software without specific prior written
+      permission.
+
+   THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+   IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <math.h>
+
+float
+fabsf (float x)
+{
+  float result;
+  asm ("fabs\t%s0, %s1" : "=w" (result) : "w" (x));
+  return result;
+}

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