[PATCH][AArch64] Add rawmemchr

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH][AArch64] Add rawmemchr

Wilco Dijkstra-2
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  <[hidden email]>

        * 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




Reply | Threaded
Open this post in threaded view
|

Re: [PATCH][AArch64] Add rawmemchr

Wilco Dijkstra-2
Fixed copyright message to 2015-2016, updated version below.

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

ChangeLog:
2015-04-28  Wilco Dijkstra  [hidden email]

        * 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.

--

diff --git a/newlib/libc/machine/aarch64/Makefile.am b/newlib/libc/machine/aarch64/Makefile.am
index e2a577c5aeca2984a41c7991d75c924237890d97..e8b8197fac4e7399cf1896ca924c72a4edf6f63f 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 eb7087ffe4093e51c4430bb6baa471451ad9fb26..c512911a27a04a1636e35b8baea83009afd3c074 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 0000000000000000000000000000000000000000..44494128be50dd010b7bd7f949b23ef192642f66
--- /dev/null
+++ b/newlib/libc/machine/aarch64/rawmemchr-stub.c
@@ -0,0 +1,31 @@
+/* Copyright (c) 2015-2016, 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 0000000000000000000000000000000000000000..26da810054832c4f166f27caab33ec7e766e52e1
--- /dev/null
+++ b/newlib/libc/machine/aarch64/rawmemchr.S
@@ -0,0 +1,68 @@
+/* Copyright (c) 2015-2016, 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
+

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH][AArch64] Add rawmemchr

Wilco Dijkstra-2
ping

________________________________________
From: Wilco Dijkstra
Sent: 28 April 2016 14:35
To: [hidden email]; Richard Earnshaw
Cc: nd
Subject: Re: [PATCH][AArch64] Add rawmemchr

Fixed copyright message to 2015-2016, updated version below.

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

ChangeLog:
2015-04-28  Wilco Dijkstra  [hidden email]

        * 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.

--

diff --git a/newlib/libc/machine/aarch64/Makefile.am b/newlib/libc/machine/aarch64/Makefile.am
index e2a577c5aeca2984a41c7991d75c924237890d97..e8b8197fac4e7399cf1896ca924c72a4edf6f63f 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 eb7087ffe4093e51c4430bb6baa471451ad9fb26..c512911a27a04a1636e35b8baea83009afd3c074 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 0000000000000000000000000000000000000000..44494128be50dd010b7bd7f949b23ef192642f66
--- /dev/null
+++ b/newlib/libc/machine/aarch64/rawmemchr-stub.c
@@ -0,0 +1,31 @@
+/* Copyright (c) 2015-2016, 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 0000000000000000000000000000000000000000..26da810054832c4f166f27caab33ec7e766e52e1
--- /dev/null
+++ b/newlib/libc/machine/aarch64/rawmemchr.S
@@ -0,0 +1,68 @@
+/* Copyright (c) 2015-2016, 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
+

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH][AArch64] Add rawmemchr

Marcus
In reply to this post by Wilco Dijkstra-2
On 22 April 2016 at 13:29, Wilco Dijkstra <[hidden email]> wrote:

> 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  <[hidden email]>
>
>         * 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.
>

Hi,
This patch appears to have been munged by the mail system, can you
repost as an attachment please.

Thanks
/Marcus

> ---
>  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
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH][AArch64] Add rawmemchr

Wilco Dijkstra-2
Marcus Shawcroft wrote:
> This patch appears to have been munged by the mail system, can you
> repost as an attachment please.

Sure, I've attached the patch.

Wilco

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  <[hidden email]>

        * 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.

rawmemchr_newlib.patch (11K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH][AArch64] Add rawmemchr

Wilco Dijkstra-2
ping

________________________________________
From: Wilco Dijkstra
Sent: 12 May 2016 17:16
To: Marcus Shawcroft
Cc: [hidden email]; nd
Subject: Re: [PATCH][AArch64] Add rawmemchr

Marcus Shawcroft wrote:
> This patch appears to have been munged by the mail system, can you
> repost as an attachment please.

Sure, I've attached the patch.

Wilco

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  <[hidden email]>

        * 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.

rawmemchr_newlib.patch (11K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH][AArch64] Add rawmemchr

Corinna Vinschen
In reply to this post by Wilco Dijkstra-2
On May 12 16:16, Wilco Dijkstra wrote:

> Marcus Shawcroft wrote:
> > This patch appears to have been munged by the mail system, can you
> > repost as an attachment please.
>
> Sure, I've attached the patch.
>
> Wilco
>
> 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  <[hidden email]>
>
>         * 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.
Patch applied.


Thanks,
Corinna

--
Corinna Vinschen
Cygwin Maintainer
Red Hat

signature.asc (836 bytes) Download Attachment