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] Add rawmemchr


Add a simple rawmemchr implementation. Use strlen for rawmemchr(s, '\0') as it is the 
fastest way to search for '\0', and use memchr with an infinite size for other cases.
This is 3x faster for large sizes.

ChangeLog:
2016-04-22  Wilco Dijkstra  <wdijkstr@arm.com>

	* newlib/libc/machine/aarch64/Makefile.in: Add rawmemchr.S and
	rawmemchr-stub.c.
	* newlib/libc/machine/aarch64/Makefile.am: Likewise.
	* newlib/libc/machine/aarch64/rawmemchr.S (rawmemchr): Add rawmemchr.
	* newlib/libc/machine/aarch64/rawmemchr-stub.c (rawmemchr): Likewise.

---
 newlib/libc/machine/aarch64/Makefile.am      |  2 +
 newlib/libc/machine/aarch64/Makefile.in      | 19 +++++++-
 newlib/libc/machine/aarch64/rawmemchr-stub.c | 31 +++++++++++++
 newlib/libc/machine/aarch64/rawmemchr.S      | 68 ++++++++++++++++++++++++++++
 4 files changed, 118 insertions(+), 2 deletions(-)
 create mode 100644 newlib/libc/machine/aarch64/rawmemchr-stub.c
 create mode 100644 newlib/libc/machine/aarch64/rawmemchr.S

diff --git a/newlib/libc/machine/aarch64/Makefile.am b/newlib/libc/machine/aarch64/Makefile.am
index e2a577c..e8b8197 100644
--- a/newlib/libc/machine/aarch64/Makefile.am
+++ b/newlib/libc/machine/aarch64/Makefile.am
@@ -19,6 +19,8 @@ lib_a_SOURCES += memmove-stub.c
 lib_a_SOURCES += memmove.S
 lib_a_SOURCES += memset-stub.c
 lib_a_SOURCES += memset.S
+lib_a_SOURCES += rawmemchr.S
+lib_a_SOURCES += rawmemchr-stub.c
 lib_a_SOURCES += setjmp.S
 lib_a_SOURCES += stpcpy-stub.c
 lib_a_SOURCES += stpcpy.S
diff --git a/newlib/libc/machine/aarch64/Makefile.in b/newlib/libc/machine/aarch64/Makefile.in
index eb7087f..c512911 100644
--- a/newlib/libc/machine/aarch64/Makefile.in
+++ b/newlib/libc/machine/aarch64/Makefile.in
@@ -83,7 +83,8 @@ am_lib_a_OBJECTS = lib_a-memchr-stub.$(OBJEXT) lib_a-memchr.$(OBJEXT) \
 	lib_a-strlen.$(OBJEXT) lib_a-strncmp-stub.$(OBJEXT) \
 	lib_a-strncmp.$(OBJEXT) lib_a-strnlen-stub.$(OBJEXT) \
 	lib_a-strnlen.$(OBJEXT) lib_a-strrchr-stub.$(OBJEXT) \
-	lib_a-strrchr.$(OBJEXT)
+	lib_a-strrchr.$(OBJEXT) lib_a-rawmemchr-stub.$(OBJEXT) \
+	lib_a-rawmemchr.$(OBJEXT)
 lib_a_OBJECTS = $(am_lib_a_OBJECTS)
 DEFAULT_INCLUDES = -I.@am__isrc@
 depcomp =
@@ -214,7 +215,8 @@ lib_a_SOURCES = memchr-stub.c memchr.S memcmp-stub.c memcmp.S \
 	memset.S setjmp.S stpcpy-stub.c stpcpy.S strchr-stub.c \
 	strchr.S strchrnul-stub.c strchrnul.S strcmp-stub.c strcmp.S \
 	strcpy-stub.c strcpy.S strlen-stub.c strlen.S strncmp-stub.c \
-	strncmp.S strnlen-stub.c strnlen.S strrchr-stub.c strrchr.S
+	strncmp.S strnlen-stub.c strnlen.S strrchr-stub.c strrchr.S \
+	rawmemchr.S rawmemchr-stub.c
 lib_a_CCASFLAGS = $(AM_CCASFLAGS)
 lib_a_CFLAGS = $(AM_CFLAGS)
 ACLOCAL_AMFLAGS = -I ../../.. -I ../../../..
@@ -277,6 +279,13 @@ distclean-compile:
 .S.obj:
 	$(CPPASCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
 
+
+lib_a-rawmemchr.o: rawmemchr.S
+	$(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CCASFLAGS) $(CCASFLAGS) -c -o lib_a-rawmemchr.o `test -f 'rawmemchr.S' || echo '$(srcdir)/'`rawmemchr.S
+
+lib_a-rawmemchr.obj: rawmemchr.S
+	$(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CCASFLAGS) $(CCASFLAGS) -c -o lib_a-rawmemchr.obj `if test -f 'rawmemchr.S'; then $(CYGPATH_W) 'rawmemchr.S'; else $(CYGPATH_W) '$(srcdir)/rawmemchr.S'; fi`
+
 lib_a-memchr.o: memchr.S
 	$(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CCASFLAGS) $(CCASFLAGS) -c -o lib_a-memchr.o `test -f 'memchr.S' || echo '$(srcdir)/'`memchr.S
 
@@ -373,6 +382,12 @@ lib_a-strrchr.obj: strrchr.S
 .c.obj:
 	$(COMPILE) -c `$(CYGPATH_W) '$<'`
 
+lib_a-rawmemchr-stub.o: rawmemchr-stub.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rawmemchr-stub.o `test -f 'rawmemchr-stub.c' || echo '$(srcdir)/'`rawmemchr-stub.c
+
+lib_a-rawmemchr-stub.obj: rawmemchr-stub.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rawmemchr-stub.obj `if test -f 'rawmemchr-stub.c'; then $(CYGPATH_W) 'rawmemchr-stub.c'; else $(CYGPATH_W) '$(srcdir)/rawmemchr-stub.c'; fi`
+
 lib_a-memchr-stub.o: memchr-stub.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-memchr-stub.o `test -f 'memchr-stub.c' || echo '$(srcdir)/'`memchr-stub.c
 
diff --git a/newlib/libc/machine/aarch64/rawmemchr-stub.c b/newlib/libc/machine/aarch64/rawmemchr-stub.c
new file mode 100644
index 0000000..582bd2d
--- /dev/null
+++ b/newlib/libc/machine/aarch64/rawmemchr-stub.c
@@ -0,0 +1,31 @@
+/* Copyright (c) 2015, ARM Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * 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.
+       * Neither the name of the company nor the names of its contributors
+         may be used to endorse or promote products derived from this
+         software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "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 THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS 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.  */
+
+#if (defined (__OPTIMIZE_SIZE__) || defined (PREFER_SIZE_OVER_SPEED))
+# include "../../string/rawmemchr.c"
+#else
+/* See rawmemchr.S.  */
+#endif
diff --git a/newlib/libc/machine/aarch64/rawmemchr.S b/newlib/libc/machine/aarch64/rawmemchr.S
new file mode 100644
index 0000000..6514f52
--- /dev/null
+++ b/newlib/libc/machine/aarch64/rawmemchr.S
@@ -0,0 +1,68 @@
+/* Copyright (c) 2015, ARM Limited
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * 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.
+       * Neither the name of the company nor the names of its contributors
+         may be used to endorse or promote products derived from this
+         software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "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 THE COPYRIGHT
+   HOLDER OR CONTRIBUTORS 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.  */
+
+/* Assumptions:
+ *
+ * ARMv8-a, AArch64, unaligned accesses
+ *
+ */
+
+#if (defined (__OPTIMIZE_SIZE__) || defined (PREFER_SIZE_OVER_SPEED))
+/* See rawmemchr-stub.c.  */
+#else
+
+#define L(l) .L ## l
+
+	.macro def_fn f p2align=0
+	.text
+	.p2align \p2align
+	.global \f
+	.type \f, %function
+\f:
+	.endm
+
+/* Special case rawmemchr (s, 0) as strlen, otherwise tailcall memchr.
+   Call strlen without setting up a full frame - it preserves x14/x15.
+*/
+
+def_fn rawmemchr p2align=5
+	.cfi_startproc
+	cbz	w1, L(do_strlen)
+	mov	x2, -1
+	b	memchr
+
+L(do_strlen):
+	mov	x15, x30
+	.cfi_return_column x15
+	mov	x14, x0
+	bl	strlen
+	add	x0, x14, x0
+	ret	x15
+	.cfi_endproc
+
+	.size   rawmemchr, . - rawmemchr
+#endif
+
-- 
1.9.1





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