2 * linux/arch/arm/lib/memset.S
4 * Copyright (C) 1995-2000 Russell King
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.
10 * ASM optimised string functions
12 #include <linux/linkage.h>
13 #include <asm/assembler.h>
19 #if CONFIG_IS_ENABLED(SYS_THUMB_BUILD) && !defined(MEMSET_NO_THUMB_BUILD)
24 ands r3, r0, #3 @ 1 unaligned?
25 mov ip, r0 @ preserve r0 as return value
28 * we know that the pointer in ip is aligned to a word boundary.
30 1: orr r1, r1, r1, lsl #8
31 orr r1, r1, r1, lsl #16
39 * We need 2 extra registers for this loop - use r8 and the LR
46 stmiage ip!, {r1, r3, r8, lr} @ 64 bytes at a time.
47 stmiage ip!, {r1, r3, r8, lr}
48 stmiage ip!, {r1, r3, r8, lr}
49 stmiage ip!, {r1, r3, r8, lr}
51 ldmfdeq sp!, {r8, pc} @ Now <64 bytes to go.
53 * No need to correct the count; we're only testing bits from now on
56 stmiane ip!, {r1, r3, r8, lr}
57 stmiane ip!, {r1, r3, r8, lr}
59 stmiane ip!, {r1, r3, r8, lr}
65 * This version aligns the destination pointer in order to write
66 * whole cache lines at once.
69 stmfd sp!, {r4-r8, lr}
84 movs r8, r8, lsl #(32 - 4)
85 stmiacs ip!, {r4, r5, r6, r7}
92 stmiage ip!, {r1, r3-r8, lr}
93 stmiage ip!, {r1, r3-r8, lr}
95 ldmfdeq sp!, {r4-r8, pc}
98 stmiane ip!, {r1, r3-r8, lr}
101 ldmfd sp!, {r4-r8, lr}
106 stmiane ip!, {r1, r3}
110 * When we get here, we've got less than 4 bytes to zero. We
111 * may have an unaligned pointer as well.
120 6: subs r2, r2, #4 @ 1 do we have enough
121 blt 5b @ 1 bytes to align with?
123 strblt r1, [ip], #1 @ 1
124 strble r1, [ip], #1 @ 1
125 strb r1, [ip], #1 @ 1
126 add r2, r2, r3 @ 1 (r2 = r2 - (4 - r3))