strlen.S revision 271337
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: stable/10/lib/libc/arm/string/strlen.S 271337 2014-09-09 22:24:01Z ian $"); 29150875Scognet 30150875ScognetENTRY(strlen) 31150875Scognet mov r1, #0 32150875Scognet /* Check that the pointer is aligned on 32 bits. */ 33150875Scognet ands r3, r0, #3 34150875Scognet beq .Loop 35150875Scognet sub r0, r0, r3 36150875Scognet ldr r2, [r0] 37150875Scognet add r0, r0, #4 38150875Scognet cmp r3, #2 39150875Scognet blt .Ldo_3 40150875Scognet bgt .Ldo_1 41150875Scognet /* So that the N bit is set. */ 42150875Scognet cmp r3, #0 43150875Scognet b .Ldo_2 44150875Scognet 45150875Scognet.Loop: 46150875Scognet ldr r2, [r0] 47150875Scognet add r0, r0, #4 48150875Scognet#ifndef __ARMEB__ 49150875Scognet ands r3, r2, #0x000000ff 50150875Scognet#else 51150875Scognet ands r3, r2, #0xff000000 52150875Scognet#endif 53150875Scognet addne r1, r1, #1 54150875Scognet.Ldo_3: 55150875Scognet#ifndef __ARMEB__ 56150875Scognet andnes r3, r2, #0x0000ff00 57150875Scognet#else 58150875Scognet andnes r3, r2, #0x00ff0000 59150875Scognet#endif 60150875Scognet addne r1, r1, #1 61150875Scognet.Ldo_2: 62150875Scognet#ifndef __ARMEB__ 63150875Scognet andnes r3, r2, #0x00ff0000 64150875Scognet#else 65150875Scognet andnes r3, r2, #0x0000ff00 66150875Scognet#endif 67150875Scognet addne r1, r1, #1 68150875Scognet.Ldo_1: 69150875Scognet#ifndef __ARMEB__ 70150875Scognet andnes r3, r2, #0xff000000 71150875Scognet#else 72150875Scognet andnes r3, r2, #0x000000ff 73150875Scognet#endif 74150875Scognet addne r1, r1, #1 75150875Scognet bne .Loop 76150875Scognet.Lexit: 77150875Scognet mov r0, r1 78150875Scognet RET 79271337SianEND(strlen) 80