4
@ Copyright (c) 2010-2011, Linaro Limited
7
@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9
@ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10
@ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
@ * Neither the name of Linaro Limited nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13
@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
@ Written by Dave Gilbert <david.gilbert@linaro.org>
17
@ This strlen routine is optimised on a Cortex-A9 and should work on all ARMv7
18
@ processors. This routine is reasonably fast for short strings, but is
19
@ probably slower than a simple implementation if all your strings are very short
21
@ 2011-02-08 david.gilbert@linaro.org
22
@ Extracted from local git 6848613a
25
@-----------------------------------------------------------------------------------------------------------------------------
30
.type strlen,%function
33
@ returns count of bytes in string not including terminator
43
tst r1, #7 @ Hit alignment yet?
44
cbz r2, 10f @ Exit if we found the 0
47
@ So we're now aligned
50
uadd8 r2, r2, r6 @ Parallel add 0xff - sets the GE bits for anything that wasn't 0
51
sel r2, r4, r6 @ bytes are 00 for none-00 bytes, or ff for 00 bytes - NOTE INVERSION
52
uadd8 r3, r3, r6 @ Parallel add 0xff - sets the GE bits for anything that wasn't 0
53
sel r3, r2, r6 @ bytes are 00 for none-00 bytes, or ff for 00 bytes - NOTE INVERSION
58
@ One (or more) of the bytes we loaded was 0 - but which one?
59
@ r2 has the mask corresponding to the first loaded word
60
@ r3 has a combined mask of the two words - but if r2 was all-non 0
61
@ then it's just the 2nd words
64
moveq r2, r3 @ the end is in the 2nd word
68
@ r1 currently points to the 2nd byte of the word containing the 0
69
tst r2, # (1<<0) @ 1st character
72
tst r2, # (1<<8) @ 2nd character
75
tsteq r2, # (3<<15) @ 2nd & 3rd character
76
@ If not the 3rd must be the last one
80
@ r0 is still at the beginning, r1 is pointing 1 byte after the terminator