1 /* Copyright (c) 2010-2011, Linaro Limited
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
15 * Neither the name of Linaro Limited nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 Written by Dave Gilbert <david.gilbert@linaro.org>
35 This memset routine is optimised on a Cortex-A9 and should work on
43 @ 2011-08-30 david.gilbert@linaro.org
44 @ Extracted from local git 2f11b436
46 @ this lets us check a flag in a 00/ff byte easily in either endianness
48 #define CHARTSTMASK(c) 1<<(31-(c*8))
50 #define CHARTSTMASK(c) 1<<(c*8)
55 @ ---------------------------------------------------------------------------
60 .type memset,%function
65 @ returns original address in r0
67 mov r3, r0 @ Leave r0 alone
68 cbz r2, 10f @ Exit if 0 length
71 beq 2f @ Already aligned
73 @ Ok, so we're misaligned here
78 cbz r2, 10f @ Exit if we hit the end
79 bne 1b @ go round again if still misaligned
82 @ OK, so we're aligned
84 bics r4, r2, #15 @ if less than 16 bytes then need to finish it off
88 @ POSIX says that ch is cast to an unsigned char. A uxtb is one
89 @ byte and takes two cycles, where an AND is four bytes but one
92 orr r1, r1, r1, lsl#8 @ Same character into all bytes
93 orr r1, r1, r1, lsl#16
100 stmia r3!,{r1,r5,r6,r7}
104 @ At this point we're still aligned and we have upto align-1 bytes left to right
105 @ we can avoid some of the byte-at-a time now by testing for some big chunks
115 @ Got to do any last < alignment bytes