]> xenbits.xensource.com Git - xen.git/commitdiff
xen: arm64: assembly optimised mem* and str*
authorIan Campbell <ian.campbell@citrix.com>
Wed, 26 Mar 2014 13:38:49 +0000 (13:38 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 3 Apr 2014 16:15:43 +0000 (17:15 +0100)
Taken from Linux v3.14-rc7.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Julien Grall <julien.grall@linaro.org>
Acked-by: Tim Deegan <tim@xen.org>
xen/arch/arm/arm64/lib/Makefile
xen/arch/arm/arm64/lib/memchr.S [new file with mode: 0644]
xen/arch/arm/arm64/lib/memcpy.S [new file with mode: 0644]
xen/arch/arm/arm64/lib/memmove.S [new file with mode: 0644]
xen/arch/arm/arm64/lib/memset.S [new file with mode: 0644]
xen/arch/arm/arm64/lib/strchr.S [new file with mode: 0644]
xen/arch/arm/arm64/lib/strrchr.S [new file with mode: 0644]
xen/include/asm-arm/string.h

index 32c02c4550c86b61f24617a92b1c3f8c2aff6de9..9f3b2360b776f59d2fd15b5c567ce28f7093b04d 100644 (file)
@@ -1 +1,3 @@
+obj-y += memcpy.o memmove.o memset.o memchr.o
 obj-y += bitops.o find_next_bit.o
+obj-y += strchr.o strrchr.o
diff --git a/xen/arch/arm/arm64/lib/memchr.S b/xen/arch/arm/arm64/lib/memchr.S
new file mode 100644 (file)
index 0000000..3cc1b01
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Based on arch/arm/lib/memchr.S
+ *
+ * Copyright (C) 1995-2000 Russell King
+ * Copyright (C) 2013 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/config.h>
+
+/*
+ * Find a character in an area of memory.
+ *
+ * Parameters:
+ *     x0 - buf
+ *     x1 - c
+ *     x2 - n
+ * Returns:
+ *     x0 - address of first occurrence of 'c' or 0
+ */
+ENTRY(memchr)
+       and     w1, w1, #0xff
+1:     subs    x2, x2, #1
+       b.mi    2f
+       ldrb    w3, [x0], #1
+       cmp     w3, w1
+       b.ne    1b
+       sub     x0, x0, #1
+       ret
+2:     mov     x0, #0
+       ret
+ENDPROC(memchr)
diff --git a/xen/arch/arm/arm64/lib/memcpy.S b/xen/arch/arm/arm64/lib/memcpy.S
new file mode 100644 (file)
index 0000000..c8197c6
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/config.h>
+
+/*
+ * Copy a buffer from src to dest (alignment handled by the hardware)
+ *
+ * Parameters:
+ *     x0 - dest
+ *     x1 - src
+ *     x2 - n
+ * Returns:
+ *     x0 - dest
+ */
+ENTRY(memcpy)
+       mov     x4, x0
+       subs    x2, x2, #8
+       b.mi    2f
+1:     ldr     x3, [x1], #8
+       subs    x2, x2, #8
+       str     x3, [x4], #8
+       b.pl    1b
+2:     adds    x2, x2, #4
+       b.mi    3f
+       ldr     w3, [x1], #4
+       sub     x2, x2, #4
+       str     w3, [x4], #4
+3:     adds    x2, x2, #2
+       b.mi    4f
+       ldrh    w3, [x1], #2
+       sub     x2, x2, #2
+       strh    w3, [x4], #2
+4:     adds    x2, x2, #1
+       b.mi    5f
+       ldrb    w3, [x1]
+       strb    w3, [x4]
+5:     ret
+ENDPROC(memcpy)
diff --git a/xen/arch/arm/arm64/lib/memmove.S b/xen/arch/arm/arm64/lib/memmove.S
new file mode 100644 (file)
index 0000000..1bf0936
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2013 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/config.h>
+
+/*
+ * Move a buffer from src to test (alignment handled by the hardware).
+ * If dest <= src, call memcpy, otherwise copy in reverse order.
+ *
+ * Parameters:
+ *     x0 - dest
+ *     x1 - src
+ *     x2 - n
+ * Returns:
+ *     x0 - dest
+ */
+ENTRY(memmove)
+       cmp     x0, x1
+       b.ls    memcpy
+       add     x4, x0, x2
+       add     x1, x1, x2
+       subs    x2, x2, #8
+       b.mi    2f
+1:     ldr     x3, [x1, #-8]!
+       subs    x2, x2, #8
+       str     x3, [x4, #-8]!
+       b.pl    1b
+2:     adds    x2, x2, #4
+       b.mi    3f
+       ldr     w3, [x1, #-4]!
+       sub     x2, x2, #4
+       str     w3, [x4, #-4]!
+3:     adds    x2, x2, #2
+       b.mi    4f
+       ldrh    w3, [x1, #-2]!
+       sub     x2, x2, #2
+       strh    w3, [x4, #-2]!
+4:     adds    x2, x2, #1
+       b.mi    5f
+       ldrb    w3, [x1, #-1]
+       strb    w3, [x4, #-1]
+5:     ret
+ENDPROC(memmove)
diff --git a/xen/arch/arm/arm64/lib/memset.S b/xen/arch/arm/arm64/lib/memset.S
new file mode 100644 (file)
index 0000000..25a4fb6
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/config.h>
+
+/*
+ * Fill in the buffer with character c (alignment handled by the hardware)
+ *
+ * Parameters:
+ *     x0 - buf
+ *     x1 - c
+ *     x2 - n
+ * Returns:
+ *     x0 - buf
+ */
+ENTRY(memset)
+       mov     x4, x0
+       and     w1, w1, #0xff
+       orr     w1, w1, w1, lsl #8
+       orr     w1, w1, w1, lsl #16
+       orr     x1, x1, x1, lsl #32
+       subs    x2, x2, #8
+       b.mi    2f
+1:     str     x1, [x4], #8
+       subs    x2, x2, #8
+       b.pl    1b
+2:     adds    x2, x2, #4
+       b.mi    3f
+       sub     x2, x2, #4
+       str     w1, [x4], #4
+3:     adds    x2, x2, #2
+       b.mi    4f
+       sub     x2, x2, #2
+       strh    w1, [x4], #2
+4:     adds    x2, x2, #1
+       b.mi    5f
+       strb    w1, [x4]
+5:     ret
+ENDPROC(memset)
diff --git a/xen/arch/arm/arm64/lib/strchr.S b/xen/arch/arm/arm64/lib/strchr.S
new file mode 100644 (file)
index 0000000..9e265e4
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Based on arch/arm/lib/strchr.S
+ *
+ * Copyright (C) 1995-2000 Russell King
+ * Copyright (C) 2013 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/config.h>
+
+/*
+ * Find the first occurrence of a character in a string.
+ *
+ * Parameters:
+ *     x0 - str
+ *     x1 - c
+ * Returns:
+ *     x0 - address of first occurrence of 'c' or 0
+ */
+ENTRY(strchr)
+       and     w1, w1, #0xff
+1:     ldrb    w2, [x0], #1
+       cmp     w2, w1
+       ccmp    w2, wzr, #4, ne
+       b.ne    1b
+       sub     x0, x0, #1
+       cmp     w2, w1
+       csel    x0, x0, xzr, eq
+       ret
+ENDPROC(strchr)
diff --git a/xen/arch/arm/arm64/lib/strrchr.S b/xen/arch/arm/arm64/lib/strrchr.S
new file mode 100644 (file)
index 0000000..3791754
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Based on arch/arm/lib/strrchr.S
+ *
+ * Copyright (C) 1995-2000 Russell King
+ * Copyright (C) 2013 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/config.h>
+
+/*
+ * Find the last occurrence of a character in a string.
+ *
+ * Parameters:
+ *     x0 - str
+ *     x1 - c
+ * Returns:
+ *     x0 - address of last occurrence of 'c' or 0
+ */
+ENTRY(strrchr)
+       mov     x3, #0
+       and     w1, w1, #0xff
+1:     ldrb    w2, [x0], #1
+       cbz     w2, 2f
+       cmp     w2, w1
+       b.ne    1b
+       sub     x3, x0, #1
+       b       1b
+2:     mov     x0, x3
+       ret
+ENDPROC(strrchr)
index 7d8b35a64ac111f62f3bebc5af5df881a2d9fe27..324276262e5fdd3f7b5b60de308a2e3c6febcf34 100644 (file)
@@ -3,8 +3,6 @@
 
 #include <xen/config.h>
 
-#if defined(CONFIG_ARM_32)
-
 /*
  * We don't do inline string functions, since the
  * optimised inline asm versions are not small.
@@ -29,6 +27,8 @@ extern void * memset(void *, int, __kernel_size_t);
 #define __HAVE_ARCH_MEMCHR
 extern void * memchr(const void *, int, __kernel_size_t);
 
+#if defined(CONFIG_ARM_32)
+
 extern void __memzero(void *ptr, __kernel_size_t n);
 
 #define memset(p,v,n)                                                   \