aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm64
diff options
context:
space:
mode:
authorCatalin Marinas <catalin.marinas@arm.com>2013-03-21 12:23:43 -0400
committerCatalin Marinas <catalin.marinas@arm.com>2013-03-21 13:39:30 -0400
commit2b8cac814cd5a0a305d62dcd1d589faccb705a4d (patch)
tree62340ae9d079bdf28747eff9c5a9e12530f52895 /arch/arm64
parent4a8992271c843cb5bcd3321bf6a02eb251280b1d (diff)
arm64: klib: Optimised string functions
This patch introduces AArch64-specific string functions (strchr, strrchr). Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Diffstat (limited to 'arch/arm64')
-rw-r--r--arch/arm64/include/asm/string.h6
-rw-r--r--arch/arm64/kernel/arm64ksyms.c2
-rw-r--r--arch/arm64/lib/Makefile3
-rw-r--r--arch/arm64/lib/strchr.S42
-rw-r--r--arch/arm64/lib/strrchr.S43
5 files changed, 95 insertions, 1 deletions
diff --git a/arch/arm64/include/asm/string.h b/arch/arm64/include/asm/string.h
index be8a644f306a..3ee8b303d9a9 100644
--- a/arch/arm64/include/asm/string.h
+++ b/arch/arm64/include/asm/string.h
@@ -16,6 +16,12 @@
16#ifndef __ASM_STRING_H 16#ifndef __ASM_STRING_H
17#define __ASM_STRING_H 17#define __ASM_STRING_H
18 18
19#define __HAVE_ARCH_STRRCHR
20extern char *strrchr(const char *, int c);
21
22#define __HAVE_ARCH_STRCHR
23extern char *strchr(const char *, int c);
24
19#define __HAVE_ARCH_MEMCPY 25#define __HAVE_ARCH_MEMCPY
20extern void *memcpy(void *, const void *, __kernel_size_t); 26extern void *memcpy(void *, const void *, __kernel_size_t);
21 27
diff --git a/arch/arm64/kernel/arm64ksyms.c b/arch/arm64/kernel/arm64ksyms.c
index d7f7b17c414e..a5d0d4643109 100644
--- a/arch/arm64/kernel/arm64ksyms.c
+++ b/arch/arm64/kernel/arm64ksyms.c
@@ -48,6 +48,8 @@ EXPORT_SYMBOL(__atomic_hash);
48EXPORT_SYMBOL(memstart_addr); 48EXPORT_SYMBOL(memstart_addr);
49 49
50 /* string / mem functions */ 50 /* string / mem functions */
51EXPORT_SYMBOL(strchr);
52EXPORT_SYMBOL(strrchr);
51EXPORT_SYMBOL(memset); 53EXPORT_SYMBOL(memset);
52EXPORT_SYMBOL(memcpy); 54EXPORT_SYMBOL(memcpy);
53EXPORT_SYMBOL(memmove); 55EXPORT_SYMBOL(memmove);
diff --git a/arch/arm64/lib/Makefile b/arch/arm64/lib/Makefile
index 2fce1398aa24..59acc0ef0462 100644
--- a/arch/arm64/lib/Makefile
+++ b/arch/arm64/lib/Makefile
@@ -2,4 +2,5 @@ lib-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 5 memchr.o memcpy.o memmove.o memset.o \
6 strchr.o strrchr.o
diff --git a/arch/arm64/lib/strchr.S b/arch/arm64/lib/strchr.S
new file mode 100644
index 000000000000..dae0cf5591f9
--- /dev/null
+++ b/arch/arm64/lib/strchr.S
@@ -0,0 +1,42 @@
1/*
2 * Based on arch/arm/lib/strchr.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 the first occurrence of a character in a string.
25 *
26 * Parameters:
27 * x0 - str
28 * x1 - c
29 * Returns:
30 * x0 - address of first occurrence of 'c' or 0
31 */
32ENTRY(strchr)
33 and w1, w1, #0xff
341: ldrb w2, [x0], #1
35 cmp w2, w1
36 ccmp w2, wzr, #4, ne
37 b.ne 1b
38 sub x0, x0, #1
39 cmp w2, w1
40 csel x0, x0, xzr, eq
41 ret
42ENDPROC(strchr)
diff --git a/arch/arm64/lib/strrchr.S b/arch/arm64/lib/strrchr.S
new file mode 100644
index 000000000000..61eabd9a289a
--- /dev/null
+++ b/arch/arm64/lib/strrchr.S
@@ -0,0 +1,43 @@
1/*
2 * Based on arch/arm/lib/strrchr.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 the last occurrence of a character in a string.
25 *
26 * Parameters:
27 * x0 - str
28 * x1 - c
29 * Returns:
30 * x0 - address of last occurrence of 'c' or 0
31 */
32ENTRY(strrchr)
33 mov x3, #0
34 and w1, w1, #0xff
351: ldrb w2, [x0], #1
36 cbz w2, 2f
37 cmp w2, w1
38 b.ne 1b
39 sub x3, x0, #1
40 b 1b
412: mov x0, x3
42 ret
43ENDPROC(strrchr)