xref: /freebsd/lib/libc/arm/string/strlen.S (revision 6c5bc49c5a803101b52861068594eacf6775e08c)
13507a157SOlivier Houchard/*-
23507a157SOlivier Houchard * Copyright (c) 2005 Olivier Houchard
33507a157SOlivier Houchard * All rights reserved.
43507a157SOlivier Houchard *
53507a157SOlivier Houchard * Redistribution and use in source and binary forms, with or without
63507a157SOlivier Houchard * modification, are permitted provided that the following conditions
73507a157SOlivier Houchard * are met:
8dc9e655cSOlivier Houchard * 1. Redistributions of source code must retain the above copyright
9dc9e655cSOlivier Houchard *    notice, this list of conditions and the following disclaimer.
103507a157SOlivier Houchard * 2. Redistributions in binary form must reproduce the above copyright
113507a157SOlivier Houchard *    notice, this list of conditions and the following disclaimer in the
123507a157SOlivier Houchard *    documentation and/or other materials provided with the distribution.
133507a157SOlivier Houchard *
143507a157SOlivier Houchard * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
153507a157SOlivier Houchard * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
163507a157SOlivier Houchard * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
173507a157SOlivier Houchard * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
183507a157SOlivier Houchard * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
193507a157SOlivier Houchard * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
203507a157SOlivier Houchard * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
213507a157SOlivier Houchard * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
223507a157SOlivier Houchard * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
233507a157SOlivier Houchard * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
243507a157SOlivier Houchard * SUCH DAMAGE.
253507a157SOlivier Houchard */
263507a157SOlivier Houchard
273507a157SOlivier Houchard#include <machine/asm.h>
283507a157SOlivier Houchard__FBSDID("$FreeBSD$");
293507a157SOlivier Houchard
30a215cdfdSAndrew Turner.syntax	unified
31a215cdfdSAndrew Turner
323507a157SOlivier HouchardENTRY(strlen)
333507a157SOlivier Houchard	mov	r1, #0
343507a157SOlivier Houchard	/* Check that the pointer is aligned on 32 bits. */
353507a157SOlivier Houchard	ands	r3, r0, #3
363507a157SOlivier Houchard	beq	.Loop
373507a157SOlivier Houchard	sub	r0, r0, r3
383507a157SOlivier Houchard	ldr	r2, [r0]
393507a157SOlivier Houchard	add	r0, r0, #4
403507a157SOlivier Houchard	cmp	r3, #2
413507a157SOlivier Houchard	blt	.Ldo_3
423507a157SOlivier Houchard	bgt	.Ldo_1
433507a157SOlivier Houchard	/* So that the N bit is set. */
443507a157SOlivier Houchard	cmp	r3, #0
453507a157SOlivier Houchard	b	.Ldo_2
463507a157SOlivier Houchard
473507a157SOlivier Houchard.Loop:
483507a157SOlivier Houchard	ldr	r2, [r0]
493507a157SOlivier Houchard	add	r0, r0, #4
503507a157SOlivier Houchard#ifndef __ARMEB__
513507a157SOlivier Houchard	ands	r3, r2, #0x000000ff
523507a157SOlivier Houchard#else
533507a157SOlivier Houchard	ands	r3, r2, #0xff000000
543507a157SOlivier Houchard#endif
55*6c5bc49cSAndrew Turner	it	ne
563507a157SOlivier Houchard	addne	r1, r1, #1
573507a157SOlivier Houchard.Ldo_3:
58*6c5bc49cSAndrew Turner	itt	ne
593507a157SOlivier Houchard#ifndef __ARMEB__
60a215cdfdSAndrew Turner	andsne    r3, r2, #0x0000ff00
613507a157SOlivier Houchard#else
62a215cdfdSAndrew Turner  	andsne    r3, r2, #0x00ff0000
633507a157SOlivier Houchard#endif
643507a157SOlivier Houchard	addne     r1, r1, #1
653507a157SOlivier Houchard.Ldo_2:
66*6c5bc49cSAndrew Turner	itt	ne
673507a157SOlivier Houchard#ifndef __ARMEB__
68a215cdfdSAndrew Turner	andsne    r3, r2, #0x00ff0000
693507a157SOlivier Houchard#else
70a215cdfdSAndrew Turner	andsne    r3, r2, #0x0000ff00
713507a157SOlivier Houchard#endif
723507a157SOlivier Houchard	addne	r1, r1, #1
733507a157SOlivier Houchard.Ldo_1:
74*6c5bc49cSAndrew Turner	ittt	ne
753507a157SOlivier Houchard#ifndef __ARMEB__
76a215cdfdSAndrew Turner	andsne	r3, r2, #0xff000000
773507a157SOlivier Houchard#else
78a215cdfdSAndrew Turner	andsne	r3, r2, #0x000000ff
793507a157SOlivier Houchard#endif
803507a157SOlivier Houchard	addne	r1, r1, #1
813507a157SOlivier Houchard	bne	.Loop
823507a157SOlivier Houchard.Lexit:
833507a157SOlivier Houchard	mov	r0, r1
843507a157SOlivier Houchard	RET
85f2e71517SIan LeporeEND(strlen)
86