2.9
[glibc/nacl-glibc.git] / sysdeps / sh / strlen.S
blobe25d7ef5eccc6c0dff1e27d15328f7ee30f00e20
1 /* Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Kazumoto Kojima <kkojima@rr.iij4u.or.jp>
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep.h>
21 #include <endian.h>
23 /* size_t strlen (const char *s)  */
25 ENTRY(strlen)
26         mov     r4, r0
27         and     #3, r0
28         tst     r0, r0
29         bt/s    1f
30         mov     #0, r2
32         add     #-1, r0
33         shll2   r0
34         shll    r0
35         braf    r0
36         nop
38         mov.b   @r4+, r1
39         tst     r1, r1
40         bt      8f
41         add     #1, r2  
43         mov.b   @r4+, r1
44         tst     r1, r1
45         bt      8f
46         add     #1, r2  
48         mov.b   @r4+, r1
49         tst     r1, r1
50         bt      8f
51         add     #1, r2  
54         mov     #0, r3
56         mov.l   @r4+, r1
57         cmp/str r3, r1
58         bf/s    2b
59         add     #4, r2
61         add     #-4, r2
62 #if __BYTE_ORDER == __BIG_ENDIAN
63         swap.b  r1, r1
64         swap.w  r1, r1
65         swap.b  r1, r1
66 #endif
67         extu.b  r1, r0
68         tst     r0, r0
69         bt/s    8f
70         shlr8   r1
71         add     #1, r2
72         extu.b  r1, r0
73         tst     r0, r0
74         bt/s    8f
75         shlr8   r1
76         add     #1, r2
77         extu.b  r1, r0
78         tst     r0, r0
79         bt      8f
80         add     #1, r2
82         rts
83         mov     r2, r0
84 END(strlen)
85 libc_hidden_builtin_def (strlen)