1150875Scognet/*-
2150875Scognet * Copyright (c) 2005 Olivier Houchard
3150875Scognet * All rights reserved.
4150875Scognet *
5150875Scognet * Redistribution and use in source and binary forms, with or without
6150875Scognet * modification, are permitted provided that the following conditions
7150875Scognet * are met:
8150877Scognet * 1. Redistributions of source code must retain the above copyright
9150877Scognet *    notice, this list of conditions and the following disclaimer.
10150875Scognet * 2. Redistributions in binary form must reproduce the above copyright
11150875Scognet *    notice, this list of conditions and the following disclaimer in the
12150875Scognet *    documentation and/or other materials provided with the distribution.
13150875Scognet *
14150875Scognet * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15150875Scognet * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16150875Scognet * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17150875Scognet * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18150875Scognet * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19150875Scognet * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20150875Scognet * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21150875Scognet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22150875Scognet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23150875Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24150875Scognet * SUCH DAMAGE.
25150875Scognet */
26150875Scognet
27150875Scognet#include <machine/asm.h>
28150875Scognet__FBSDID("$FreeBSD$");
29150875Scognet
30275767Sandrew.syntax	unified
31275767Sandrew
32150875ScognetENTRY(strlen)
33150875Scognet	mov	r1, #0
34150875Scognet	/* Check that the pointer is aligned on 32 bits. */
35150875Scognet	ands	r3, r0, #3
36150875Scognet	beq	.Loop
37150875Scognet	sub	r0, r0, r3
38150875Scognet	ldr	r2, [r0]
39150875Scognet	add	r0, r0, #4
40150875Scognet	cmp	r3, #2
41150875Scognet	blt	.Ldo_3
42150875Scognet	bgt	.Ldo_1
43150875Scognet	/* So that the N bit is set. */
44150875Scognet	cmp	r3, #0
45150875Scognet	b	.Ldo_2
46150875Scognet
47150875Scognet.Loop:
48150875Scognet	ldr	r2, [r0]
49150875Scognet	add	r0, r0, #4
50150875Scognet#ifndef __ARMEB__
51150875Scognet	ands	r3, r2, #0x000000ff
52150875Scognet#else
53150875Scognet	ands	r3, r2, #0xff000000
54150875Scognet#endif
55150875Scognet	addne	r1, r1, #1
56150875Scognet.Ldo_3:
57150875Scognet#ifndef __ARMEB__
58275767Sandrew	andsne    r3, r2, #0x0000ff00
59150875Scognet#else
60275767Sandrew  	andsne    r3, r2, #0x00ff0000
61150875Scognet#endif
62150875Scognet	addne     r1, r1, #1
63150875Scognet.Ldo_2:
64150875Scognet#ifndef __ARMEB__
65275767Sandrew	andsne    r3, r2, #0x00ff0000
66150875Scognet#else
67275767Sandrew	andsne    r3, r2, #0x0000ff00
68150875Scognet#endif
69150875Scognet	addne	r1, r1, #1
70150875Scognet.Ldo_1:
71150875Scognet#ifndef __ARMEB__
72275767Sandrew	andsne	r3, r2, #0xff000000
73150875Scognet#else
74275767Sandrew	andsne	r3, r2, #0x000000ff
75150875Scognet#endif
76150875Scognet	addne	r1, r1, #1
77150875Scognet	bne	.Loop
78150875Scognet.Lexit:
79150875Scognet	mov	r0, r1
80150875Scognet	RET
81271337SianEND(strlen)
82