strlen.S revision 150875
1221337Sdim/*-
2221337Sdim * Copyright (c) 2005 Olivier Houchard
3221337Sdim * All rights reserved.
4221337Sdim *
5221337Sdim * Redistribution and use in source and binary forms, with or without
6221337Sdim * modification, are permitted provided that the following conditions
7221337Sdim * are met:
8221337Sdim * 1. Redistributions of source code must retain the above copyright             *    notice, this list of conditions and the following disclaimer.
9221337Sdim * 2. Redistributions in binary form must reproduce the above copyright
10223017Sdim *    notice, this list of conditions and the following disclaimer in the
11221337Sdim *    documentation and/or other materials provided with the distribution.
12221337Sdim *
13221337Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14221337Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15221337Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16223017Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17221337Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18223017Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19221337Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20221337Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21221337Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22234353Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23234353Sdim * SUCH DAMAGE.
24234353Sdim */
25234353Sdim
26234353Sdim#include <machine/asm.h>
27234353Sdim__FBSDID("$FreeBSD: head/lib/libc/arm/string/strlen.S 150875 2005-10-03 14:21:49Z cognet $");
28234353Sdim
29221337SdimENTRY(strlen)
30221337Sdim	mov	r1, #0
31221337Sdim	/* Check that the pointer is aligned on 32 bits. */
32221337Sdim	ands	r3, r0, #3
33221337Sdim	beq	.Loop
34221337Sdim	sub	r0, r0, r3
35221337Sdim	ldr	r2, [r0]
36221337Sdim	add	r0, r0, #4
37221337Sdim	cmp	r3, #2
38221337Sdim	blt	.Ldo_3
39221337Sdim	bgt	.Ldo_1
40221337Sdim	/* So that the N bit is set. */
41221337Sdim	cmp	r3, #0
42221337Sdim	b	.Ldo_2
43221337Sdim
44221337Sdim.Loop:
45263508Sdim	ldr	r2, [r0]
46221337Sdim	add	r0, r0, #4
47221337Sdim#ifndef __ARMEB__
48223017Sdim	ands	r3, r2, #0x000000ff
49221337Sdim#else
50223017Sdim	ands	r3, r2, #0xff000000
51223017Sdim#endif
52223017Sdim	addne	r1, r1, #1
53221337Sdim.Ldo_3:
54221337Sdim#ifndef __ARMEB__
55221337Sdim	andnes    r3, r2, #0x0000ff00
56221337Sdim#else
57221337Sdim  	andnes    r3, r2, #0x00ff0000
58221337Sdim#endif
59221337Sdim	addne     r1, r1, #1
60221337Sdim.Ldo_2:
61263508Sdim#ifndef __ARMEB__
62221337Sdim	andnes    r3, r2, #0x00ff0000
63221337Sdim#else
64221337Sdim	andnes    r3, r2, #0x0000ff00
65221337Sdim#endif
66221337Sdim	addne	r1, r1, #1
67221337Sdim.Ldo_1:
68221337Sdim#ifndef __ARMEB__
69221337Sdim	andnes	r3, r2, #0xff000000
70221337Sdim#else
71221337Sdim	andnes	r3, r2, #0x000000ff
72221337Sdim#endif
73221337Sdim	addne	r1, r1, #1
74221337Sdim	bne	.Loop
75223017Sdim.Lexit:
76226633Sdim	mov	r0, r1
77223017Sdim	RET
78221337Sdim