10aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris/*
20aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * Copyright (C) 2013 The Android Open Source Project
30aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * All rights reserved.
40aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *
50aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * Redistribution and use in source and binary forms, with or without
60aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * modification, are permitted provided that the following conditions
70aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * are met:
80aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *  * Redistributions of source code must retain the above copyright
90aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *    notice, this list of conditions and the following disclaimer.
100aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *  * Redistributions in binary form must reproduce the above copyright
110aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *    notice, this list of conditions and the following disclaimer in
120aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *    the documentation and/or other materials provided with the
130aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *    distribution.
140aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *
150aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
160aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
170aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
180aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
190aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
200aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
210aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
220aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
230aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
240aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
250aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
260aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * SUCH DAMAGE.
270aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris */
280aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris/*
290aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * Copyright (c) 2013 ARM Ltd
300aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * All rights reserved.
310aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *
320aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * Redistribution and use in source and binary forms, with or without
330aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * modification, are permitted provided that the following conditions
340aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * are met:
350aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * 1. Redistributions of source code must retain the above copyright
360aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *    notice, this list of conditions and the following disclaimer.
370aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * 2. Redistributions in binary form must reproduce the above copyright
380aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *    notice, this list of conditions and the following disclaimer in the
390aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *    documentation and/or other materials provided with the distribution.
400aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * 3. The name of the company may not be used to endorse or promote
410aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *    products derived from this software without specific prior written
420aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *    permission.
430aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris *
440aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
450aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
460aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
470aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
480aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
490aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
500aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
510aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
520aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
530aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
540aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris */
550aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
56851e68a2402fa414544e66650e09dfdaac813e51Elliott Hughes#include <private/bionic_asm.h>
570aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
580aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    .syntax unified
590aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
600aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    .thumb
610aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    .thumb_func
620aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
630aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher FerrisENTRY(strlen)
644e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    pld     [r0, #0]
654e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    mov     r1, r0
660aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
674e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    ands    r3, r0, #7
680aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    beq     mainloop
690aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
700aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    // Align to a double word (64 bits).
714e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    rsb     r3, r3, #8
724e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    lsls    ip, r3, #31
730aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    beq     align_to_32
740aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
750aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    ldrb    r2, [r1], #1
764e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    cbz     r2, update_count_and_return
770aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
780aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferrisalign_to_32:
794e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bcc     align_to_64
800aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    ands    ip, r3, #2
810aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    beq     align_to_64
820aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
830aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    ldrb    r2, [r1], #1
844e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    cbz     r2, update_count_and_return
850aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    ldrb    r2, [r1], #1
864e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    cbz     r2, update_count_and_return
870aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
880aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferrisalign_to_64:
894e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    tst     r3, #4
900aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    beq     mainloop
910aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    ldr     r3, [r1], #4
920aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
930aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    sub     ip, r3, #0x01010101
940aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    bic     ip, ip, r3
950aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    ands    ip, ip, #0x80808080
960aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    bne     zero_in_second_register
970aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
984e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    .p2align 2
990aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferrismainloop:
1000aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    ldrd    r2, r3, [r1], #8
1010aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
1020aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    pld     [r1, #64]
1030aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
1040aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    sub     ip, r2, #0x01010101
1050aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    bic     ip, ip, r2
1060aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    ands    ip, ip, #0x80808080
1070aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    bne     zero_in_first_register
1080aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
1090aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    sub     ip, r3, #0x01010101
1100aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    bic     ip, ip, r3
1110aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    ands    ip, ip, #0x80808080
1120aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    bne     zero_in_second_register
1130aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    b       mainloop
1140aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
1154e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrisupdate_count_and_return:
1160aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    sub     r0, r1, r0
1174e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #1
1184e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bx      lr
1190aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
1204e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferriszero_in_first_register:
1214e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r1, r0
1224e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    lsls    r3, ip, #17
1234e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bne     sub8_and_return
1244e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bcs     sub7_and_return
1254e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    lsls    ip, ip, #1
1264e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bne     sub6_and_return
1270aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
1284e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #5
1290aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    bx      lr
1300aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
1314e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrissub8_and_return:
1324e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #8
1330aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    bx      lr
1340aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
1354e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrissub7_and_return:
1364e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #7
1374e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bx      lr
1380aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
1394e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrissub6_and_return:
1404e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #6
1410aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    bx      lr
1420aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
1434e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferriszero_in_second_register:
1440aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    sub     r0, r1, r0
1454e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    lsls    r3, ip, #17
1464e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bne     sub4_and_return
1474e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bcs     sub3_and_return
1484e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    lsls    ip, ip, #1
1494e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bne     sub2_and_return
1500aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris
1510aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    sub     r0, r0, #1
1520aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher Ferris    bx      lr
1534e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1544e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrissub4_and_return:
1554e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #4
1564e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bx      lr
1574e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1584e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrissub3_and_return:
1594e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #3
1604e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bx      lr
1614e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1624e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrissub2_and_return:
1634e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #2
1644e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bx      lr
1650aa9b52efa75b4c8bbdc12845434e25e457ea57bChristopher FerrisEND(strlen)
166