Update copyright dates with scripts/update-copyrights
[glibc.git] / sysdeps / arm / strlen.S
blob4e2cd426ebb7c274dbd8ad4be0828743c66bfc4c
1 /* Copyright (C) 1998-2023 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library.  If not, see
16    <https://www.gnu.org/licenses/>.  */
18 /* Thumb requires excessive IT insns here.  */
19 #define NO_THUMB
20 #include <sysdep.h>
22 /* size_t strlen(const char *S)
23  * entry: r0 -> string
24  * exit: r0 = len
25  */
27         .syntax unified
28         .text
30 ENTRY(strlen)
31         bic     r1, r0, $3              @ addr of word containing first byte
32         ldr     r2, [r1], $4            @ get the first word
33         ands    r3, r0, $3              @ how many bytes are duff?
34         rsb     r0, r3, $0              @ get - that number into counter.
35         beq     Laligned                @ skip into main check routine if no
36                                         @ more
37 #ifdef __ARMEB__
38         orr     r2, r2, $0xff000000     @ set this byte to non-zero
39         subs    r3, r3, $1              @ any more to do?
40         orrgt   r2, r2, $0x00ff0000     @ if so, set this byte
41         subs    r3, r3, $1              @ more?
42         orrgt   r2, r2, $0x0000ff00     @ then set.
43 #else
44         orr     r2, r2, $0x000000ff     @ set this byte to non-zero
45         subs    r3, r3, $1              @ any more to do?
46         orrgt   r2, r2, $0x0000ff00     @ if so, set this byte
47         subs    r3, r3, $1              @ more?
48         orrgt   r2, r2, $0x00ff0000     @ then set.
49 #endif
50 Laligned:                               @ here, we have a word in r2.  Does it
51         tst     r2, $0x000000ff         @ contain any zeroes?
52         tstne   r2, $0x0000ff00         @
53         tstne   r2, $0x00ff0000         @
54         tstne   r2, $0xff000000         @
55         addne   r0, r0, $4              @ if not, the string is 4 bytes longer
56         ldrne   r2, [r1], $4            @ and we continue to the next word
57         bne     Laligned                @
58 Llastword:                              @ drop through to here once we find a
59 #ifdef __ARMEB__
60         tst     r2, $0xff000000         @ word that has a zero byte in it
61         addne   r0, r0, $1              @
62         tstne   r2, $0x00ff0000         @ and add up to 3 bytes on to it
63         addne   r0, r0, $1              @
64         tstne   r2, $0x0000ff00         @ (if first three all non-zero, 4th
65         addne   r0, r0, $1              @  must be zero)
66 #else
67         tst     r2, $0x000000ff         @ word that has a zero byte in it
68         addne   r0, r0, $1              @
69         tstne   r2, $0x0000ff00         @ and add up to 3 bytes on to it
70         addne   r0, r0, $1              @
71         tstne   r2, $0x00ff0000         @ (if first three all non-zero, 4th
72         addne   r0, r0, $1              @  must be zero)
73 #endif
74         DO_RET(lr)
75 END(strlen)
76 libc_hidden_builtin_def (strlen)