source: trunk/libs/newlib/src/newlib/libc/machine/arm/strlen-armv7.S @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 5.9 KB
Line 
1/* Copyright (c) 2010-2011,2013 Linaro Limited
2   All rights reserved.
3
4   Redistribution and use in source and binary forms, with or without
5   modification, are permitted provided that the following conditions
6   are met:
7
8      * Redistributions of source code must retain the above copyright
9      notice, this list of conditions and the following disclaimer.
10
11      * Redistributions in binary form must reproduce the above copyright
12      notice, this list of conditions and the following disclaimer in the
13      documentation and/or other materials provided with the distribution.
14
15      * Neither the name of Linaro Limited nor the names of its
16      contributors may be used to endorse or promote products derived
17      from this software without specific prior written permission.
18
19   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31   Assumes:
32   ARMv6T2 or ARMv7E-M, AArch32
33 */
34
35/* Copyright (c) 2015 ARM Ltd.
36   All rights reserved.
37
38   Redistribution and use in source and binary forms, with or without
39   modification, are permitted provided that the following conditions are met:
40       * Redistributions of source code must retain the above copyright
41         notice, this list of conditions and the following disclaimer.
42       * Redistributions in binary form must reproduce the above copyright
43         notice, this list of conditions and the following disclaimer in the
44         documentation and/or other materials provided with the distribution.
45       * Neither the name of the Linaro nor the
46         names of its contributors may be used to endorse or promote products
47         derived from this software without specific prior written permission.
48
49   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
53   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */
60
61#include "acle-compat.h"
62
63        .macro def_fn f p2align=0
64        .text
65        .p2align \p2align
66        .global \f
67        .type \f, %function
68\f:
69        .endm
70
71#ifdef __ARMEB__
72#define S2LO            lsl
73#define S2HI            lsr
74#else
75#define S2LO            lsr
76#define S2HI            lsl
77#endif
78
79        /* This code requires Thumb.  */
80#if __ARM_ARCH_PROFILE == 'M'
81        .arch   armv7e-m
82#else
83        .arch   armv6t2
84#endif
85        .eabi_attribute Tag_ARM_ISA_use, 0
86        .thumb
87        .syntax unified
88
89/* Parameters and result.  */
90#define srcin           r0
91#define result          r0
92
93/* Internal variables.  */
94#define src             r1
95#define data1a          r2
96#define data1b          r3
97#define const_m1        r12
98#define const_0         r4
99#define tmp1            r4              /* Overlaps const_0  */
100#define tmp2            r5
101
102def_fn  strlen p2align=6
103        pld     [srcin, #0]
104        strd    r4, r5, [sp, #-8]!
105        bic     src, srcin, #7
106        mvn     const_m1, #0
107        ands    tmp1, srcin, #7         /* (8 - bytes) to alignment.  */
108        pld     [src, #32]
109        bne.w   .Lmisaligned8
110        mov     const_0, #0
111        mov     result, #-8
112.Lloop_aligned:
113        /* Bytes 0-7.  */
114        ldrd    data1a, data1b, [src]
115        pld     [src, #64]
116        add     result, result, #8
117.Lstart_realigned:
118        uadd8   data1a, data1a, const_m1        /* Saturating GE<0:3> set.  */
119        sel     data1a, const_0, const_m1       /* Select based on GE<0:3>.  */
120        uadd8   data1b, data1b, const_m1
121        sel     data1b, data1a, const_m1        /* Only used if d1a == 0.  */
122        cbnz    data1b, .Lnull_found
123
124        /* Bytes 8-15.  */
125        ldrd    data1a, data1b, [src, #8]
126        uadd8   data1a, data1a, const_m1        /* Saturating GE<0:3> set.  */
127        add     result, result, #8
128        sel     data1a, const_0, const_m1       /* Select based on GE<0:3>.  */
129        uadd8   data1b, data1b, const_m1
130        sel     data1b, data1a, const_m1        /* Only used if d1a == 0.  */
131        cbnz    data1b, .Lnull_found
132
133        /* Bytes 16-23.  */
134        ldrd    data1a, data1b, [src, #16]
135        uadd8   data1a, data1a, const_m1        /* Saturating GE<0:3> set.  */
136        add     result, result, #8
137        sel     data1a, const_0, const_m1       /* Select based on GE<0:3>.  */
138        uadd8   data1b, data1b, const_m1
139        sel     data1b, data1a, const_m1        /* Only used if d1a == 0.  */
140        cbnz    data1b, .Lnull_found
141
142        /* Bytes 24-31.  */
143        ldrd    data1a, data1b, [src, #24]
144        add     src, src, #32
145        uadd8   data1a, data1a, const_m1        /* Saturating GE<0:3> set.  */
146        add     result, result, #8
147        sel     data1a, const_0, const_m1       /* Select based on GE<0:3>.  */
148        uadd8   data1b, data1b, const_m1
149        sel     data1b, data1a, const_m1        /* Only used if d1a == 0.  */
150        cmp     data1b, #0
151        beq     .Lloop_aligned
152
153.Lnull_found:
154        cmp     data1a, #0
155        itt     eq
156        addeq   result, result, #4
157        moveq   data1a, data1b
158#ifndef __ARMEB__
159        rev     data1a, data1a
160#endif
161        clz     data1a, data1a
162        ldrd    r4, r5, [sp], #8
163        add     result, result, data1a, lsr #3  /* Bits -> Bytes.  */
164        bx      lr
165
166.Lmisaligned8:
167        ldrd    data1a, data1b, [src]
168        and     tmp2, tmp1, #3
169        rsb     result, tmp1, #0
170        lsl     tmp2, tmp2, #3                  /* Bytes -> bits.  */
171        tst     tmp1, #4
172        pld     [src, #64]
173        S2HI    tmp2, const_m1, tmp2
174        orn     data1a, data1a, tmp2
175        itt     ne
176        ornne   data1b, data1b, tmp2
177        movne   data1a, const_m1
178        mov     const_0, #0
179        b       .Lstart_realigned
180        .size   strlen, . - strlen
Note: See TracBrowser for help on using the repository browser.