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> 28a215cdfdSAndrew Turner.syntax unified 29a215cdfdSAndrew Turner 303507a157SOlivier HouchardENTRY(strlen) 313507a157SOlivier Houchard mov r1, #0 323507a157SOlivier Houchard /* Check that the pointer is aligned on 32 bits. */ 333507a157SOlivier Houchard ands r3, r0, #3 343507a157SOlivier Houchard beq .Loop 353507a157SOlivier Houchard sub r0, r0, r3 363507a157SOlivier Houchard ldr r2, [r0] 373507a157SOlivier Houchard add r0, r0, #4 383507a157SOlivier Houchard cmp r3, #2 393507a157SOlivier Houchard blt .Ldo_3 403507a157SOlivier Houchard bgt .Ldo_1 413507a157SOlivier Houchard /* So that the N bit is set. */ 423507a157SOlivier Houchard cmp r3, #0 433507a157SOlivier Houchard b .Ldo_2 443507a157SOlivier Houchard 453507a157SOlivier Houchard.Loop: 463507a157SOlivier Houchard ldr r2, [r0] 473507a157SOlivier Houchard add r0, r0, #4 483507a157SOlivier Houchard ands r3, r2, #0x000000ff 496c5bc49cSAndrew Turner it ne 503507a157SOlivier Houchard addne r1, r1, #1 513507a157SOlivier Houchard.Ldo_3: 526c5bc49cSAndrew Turner itt ne 53a215cdfdSAndrew Turner andsne r3, r2, #0x0000ff00 543507a157SOlivier Houchard addne r1, r1, #1 553507a157SOlivier Houchard.Ldo_2: 566c5bc49cSAndrew Turner itt ne 57a215cdfdSAndrew Turner andsne r3, r2, #0x00ff0000 583507a157SOlivier Houchard addne r1, r1, #1 593507a157SOlivier Houchard.Ldo_1: 606c5bc49cSAndrew Turner ittt ne 61a215cdfdSAndrew Turner andsne r3, r2, #0xff000000 623507a157SOlivier Houchard addne r1, r1, #1 633507a157SOlivier Houchard bne .Loop 643507a157SOlivier Houchard.Lexit: 653507a157SOlivier Houchard mov r0, r1 663507a157SOlivier Houchard RET 67f2e71517SIan LeporeEND(strlen) 68*96cdb0abSKonstantin Belousov 69*96cdb0abSKonstantin Belousov .section .note.GNU-stack,"",%progbits 70