[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 14/17] xen: arm64: assembly optimised mem* and str*



Taken from Linux v3.14-rc7.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 xen/arch/arm/arm64/lib/Makefile  |    2 ++
 xen/arch/arm/arm64/lib/memchr.S  |   43 +++++++++++++++++++++++++++++
 xen/arch/arm/arm64/lib/memcpy.S  |   52 +++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/lib/memmove.S |   56 ++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/lib/memset.S  |   52 +++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/lib/strchr.S  |   41 ++++++++++++++++++++++++++++
 xen/arch/arm/arm64/lib/strrchr.S |   42 ++++++++++++++++++++++++++++
 xen/include/asm-arm/string.h     |    4 +--
 8 files changed, 290 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/arm/arm64/lib/memchr.S
 create mode 100644 xen/arch/arm/arm64/lib/memcpy.S
 create mode 100644 xen/arch/arm/arm64/lib/memmove.S
 create mode 100644 xen/arch/arm/arm64/lib/memset.S
 create mode 100644 xen/arch/arm/arm64/lib/strchr.S
 create mode 100644 xen/arch/arm/arm64/lib/strrchr.S

diff --git a/xen/arch/arm/arm64/lib/Makefile b/xen/arch/arm/arm64/lib/Makefile
index 32c02c4..9f3b236 100644
--- a/xen/arch/arm/arm64/lib/Makefile
+++ b/xen/arch/arm/arm64/lib/Makefile
@@ -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
index 0000000..3cc1b01
--- /dev/null
+++ b/xen/arch/arm/arm64/lib/memchr.S
@@ -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
index 0000000..c8197c6
--- /dev/null
+++ b/xen/arch/arm/arm64/lib/memcpy.S
@@ -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
index 0000000..1bf0936
--- /dev/null
+++ b/xen/arch/arm/arm64/lib/memmove.S
@@ -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
index 0000000..25a4fb6
--- /dev/null
+++ b/xen/arch/arm/arm64/lib/memset.S
@@ -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
index 0000000..9e265e4
--- /dev/null
+++ b/xen/arch/arm/arm64/lib/strchr.S
@@ -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
index 0000000..3791754
--- /dev/null
+++ b/xen/arch/arm/arm64/lib/strrchr.S
@@ -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)
diff --git a/xen/include/asm-arm/string.h b/xen/include/asm-arm/string.h
index 7d8b35a..3242762 100644
--- a/xen/include/asm-arm/string.h
+++ b/xen/include/asm-arm/string.h
@@ -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)                                                   \
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.