aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm64
diff options
context:
space:
mode:
authorCatalin Marinas <catalin.marinas@arm.com>2013-03-21 12:16:43 -0400
committerCatalin Marinas <catalin.marinas@arm.com>2013-03-21 13:39:29 -0400
commit4a8992271c843cb5bcd3321bf6a02eb251280b1d (patch)
tree100bdf14109f0d6b6ac559db6f25a337daa4280c /arch/arm64
parent792072066d30372772137be9ee2f4d72d77329f9 (diff)
arm64: klib: Optimised memory functions
This patch introduces AArch64-specific memory functions (memcpy, memmove, memchr, memset). These functions are not optimised for any CPU implementation but can be used as a starting point once hardware is available. Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Diffstat (limited to 'arch/arm64')
-rw-r--r--arch/arm64/include/asm/Kbuild1
-rw-r--r--arch/arm64/include/asm/string.h31
-rw-r--r--arch/arm64/kernel/arm64ksyms.c6
-rw-r--r--arch/arm64/lib/Makefile3
-rw-r--r--arch/arm64/lib/memchr.S44
-rw-r--r--arch/arm64/lib/memcpy.S53
-rw-r--r--arch/arm64/lib/memmove.S57
-rw-r--r--arch/arm64/lib/memset.S53
8 files changed, 246 insertions, 2 deletions
diff --git a/arch/arm64/include/asm/Kbuild b/arch/arm64/include/asm/Kbuild
index e5fe4f99fe10..a13a4a493d56 100644
--- a/arch/arm64/include/asm/Kbuild
+++ b/arch/arm64/include/asm/Kbuild
@@ -39,7 +39,6 @@ generic-y += shmbuf.h
39generic-y += sizes.h 39generic-y += sizes.h
40generic-y += socket.h 40generic-y += socket.h
41generic-y += sockios.h 41generic-y += sockios.h
42generic-y += string.h
43generic-y += switch_to.h 42generic-y += switch_to.h
44generic-y += swab.h 43generic-y += swab.h
45generic-y += termbits.h 44generic-y += termbits.h
diff --git a/arch/arm64/include/asm/string.h b/arch/arm64/include/asm/string.h
new file mode 100644
index 000000000000..be8a644f306a
--- /dev/null
+++ b/arch/arm64/include/asm/string.h
@@ -0,0 +1,31 @@
1/*
2 * Copyright (C) 2013 ARM Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#ifndef __ASM_STRING_H
17#define __ASM_STRING_H
18
19#define __HAVE_ARCH_MEMCPY
20extern void *memcpy(void *, const void *, __kernel_size_t);
21
22#define __HAVE_ARCH_MEMMOVE
23extern void *memmove(void *, const void *, __kernel_size_t);
24
25#define __HAVE_ARCH_MEMCHR
26extern void *memchr(const void *, int, __kernel_size_t);
27
28#define __HAVE_ARCH_MEMSET
29extern void *memset(void *, int, __kernel_size_t);
30
31#endif
diff --git a/arch/arm64/kernel/arm64ksyms.c b/arch/arm64/kernel/arm64ksyms.c
index aa3e948f7885..d7f7b17c414e 100644
--- a/arch/arm64/kernel/arm64ksyms.c
+++ b/arch/arm64/kernel/arm64ksyms.c
@@ -46,3 +46,9 @@ EXPORT_SYMBOL(__atomic_hash);
46 46
47 /* physical memory */ 47 /* physical memory */
48EXPORT_SYMBOL(memstart_addr); 48EXPORT_SYMBOL(memstart_addr);
49
50 /* string / mem functions */
51EXPORT_SYMBOL(memset);
52EXPORT_SYMBOL(memcpy);
53EXPORT_SYMBOL(memmove);
54EXPORT_SYMBOL(memchr);
diff --git a/arch/arm64/lib/Makefile b/arch/arm64/lib/Makefile
index 2fb7f6092aae..2fce1398aa24 100644
--- a/arch/arm64/lib/Makefile
+++ b/arch/arm64/lib/Makefile
@@ -1,4 +1,5 @@
1lib-y := bitops.o delay.o \ 1lib-y := bitops.o delay.o \
2 strncpy_from_user.o strnlen_user.o clear_user.o \ 2 strncpy_from_user.o strnlen_user.o clear_user.o \
3 copy_from_user.o copy_to_user.o copy_in_user.o \ 3 copy_from_user.o copy_to_user.o copy_in_user.o \
4 copy_page.o clear_page.o 4 copy_page.o clear_page.o \
5 memchr.o memcpy.o memmove.o memset.o
diff --git a/arch/arm64/lib/memchr.S b/arch/arm64/lib/memchr.S
new file mode 100644
index 000000000000..8636b7549163
--- /dev/null
+++ b/arch/arm64/lib/memchr.S
@@ -0,0 +1,44 @@
1/*
2 * Based on arch/arm/lib/memchr.S
3 *
4 * Copyright (C) 1995-2000 Russell King
5 * Copyright (C) 2013 ARM Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/linkage.h>
21#include <asm/assembler.h>
22
23/*
24 * Find a character in an area of memory.
25 *
26 * Parameters:
27 * x0 - buf
28 * x1 - c
29 * x2 - n
30 * Returns:
31 * x0 - address of first occurrence of 'c' or 0
32 */
33ENTRY(memchr)
34 and w1, w1, #0xff
351: subs x2, x2, #1
36 b.mi 2f
37 ldrb w3, [x0], #1
38 cmp w3, w1
39 b.ne 1b
40 sub x0, x0, #1
41 ret
422: mov x0, #0
43 ret
44ENDPROC(memchr)
diff --git a/arch/arm64/lib/memcpy.S b/arch/arm64/lib/memcpy.S
new file mode 100644
index 000000000000..27b5003609b6
--- /dev/null
+++ b/arch/arm64/lib/memcpy.S
@@ -0,0 +1,53 @@
1/*
2 * Copyright (C) 2013 ARM Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/linkage.h>
18#include <asm/assembler.h>
19
20/*
21 * Copy a buffer from src to dest (alignment handled by the hardware)
22 *
23 * Parameters:
24 * x0 - dest
25 * x1 - src
26 * x2 - n
27 * Returns:
28 * x0 - dest
29 */
30ENTRY(memcpy)
31 mov x4, x0
32 subs x2, x2, #8
33 b.mi 2f
341: ldr x3, [x1], #8
35 subs x2, x2, #8
36 str x3, [x4], #8
37 b.pl 1b
382: adds x2, x2, #4
39 b.mi 3f
40 ldr w3, [x1], #4
41 sub x2, x2, #4
42 str w3, [x4], #4
433: adds x2, x2, #2
44 b.mi 4f
45 ldrh w3, [x1], #2
46 sub x2, x2, #2
47 strh w3, [x4], #2
484: adds x2, x2, #1
49 b.mi 5f
50 ldrb w3, [x1]
51 strb w3, [x4]
525: ret
53ENDPROC(memcpy)
diff --git a/arch/arm64/lib/memmove.S b/arch/arm64/lib/memmove.S
new file mode 100644
index 000000000000..b79fdfa42d39
--- /dev/null
+++ b/arch/arm64/lib/memmove.S
@@ -0,0 +1,57 @@
1/*
2 * Copyright (C) 2013 ARM Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/linkage.h>
18#include <asm/assembler.h>
19
20/*
21 * Move a buffer from src to test (alignment handled by the hardware).
22 * If dest <= src, call memcpy, otherwise copy in reverse order.
23 *
24 * Parameters:
25 * x0 - dest
26 * x1 - src
27 * x2 - n
28 * Returns:
29 * x0 - dest
30 */
31ENTRY(memmove)
32 cmp x0, x1
33 b.ls memcpy
34 add x4, x0, x2
35 add x1, x1, x2
36 subs x2, x2, #8
37 b.mi 2f
381: ldr x3, [x1, #-8]!
39 subs x2, x2, #8
40 str x3, [x4, #-8]!
41 b.pl 1b
422: adds x2, x2, #4
43 b.mi 3f
44 ldr w3, [x1, #-4]!
45 sub x2, x2, #4
46 str w3, [x4, #-4]!
473: adds x2, x2, #2
48 b.mi 4f
49 ldrh w3, [x1, #-2]!
50 sub x2, x2, #2
51 strh w3, [x4, #-2]!
524: adds x2, x2, #1
53 b.mi 5f
54 ldrb w3, [x1, #-1]
55 strb w3, [x4, #-1]
565: ret
57ENDPROC(memmove)
diff --git a/arch/arm64/lib/memset.S b/arch/arm64/lib/memset.S
new file mode 100644
index 000000000000..87e4a68fbbbc
--- /dev/null
+++ b/arch/arm64/lib/memset.S
@@ -0,0 +1,53 @@
1/*
2 * Copyright (C) 2013 ARM Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/linkage.h>
18#include <asm/assembler.h>
19
20/*
21 * Fill in the buffer with character c (alignment handled by the hardware)
22 *
23 * Parameters:
24 * x0 - buf
25 * x1 - c
26 * x2 - n
27 * Returns:
28 * x0 - buf
29 */
30ENTRY(memset)
31 mov x4, x0
32 and w1, w1, #0xff
33 orr w1, w1, w1, lsl #8
34 orr w1, w1, w1, lsl #16
35 orr x1, x1, x1, lsl #32
36 subs x2, x2, #8
37 b.mi 2f
381: str x1, [x4], #8
39 subs x2, x2, #8
40 b.pl 1b
412: adds x2, x2, #4
42 b.mi 3f
43 sub x2, x2, #4
44 str w1, [x4], #4
453: adds x2, x2, #2
46 b.mi 4f
47 sub x2, x2, #2
48 strh w1, [x4], #2
494: adds x2, x2, #1
50 b.mi 5f
51 strb w1, [x4]
525: ret
53ENDPROC(memset)