14e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris/*
24e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * Copyright (C) 2013 The Android Open Source Project
34e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * All rights reserved.
44e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *
54e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * Redistribution and use in source and binary forms, with or without
64e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * modification, are permitted provided that the following conditions
74e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * are met:
84e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *  * Redistributions of source code must retain the above copyright
94e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *    notice, this list of conditions and the following disclaimer.
104e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *  * Redistributions in binary form must reproduce the above copyright
114e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *    notice, this list of conditions and the following disclaimer in
124e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *    the documentation and/or other materials provided with the
134e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *    distribution.
144e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *
154e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
164e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
174e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
184e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
194e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
204e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
214e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
224e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
234e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
244e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
254e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
264e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * SUCH DAMAGE.
274e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris */
284e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris/*
294e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * Copyright (c) 2013 ARM Ltd
304e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * All rights reserved.
314e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *
324e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * Redistribution and use in source and binary forms, with or without
334e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * modification, are permitted provided that the following conditions
344e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * are met:
354e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * 1. Redistributions of source code must retain the above copyright
364e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *    notice, this list of conditions and the following disclaimer.
374e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * 2. Redistributions in binary form must reproduce the above copyright
384e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *    notice, this list of conditions and the following disclaimer in the
394e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *    documentation and/or other materials provided with the distribution.
404e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * 3. The name of the company may not be used to endorse or promote
414e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *    products derived from this software without specific prior written
424e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *    permission.
434e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris *
444e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
454e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
464e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
474e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
484e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
494e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
504e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
514e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
524e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
534e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
544e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris */
554e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
56851e68a2402fa414544e66650e09dfdaac813e51Elliott Hughes#include <private/bionic_asm.h>
574e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
584e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    .syntax unified
594e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
604e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    .thumb
614e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    .thumb_func
624e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
634e24dcc8d869db7303650d8444c8796445fbbc07Christopher FerrisENTRY(strlen)
644e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    pld     [r0, #0]
654e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    mov     r1, r0
664e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
674e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    ands    r3, r0, #7
684e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bne     align_src
694e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
704e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    .p2align 2
714e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrismainloop:
724e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    ldmia   r1!, {r2, r3}
734e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
744e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    pld     [r1, #64]
754e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
764e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     ip, r2, #0x01010101
774e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bic     ip, ip, r2
784e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    ands    ip, ip, #0x80808080
794e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bne     zero_in_first_register
804e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
814e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     ip, r3, #0x01010101
824e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bic     ip, ip, r3
834e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    ands    ip, ip, #0x80808080
844e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bne     zero_in_second_register
854e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    b       mainloop
864e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
874e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferriszero_in_first_register:
884e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r1, r0
894e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    // Check for zero in byte 0.
904e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    lsls    r2, ip, #17
914e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    beq     check_byte1_reg1
924e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
934e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #8
944e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bx      lr
954e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
964e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrischeck_byte1_reg1:
974e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bcc     check_byte2_reg1
984e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
994e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #7
1004e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bx      lr
1014e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1024e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrischeck_byte2_reg1:
1034e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    // Check for zero in byte 2.
1044e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    tst     ip, #0x800000
1054e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    itt     ne
1064e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    subne   r0, r0, #6
1074e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bxne    lr
1084e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #5
1094e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bx      lr
1104e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1114e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferriszero_in_second_register:
1124e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r1, r0
1134e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    // Check for zero in byte 0.
1144e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    lsls    r2, ip, #17
1154e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    beq     check_byte1_reg2
1164e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1174e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #4
1184e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bx      lr
1194e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1204e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrischeck_byte1_reg2:
1214e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bcc     check_byte2_reg2
1224e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1234e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #3
1244e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bx      lr
1254e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1264e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrischeck_byte2_reg2:
1274e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    // Check for zero in byte 2.
1284e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    tst     ip, #0x800000
1294e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    itt     ne
1304e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    subne   r0, r0, #2
1314e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bxne    lr
1324e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #1
1334e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bx      lr
1344e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1354e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrisalign_src:
1364e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    // Align to a double word (64 bits).
1374e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    rsb     r3, r3, #8
1384e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    lsls    ip, r3, #31
1394e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    beq     align_to_32
1404e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1414e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    ldrb    r2, [r1], #1
1424e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    cbz     r2, done
1434e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1444e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrisalign_to_32:
1454e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bcc     align_to_64
1464e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1474e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    ldrb    r2, [r1], #1
1484e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    cbz     r2, done
1494e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    ldrb    r2, [r1], #1
1504e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    cbz     r2, done
1514e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1524e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrisalign_to_64:
1534e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    tst     r3, #4
1544e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    beq     mainloop
1554e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    ldr     r2, [r1], #4
1564e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1574e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     ip, r2, #0x01010101
1584e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bic     ip, ip, r2
1594e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    ands    ip, ip, #0x80808080
1604e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bne     zero_in_second_register
1614e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    b       mainloop
1624e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris
1634e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferrisdone:
1644e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r1, r0
1654e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    sub     r0, r0, #1
1664e24dcc8d869db7303650d8444c8796445fbbc07Christopher Ferris    bx      lr
1674e24dcc8d869db7303650d8444c8796445fbbc07Christopher FerrisEND(strlen)
168