diff options
author | Catalin Marinas <catalin.marinas@arm.com> | 2013-03-28 12:13:26 -0400 |
---|---|---|
committer | Catalin Marinas <catalin.marinas@arm.com> | 2013-03-28 12:13:26 -0400 |
commit | d4784be3b20ed0dd19bbde3b2d58df023ae1dc86 (patch) | |
tree | 951aa2f45d2acd1b244bd3eabdf78c7d1e75d0f2 /arch/arm64 | |
parent | e851b58cb77b47a5c14267723bd6b76655d21840 (diff) | |
parent | 62479586532715b6da4777374a6f53b32453385e (diff) |
Merge branch 'arm64-klib' into upstream
* arm64-klib:
arm64: klib: Optimised atomic bitops
arm64: klib: Optimised string functions
arm64: klib: Optimised memory functions
Diffstat (limited to 'arch/arm64')
-rw-r--r-- | arch/arm64/include/asm/Kbuild | 1 | ||||
-rw-r--r-- | arch/arm64/include/asm/bitops.h | 18 | ||||
-rw-r--r-- | arch/arm64/include/asm/string.h | 37 | ||||
-rw-r--r-- | arch/arm64/kernel/arm64ksyms.c | 21 | ||||
-rw-r--r-- | arch/arm64/lib/Makefile | 4 | ||||
-rw-r--r-- | arch/arm64/lib/bitops.S | 70 | ||||
-rw-r--r-- | arch/arm64/lib/memchr.S (renamed from arch/arm64/lib/bitops.c) | 37 | ||||
-rw-r--r-- | arch/arm64/lib/memcpy.S | 53 | ||||
-rw-r--r-- | arch/arm64/lib/memmove.S | 57 | ||||
-rw-r--r-- | arch/arm64/lib/memset.S | 53 | ||||
-rw-r--r-- | arch/arm64/lib/strchr.S | 42 | ||||
-rw-r--r-- | arch/arm64/lib/strrchr.S | 43 |
12 files changed, 418 insertions, 18 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 | |||
39 | generic-y += sizes.h | 39 | generic-y += sizes.h |
40 | generic-y += socket.h | 40 | generic-y += socket.h |
41 | generic-y += sockios.h | 41 | generic-y += sockios.h |
42 | generic-y += string.h | ||
43 | generic-y += switch_to.h | 42 | generic-y += switch_to.h |
44 | generic-y += swab.h | 43 | generic-y += swab.h |
45 | generic-y += termbits.h | 44 | generic-y += termbits.h |
diff --git a/arch/arm64/include/asm/bitops.h b/arch/arm64/include/asm/bitops.h index 5e693073b030..aa5b59d6ba43 100644 --- a/arch/arm64/include/asm/bitops.h +++ b/arch/arm64/include/asm/bitops.h | |||
@@ -32,6 +32,16 @@ | |||
32 | #error only <linux/bitops.h> can be included directly | 32 | #error only <linux/bitops.h> can be included directly |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | /* | ||
36 | * Little endian assembly atomic bitops. | ||
37 | */ | ||
38 | extern void set_bit(int nr, volatile unsigned long *p); | ||
39 | extern void clear_bit(int nr, volatile unsigned long *p); | ||
40 | extern void change_bit(int nr, volatile unsigned long *p); | ||
41 | extern int test_and_set_bit(int nr, volatile unsigned long *p); | ||
42 | extern int test_and_clear_bit(int nr, volatile unsigned long *p); | ||
43 | extern int test_and_change_bit(int nr, volatile unsigned long *p); | ||
44 | |||
35 | #include <asm-generic/bitops/builtin-__ffs.h> | 45 | #include <asm-generic/bitops/builtin-__ffs.h> |
36 | #include <asm-generic/bitops/builtin-ffs.h> | 46 | #include <asm-generic/bitops/builtin-ffs.h> |
37 | #include <asm-generic/bitops/builtin-__fls.h> | 47 | #include <asm-generic/bitops/builtin-__fls.h> |
@@ -45,9 +55,13 @@ | |||
45 | #include <asm-generic/bitops/hweight.h> | 55 | #include <asm-generic/bitops/hweight.h> |
46 | #include <asm-generic/bitops/lock.h> | 56 | #include <asm-generic/bitops/lock.h> |
47 | 57 | ||
48 | #include <asm-generic/bitops/atomic.h> | ||
49 | #include <asm-generic/bitops/non-atomic.h> | 58 | #include <asm-generic/bitops/non-atomic.h> |
50 | #include <asm-generic/bitops/le.h> | 59 | #include <asm-generic/bitops/le.h> |
51 | #include <asm-generic/bitops/ext2-atomic.h> | 60 | |
61 | /* | ||
62 | * Ext2 is defined to use little-endian byte ordering. | ||
63 | */ | ||
64 | #define ext2_set_bit_atomic(lock, nr, p) test_and_set_bit_le(nr, p) | ||
65 | #define ext2_clear_bit_atomic(lock, nr, p) test_and_clear_bit_le(nr, p) | ||
52 | 66 | ||
53 | #endif /* __ASM_BITOPS_H */ | 67 | #endif /* __ASM_BITOPS_H */ |
diff --git a/arch/arm64/include/asm/string.h b/arch/arm64/include/asm/string.h new file mode 100644 index 000000000000..3ee8b303d9a9 --- /dev/null +++ b/arch/arm64/include/asm/string.h | |||
@@ -0,0 +1,37 @@ | |||
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_STRRCHR | ||
20 | extern char *strrchr(const char *, int c); | ||
21 | |||
22 | #define __HAVE_ARCH_STRCHR | ||
23 | extern char *strchr(const char *, int c); | ||
24 | |||
25 | #define __HAVE_ARCH_MEMCPY | ||
26 | extern void *memcpy(void *, const void *, __kernel_size_t); | ||
27 | |||
28 | #define __HAVE_ARCH_MEMMOVE | ||
29 | extern void *memmove(void *, const void *, __kernel_size_t); | ||
30 | |||
31 | #define __HAVE_ARCH_MEMCHR | ||
32 | extern void *memchr(const void *, int, __kernel_size_t); | ||
33 | |||
34 | #define __HAVE_ARCH_MEMSET | ||
35 | extern void *memset(void *, int, __kernel_size_t); | ||
36 | |||
37 | #endif | ||
diff --git a/arch/arm64/kernel/arm64ksyms.c b/arch/arm64/kernel/arm64ksyms.c index aa3e948f7885..7df1aad29b67 100644 --- a/arch/arm64/kernel/arm64ksyms.c +++ b/arch/arm64/kernel/arm64ksyms.c | |||
@@ -39,10 +39,21 @@ EXPORT_SYMBOL(__copy_from_user); | |||
39 | EXPORT_SYMBOL(__copy_to_user); | 39 | EXPORT_SYMBOL(__copy_to_user); |
40 | EXPORT_SYMBOL(__clear_user); | 40 | EXPORT_SYMBOL(__clear_user); |
41 | 41 | ||
42 | /* bitops */ | ||
43 | #ifdef CONFIG_SMP | ||
44 | EXPORT_SYMBOL(__atomic_hash); | ||
45 | #endif | ||
46 | |||
47 | /* physical memory */ | 42 | /* physical memory */ |
48 | EXPORT_SYMBOL(memstart_addr); | 43 | EXPORT_SYMBOL(memstart_addr); |
44 | |||
45 | /* string / mem functions */ | ||
46 | EXPORT_SYMBOL(strchr); | ||
47 | EXPORT_SYMBOL(strrchr); | ||
48 | EXPORT_SYMBOL(memset); | ||
49 | EXPORT_SYMBOL(memcpy); | ||
50 | EXPORT_SYMBOL(memmove); | ||
51 | EXPORT_SYMBOL(memchr); | ||
52 | |||
53 | /* atomic bitops */ | ||
54 | EXPORT_SYMBOL(set_bit); | ||
55 | EXPORT_SYMBOL(test_and_set_bit); | ||
56 | EXPORT_SYMBOL(clear_bit); | ||
57 | EXPORT_SYMBOL(test_and_clear_bit); | ||
58 | EXPORT_SYMBOL(change_bit); | ||
59 | EXPORT_SYMBOL(test_and_change_bit); | ||
diff --git a/arch/arm64/lib/Makefile b/arch/arm64/lib/Makefile index 2fb7f6092aae..59acc0ef0462 100644 --- a/arch/arm64/lib/Makefile +++ b/arch/arm64/lib/Makefile | |||
@@ -1,4 +1,6 @@ | |||
1 | lib-y := bitops.o delay.o \ | 1 | 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 \ | ||
6 | strchr.o strrchr.o | ||
diff --git a/arch/arm64/lib/bitops.S b/arch/arm64/lib/bitops.S new file mode 100644 index 000000000000..fd1e801b53e7 --- /dev/null +++ b/arch/arm64/lib/bitops.S | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * Based on arch/arm/lib/bitops.h | ||
3 | * | ||
4 | * Copyright (C) 2013 ARM Ltd. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include <linux/linkage.h> | ||
20 | #include <asm/assembler.h> | ||
21 | |||
22 | /* | ||
23 | * x0: bits 5:0 bit offset | ||
24 | * bits 63:6 word offset | ||
25 | * x1: address | ||
26 | */ | ||
27 | .macro bitop, name, instr | ||
28 | ENTRY( \name ) | ||
29 | and x3, x0, #63 // Get bit offset | ||
30 | eor x0, x0, x3 // Clear low bits | ||
31 | mov x2, #1 | ||
32 | add x1, x1, x0, lsr #3 // Get word offset | ||
33 | lsl x3, x2, x3 // Create mask | ||
34 | 1: ldxr x2, [x1] | ||
35 | \instr x2, x2, x3 | ||
36 | stxr w0, x2, [x1] | ||
37 | cbnz w0, 1b | ||
38 | ret | ||
39 | ENDPROC(\name ) | ||
40 | .endm | ||
41 | |||
42 | .macro testop, name, instr | ||
43 | ENTRY( \name ) | ||
44 | and x3, x0, #63 // Get bit offset | ||
45 | eor x0, x0, x3 // Clear low bits | ||
46 | mov x2, #1 | ||
47 | add x1, x1, x0, lsr #3 // Get word offset | ||
48 | lsl x4, x2, x3 // Create mask | ||
49 | smp_dmb ish | ||
50 | 1: ldxr x2, [x1] | ||
51 | lsr x0, x2, x3 // Save old value of bit | ||
52 | \instr x2, x2, x4 // toggle bit | ||
53 | stxr w2, x2, [x1] | ||
54 | cbnz w2, 1b | ||
55 | smp_dmb ish | ||
56 | and x0, x0, #1 | ||
57 | 3: ret | ||
58 | ENDPROC(\name ) | ||
59 | .endm | ||
60 | |||
61 | /* | ||
62 | * Atomic bit operations. | ||
63 | */ | ||
64 | bitop change_bit, eor | ||
65 | bitop clear_bit, bic | ||
66 | bitop set_bit, orr | ||
67 | |||
68 | testop test_and_change_bit, eor | ||
69 | testop test_and_clear_bit, bic | ||
70 | testop test_and_set_bit, orr | ||
diff --git a/arch/arm64/lib/bitops.c b/arch/arm64/lib/memchr.S index aa4965e60acc..8636b7549163 100644 --- a/arch/arm64/lib/bitops.c +++ b/arch/arm64/lib/memchr.S | |||
@@ -1,5 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2012 ARM Limited | 2 | * Based on arch/arm/lib/memchr.S |
3 | * | ||
4 | * Copyright (C) 1995-2000 Russell King | ||
5 | * Copyright (C) 2013 ARM Ltd. | ||
3 | * | 6 | * |
4 | * This program is free software; you can redistribute it and/or modify | 7 | * 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 | 8 | * it under the terms of the GNU General Public License version 2 as |
@@ -14,12 +17,28 @@ | |||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | */ | 18 | */ |
16 | 19 | ||
17 | #include <linux/kernel.h> | 20 | #include <linux/linkage.h> |
18 | #include <linux/spinlock.h> | 21 | #include <asm/assembler.h> |
19 | #include <linux/atomic.h> | ||
20 | 22 | ||
21 | #ifdef CONFIG_SMP | 23 | /* |
22 | arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned = { | 24 | * Find a character in an area of memory. |
23 | [0 ... (ATOMIC_HASH_SIZE-1)] = __ARCH_SPIN_LOCK_UNLOCKED | 25 | * |
24 | }; | 26 | * Parameters: |
25 | #endif | 27 | * x0 - buf |
28 | * x1 - c | ||
29 | * x2 - n | ||
30 | * Returns: | ||
31 | * x0 - address of first occurrence of 'c' or 0 | ||
32 | */ | ||
33 | ENTRY(memchr) | ||
34 | and w1, w1, #0xff | ||
35 | 1: 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 | ||
42 | 2: mov x0, #0 | ||
43 | ret | ||
44 | ENDPROC(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 | */ | ||
30 | ENTRY(memcpy) | ||
31 | mov x4, x0 | ||
32 | subs x2, x2, #8 | ||
33 | b.mi 2f | ||
34 | 1: ldr x3, [x1], #8 | ||
35 | subs x2, x2, #8 | ||
36 | str x3, [x4], #8 | ||
37 | b.pl 1b | ||
38 | 2: adds x2, x2, #4 | ||
39 | b.mi 3f | ||
40 | ldr w3, [x1], #4 | ||
41 | sub x2, x2, #4 | ||
42 | str w3, [x4], #4 | ||
43 | 3: adds x2, x2, #2 | ||
44 | b.mi 4f | ||
45 | ldrh w3, [x1], #2 | ||
46 | sub x2, x2, #2 | ||
47 | strh w3, [x4], #2 | ||
48 | 4: adds x2, x2, #1 | ||
49 | b.mi 5f | ||
50 | ldrb w3, [x1] | ||
51 | strb w3, [x4] | ||
52 | 5: ret | ||
53 | ENDPROC(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 | */ | ||
31 | ENTRY(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 | ||
38 | 1: ldr x3, [x1, #-8]! | ||
39 | subs x2, x2, #8 | ||
40 | str x3, [x4, #-8]! | ||
41 | b.pl 1b | ||
42 | 2: adds x2, x2, #4 | ||
43 | b.mi 3f | ||
44 | ldr w3, [x1, #-4]! | ||
45 | sub x2, x2, #4 | ||
46 | str w3, [x4, #-4]! | ||
47 | 3: adds x2, x2, #2 | ||
48 | b.mi 4f | ||
49 | ldrh w3, [x1, #-2]! | ||
50 | sub x2, x2, #2 | ||
51 | strh w3, [x4, #-2]! | ||
52 | 4: adds x2, x2, #1 | ||
53 | b.mi 5f | ||
54 | ldrb w3, [x1, #-1] | ||
55 | strb w3, [x4, #-1] | ||
56 | 5: ret | ||
57 | ENDPROC(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 | */ | ||
30 | ENTRY(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 | ||
38 | 1: str x1, [x4], #8 | ||
39 | subs x2, x2, #8 | ||
40 | b.pl 1b | ||
41 | 2: adds x2, x2, #4 | ||
42 | b.mi 3f | ||
43 | sub x2, x2, #4 | ||
44 | str w1, [x4], #4 | ||
45 | 3: adds x2, x2, #2 | ||
46 | b.mi 4f | ||
47 | sub x2, x2, #2 | ||
48 | strh w1, [x4], #2 | ||
49 | 4: adds x2, x2, #1 | ||
50 | b.mi 5f | ||
51 | strb w1, [x4] | ||
52 | 5: ret | ||
53 | ENDPROC(memset) | ||
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 | */ | ||
32 | ENTRY(strchr) | ||
33 | and w1, w1, #0xff | ||
34 | 1: 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 | ||
42 | ENDPROC(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 | */ | ||
32 | ENTRY(strrchr) | ||
33 | mov x3, #0 | ||
34 | and w1, w1, #0xff | ||
35 | 1: ldrb w2, [x0], #1 | ||
36 | cbz w2, 2f | ||
37 | cmp w2, w1 | ||
38 | b.ne 1b | ||
39 | sub x3, x0, #1 | ||
40 | b 1b | ||
41 | 2: mov x0, x3 | ||
42 | ret | ||
43 | ENDPROC(strrchr) | ||