summaryrefslogtreecommitdiffstats
path: root/arch/openrisc
diff options
context:
space:
mode:
authorOlof Kindgren <olof.kindgren@gmail.com>2015-02-06 07:41:51 -0500
committerStafford Horne <shorne@gmail.com>2017-02-24 14:14:35 -0500
commitd857a1e253498feb231173218df26f5562c70f09 (patch)
tree4d7c67c6d2c648d52a83f68e5ebaa3882c791073 /arch/openrisc
parente29d11c6991d078bf2011f25dc8c19a2f38c4c8e (diff)
openrisc: Add optimized memset
This adds a hand-optimized assembler version of memset and sets __HAVE_ARCH_MEMSET to use this version instead of the generic C routine Signed-off-by: Olof Kindgren <olof.kindgren@gmail.com> Signed-off-by: Stafford Horne <shorne@gmail.com>
Diffstat (limited to 'arch/openrisc')
-rw-r--r--arch/openrisc/include/asm/string.h7
-rw-r--r--arch/openrisc/kernel/or32_ksyms.c1
-rw-r--r--arch/openrisc/lib/Makefile2
-rw-r--r--arch/openrisc/lib/memset.S98
4 files changed, 107 insertions, 1 deletions
diff --git a/arch/openrisc/include/asm/string.h b/arch/openrisc/include/asm/string.h
new file mode 100644
index 000000000000..33470d4d6948
--- /dev/null
+++ b/arch/openrisc/include/asm/string.h
@@ -0,0 +1,7 @@
1#ifndef __ASM_OPENRISC_STRING_H
2#define __ASM_OPENRISC_STRING_H
3
4#define __HAVE_ARCH_MEMSET
5extern void *memset(void *s, int c, __kernel_size_t n);
6
7#endif /* __ASM_OPENRISC_STRING_H */
diff --git a/arch/openrisc/kernel/or32_ksyms.c b/arch/openrisc/kernel/or32_ksyms.c
index 86e31cf1de1d..5c4695d13542 100644
--- a/arch/openrisc/kernel/or32_ksyms.c
+++ b/arch/openrisc/kernel/or32_ksyms.c
@@ -44,3 +44,4 @@ DECLARE_EXPORT(__ashldi3);
44DECLARE_EXPORT(__lshrdi3); 44DECLARE_EXPORT(__lshrdi3);
45 45
46EXPORT_SYMBOL(__copy_tofrom_user); 46EXPORT_SYMBOL(__copy_tofrom_user);
47EXPORT_SYMBOL(memset);
diff --git a/arch/openrisc/lib/Makefile b/arch/openrisc/lib/Makefile
index 966f65dbc6f0..67c583e0617f 100644
--- a/arch/openrisc/lib/Makefile
+++ b/arch/openrisc/lib/Makefile
@@ -2,4 +2,4 @@
2# Makefile for or32 specific library files.. 2# Makefile for or32 specific library files..
3# 3#
4 4
5obj-y = string.o delay.o 5obj-y = memset.o string.o delay.o
diff --git a/arch/openrisc/lib/memset.S b/arch/openrisc/lib/memset.S
new file mode 100644
index 000000000000..92cc2eac26fa
--- /dev/null
+++ b/arch/openrisc/lib/memset.S
@@ -0,0 +1,98 @@
1/*
2 * OpenRISC memset.S
3 *
4 * Hand-optimized assembler version of memset for OpenRISC.
5 * Algorithm inspired by several other arch-specific memset routines
6 * in the kernel tree
7 *
8 * Copyright (C) 2015 Olof Kindgren <olof.kindgren@gmail.com>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 */
15
16 .global memset
17 .type memset, @function
18memset:
19 /* arguments:
20 * r3 = *s
21 * r4 = c
22 * r5 = n
23 * r13, r15, r17, r19 used as temp regs
24 */
25
26 /* Exit if n == 0 */
27 l.sfeqi r5, 0
28 l.bf 4f
29
30 /* Truncate c to char */
31 l.andi r13, r4, 0xff
32
33 /* Skip word extension if c is 0 */
34 l.sfeqi r13, 0
35 l.bf 1f
36 /* Check for at least two whole words (8 bytes) */
37 l.sfleui r5, 7
38
39 /* Extend char c to 32-bit word cccc in r13 */
40 l.slli r15, r13, 16 // r13 = 000c, r15 = 0c00
41 l.or r13, r13, r15 // r13 = 0c0c, r15 = 0c00
42 l.slli r15, r13, 8 // r13 = 0c0c, r15 = c0c0
43 l.or r13, r13, r15 // r13 = cccc, r15 = c0c0
44
451: l.addi r19, r3, 0 // Set r19 = src
46 /* Jump to byte copy loop if less than two words */
47 l.bf 3f
48 l.or r17, r5, r0 // Set r17 = n
49
50 /* Mask out two LSBs to check alignment */
51 l.andi r15, r3, 0x3
52
53 /* lsb == 00, jump to word copy loop */
54 l.sfeqi r15, 0
55 l.bf 2f
56 l.addi r19, r3, 0 // Set r19 = src
57
58 /* lsb == 01,10 or 11 */
59 l.sb 0(r3), r13 // *src = c
60 l.addi r17, r17, -1 // Decrease n
61
62 l.sfeqi r15, 3
63 l.bf 2f
64 l.addi r19, r3, 1 // src += 1
65
66 /* lsb == 01 or 10 */
67 l.sb 1(r3), r13 // *(src+1) = c
68 l.addi r17, r17, -1 // Decrease n
69
70 l.sfeqi r15, 2
71 l.bf 2f
72 l.addi r19, r3, 2 // src += 2
73
74 /* lsb == 01 */
75 l.sb 2(r3), r13 // *(src+2) = c
76 l.addi r17, r17, -1 // Decrease n
77 l.addi r19, r3, 3 // src += 3
78
79 /* Word copy loop */
802: l.sw 0(r19), r13 // *src = cccc
81 l.addi r17, r17, -4 // Decrease n
82 l.sfgeui r17, 4
83 l.bf 2b
84 l.addi r19, r19, 4 // Increase src
85
86 /* When n > 0, copy the remaining bytes, otherwise jump to exit */
87 l.sfeqi r17, 0
88 l.bf 4f
89
90 /* Byte copy loop */
913: l.addi r17, r17, -1 // Decrease n
92 l.sb 0(r19), r13 // *src = cccc
93 l.sfnei r17, 0
94 l.bf 3b
95 l.addi r19, r19, 1 // Increase src
96
974: l.jr r9
98 l.ori r11, r3, 0