2 * memset - fill memory with a constant
4 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 * See https://llvm.org/LICENSE.txt for license information.
6 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10 Written by Dave Gilbert <david.gilbert@linaro.org>
12 This memset routine is optimised on a Cortex-A9 and should work on
20 @ 2011-08-30 david.gilbert@linaro.org
21 @ Extracted from local git 2f11b436
23 @ this lets us check a flag in a 00/ff byte easily in either endianness
25 #define CHARTSTMASK(c) 1<<(31-(c*8))
27 #define CHARTSTMASK(c) 1<<(c*8)
32 @ ---------------------------------------------------------------------------
37 .type __memset_arm,%function
42 @ returns original address in r0
44 mov r3, r0 @ Leave r0 alone
45 cbz r2, 10f @ Exit if 0 length
48 beq 2f @ Already aligned
50 @ Ok, so we're misaligned here
55 cbz r2, 10f @ Exit if we hit the end
56 bne 1b @ go round again if still misaligned
59 @ OK, so we're aligned
61 bics r4, r2, #15 @ if less than 16 bytes then need to finish it off
65 @ POSIX says that ch is cast to an unsigned char. A uxtb is one
66 @ byte and takes two cycles, where an AND is four bytes but one
69 orr r1, r1, r1, lsl#8 @ Same character into all bytes
70 orr r1, r1, r1, lsl#16
77 stmia r3!,{r1,r5,r6,r7}
81 @ At this point we're still aligned and we have upto align-1 bytes left to right
82 @ we can avoid some of the byte-at-a time now by testing for some big chunks
92 @ Got to do any last < alignment bytes
100 .size __memset_arm, . - __memset_arm