1/* Copyright (C) 1999-2022 Free Software Foundation, Inc.
2   This file is part of the GNU C Library.
3
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.
8
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.
13
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/>.  */
17
18#include <sysdep.h>
19
20/* size_t strlen (const char *s)  */
21
22ENTRY(strlen)
23	mov	r4, r0
24	and	#3, r0
25	tst	r0, r0
26	bt/s	1f
27	mov	#0, r2
28
29	add	#-1, r0
30	shll2	r0
31	shll	r0
32	braf	r0
33	nop
34
35	mov.b	@r4+, r1
36	tst	r1, r1
37	bt	8f
38	add	#1, r2
39
40	mov.b	@r4+, r1
41	tst	r1, r1
42	bt	8f
43	add	#1, r2
44
45	mov.b	@r4+, r1
46	tst	r1, r1
47	bt	8f
48	add	#1, r2
49
501:
51	mov	#0, r3
522:
53	mov.l	@r4+, r1
54	cmp/str	r3, r1
55	bf/s	2b
56	add	#4, r2
57
58	add	#-4, r2
59#ifdef __BIG_ENDIAN__
60	swap.b	r1, r1
61	swap.w	r1, r1
62	swap.b	r1, r1
63#endif
64	extu.b	r1, r0
65	tst	r0, r0
66	bt/s	8f
67	shlr8	r1
68	add	#1, r2
69	extu.b	r1, r0
70	tst	r0, r0
71	bt/s	8f
72	shlr8	r1
73	add	#1, r2
74	extu.b	r1, r0
75	tst	r0, r0
76	bt	8f
77	add	#1, r2
788:
79	rts
80	mov	r2, r0
81END(strlen)
82libc_hidden_builtin_def (strlen)
83