1/*
2 * Copyright (C) 2004-2007 Atmel Corporation
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser General
5 * Public License.  See the file "COPYING.LIB" in the main directory of this
6 * archive for more details.
7 */
8
9#include <features.h>
10
11#define str r12
12
13	.text
14	.global strlen
15	.type	strlen, @function
16strlen:
17	mov	r11, r12
18
19	mov	r9, str
20	andl	r9, 3, COH
21	brne	.Lunaligned_str
22
231:	ld.w	r8, str++
24	tnbz	r8
25	brne	1b
26
27	sub	r12, r11
28	bfextu	r9, r8, 24, 8
29	cp.w	r9, 0
30	subeq	r12, 4
31	reteq	r12
32	bfextu	r9, r8, 16, 8
33	cp.w	r9, 0
34	subeq	r12, 3
35	reteq	r12
36	bfextu	r9, r8, 8, 8
37	cp.w	r9, 0
38	subeq	r12, 2
39	reteq	r12
40	sub	r12, 1
41	retal	r12
42
43.Lunaligned_str:
44	add	pc, pc, r9 << 3
45	sub	r0, r0, 0	/* 4-byte nop */
46	ld.ub	r8, str++
47	sub	r8, r8, 0
48	breq	1f
49	ld.ub	r8, str++
50	sub	r8, r8, 0
51	breq	1f
52	ld.ub	r8, str++
53	sub	r8, r8, 0
54	brne	1b
55
561:	sub	r12, 1
57	sub	r12, r11
58	retal	r12
59
60	.size	strlen, . - strlen
61
62libc_hidden_def(strlen)
63