aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2018-05-31 09:52:03 -0700
committerRichard Henderson <richard.henderson@linaro.org>2018-06-04 10:58:08 -0700
commit67e1b9fdba292361242880e144673c98a26e6b01 (patch)
tree2ca059b2cfde0614b4fec1c212c5cb06037b64a2
parent737584781cbd838bba780be6b041b08898f0f2c1 (diff)
Add src/sve/strchr.S
Change-Id: I81f3a4721fa6109890173ac6f57c665ef33bc26d
-rw-r--r--Makefile.am4
-rw-r--r--src/sve/strchr.S92
-rw-r--r--src/sve/strchrnul.S32
3 files changed, 126 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index 46b947a..e8e5256 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -288,8 +288,8 @@ if WITH_SVE
libcortex_strings_la_SOURCES = \
src/aarch64/memchr.S \
src/aarch64/memcmp.S \
- src/aarch64/strchr.S \
- src/aarch64/strchrnul.S \
+ src/sve/strchr.S \
+ src/sve/strchrnul.S \
src/sve/strcmp.S \
src/sve/strcpy.S \
src/sve/strlen.S \
diff --git a/src/sve/strchr.S b/src/sve/strchr.S
new file mode 100644
index 0000000..8cf079b
--- /dev/null
+++ b/src/sve/strchr.S
@@ -0,0 +1,92 @@
+/*
+ * strchr/strchrnul - find a character in a string
+ *
+ * Copyright (c) 2018, Linaro 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
+ * SVE Available.
+ */
+
+ .arch armv8-a+sve
+ .text
+
+/* To build as strchrnul, define BUILD_STPCPY before compiling this file. */
+#ifdef BUILD_STRCHRNUL
+#define FUNC strchrnul
+#else
+#define FUNC strchr
+#endif
+
+ .globl FUNC
+ .type FUNC, %function
+ .p2align 4
+FUNC:
+ dup z1.b, w1 /* replicate byte across vector */
+ setffr /* initialize FFR */
+ ptrue p1.b /* all ones; loop invariant */
+
+ .p2align 4
+ /* Read a vector's worth of bytes, stopping on first fault. */
+0: ldff1b z0.b, p1/z, [x0, xzr]
+ rdffrs p0.b, p1/z
+ b.nlast 2f
+
+ /* First fault did not fail: the whole vector is valid.
+ Avoid depending on the contents of FFR beyond the branch. */
+ incb x0 /* speculate increment */
+ cmpeq p2.b, p1/z, z0.b, z1.b /* search for c */
+ cmpeq p3.b, p1/z, z0.b, 0 /* search for 0 */
+ orrs p4.b, p1/z, p2.b, p3.b /* c | 0 */
+ b.none 0b
+ decb x0 /* undo speculate */
+
+ /* Found C or 0. */
+1: brka p4.b, p1/z, p4.b /* find first such */
+ sub x0, x0, 1 /* adjust pointer for that byte */
+ incp x0, p4.b
+#ifndef BUILD_STRCHRNUL
+ ptest p4, p2.b /* was first in c? */
+ csel x0, xzr, x0, none /* if there was no c, return null */
+#endif
+ ret
+
+ /* First fault failed: only some of the vector is valid.
+ Perform the comparision only on the valid bytes. */
+2: cmpeq p2.b, p0/z, z0.b, z1.b /* search for c */
+ cmpeq p3.b, p0/z, z0.b, 0 /* search for 0 */
+ orrs p4.b, p0/z, p2.b, p3.b /* c | 0 */
+ b.any 1b
+
+ /* No C or 0 found. Re-init FFR, increment, and loop. */
+ setffr
+ incp x0, p0.b
+ b 0b
+
+ .size FUNC, . - FUNC
diff --git a/src/sve/strchrnul.S b/src/sve/strchrnul.S
new file mode 100644
index 0000000..61d2877
--- /dev/null
+++ b/src/sve/strchrnul.S
@@ -0,0 +1,32 @@
+/*
+ * strchrnul - find a character or nul in a string
+ *
+ * Copyright (c) 2018, Linaro 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.
+ */
+
+#define BUILD_STRCHRNUL
+#include "strchr.S"