~linaro-toolchain-dev/cortex-strings/trunk

« back to all changes in this revision

Viewing changes to src/thumb-2/strlen.S

  • Committer: Will Newton
  • Date: 2013-06-18 16:19:32 UTC
  • mfrom: (103.1.2 a15-strlen)
  • Revision ID: will.newton@linaro.org-20130618161932-l0fj2a7xv64i5316
Merged Thumb-2 strlen implementation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
   ARMv7, AArch32
 
33
 */
 
34
 
 
35
        .macro def_fn f p2align=0
 
36
        .text
 
37
        .p2align \p2align
 
38
        .global \f
 
39
        .type \f, %function
 
40
\f:
 
41
        .endm
 
42
 
 
43
#ifdef __ARMEB__
 
44
#define S2LO            lsl
 
45
#define S2HI            lsr
 
46
#else
 
47
#define S2LO            lsr
 
48
#define S2HI            lsl
 
49
#endif
 
50
 
 
51
        /* This code requires Thumb.  */
 
52
        .thumb
 
53
        .syntax unified
 
54
 
 
55
/* Parameters and result.  */
 
56
#define srcin           r0
 
57
#define result          r0
 
58
 
 
59
/* Internal variables.  */
 
60
#define src             r1
 
61
#define data1a          r2
 
62
#define data1b          r3
 
63
#define const_m1        r12
 
64
#define const_0         r4
 
65
#define tmp1            r4              /* Overlaps const_0  */
 
66
#define tmp2            r5
 
67
 
 
68
def_fn  strlen p2align=6
 
69
        pld     [srcin, #0]
 
70
        strd    r4, r5, [sp, #-8]!
 
71
        bic     src, srcin, #7
 
72
        mvn     const_m1, #0
 
73
        ands    tmp1, srcin, #7         /* (8 - bytes) to alignment.  */
 
74
        pld     [src, #32]
 
75
        bne.w   .Lmisaligned8
 
76
        mov     const_0, #0
 
77
        mov     result, #-8
 
78
.Lloop_aligned:
 
79
        /* Bytes 0-7.  */
 
80
        ldrd    data1a, data1b, [src]
 
81
        pld     [src, #64]
 
82
        add     result, result, #8
 
83
.Lstart_realigned:
 
84
        uadd8   data1a, data1a, const_m1        /* Saturating GE<0:3> set.  */
 
85
        sel     data1a, const_0, const_m1       /* Select based on GE<0:3>.  */
 
86
        uadd8   data1b, data1b, const_m1
 
87
        sel     data1b, data1a, const_m1        /* Only used if d1a == 0.  */
 
88
        cbnz    data1b, .Lnull_found
 
89
 
 
90
        /* Bytes 8-15.  */
 
91
        ldrd    data1a, data1b, [src, #8]
 
92
        uadd8   data1a, data1a, const_m1        /* Saturating GE<0:3> set.  */
 
93
        add     result, result, #8
 
94
        sel     data1a, const_0, const_m1       /* Select based on GE<0:3>.  */
 
95
        uadd8   data1b, data1b, const_m1
 
96
        sel     data1b, data1a, const_m1        /* Only used if d1a == 0.  */
 
97
        cbnz    data1b, .Lnull_found
 
98
 
 
99
        /* Bytes 16-23.  */
 
100
        ldrd    data1a, data1b, [src, #16]
 
101
        uadd8   data1a, data1a, const_m1        /* Saturating GE<0:3> set.  */
 
102
        add     result, result, #8
 
103
        sel     data1a, const_0, const_m1       /* Select based on GE<0:3>.  */
 
104
        uadd8   data1b, data1b, const_m1
 
105
        sel     data1b, data1a, const_m1        /* Only used if d1a == 0.  */
 
106
        cbnz    data1b, .Lnull_found
 
107
 
 
108
        /* Bytes 24-31.  */
 
109
        ldrd    data1a, data1b, [src, #24]
 
110
        add     src, src, #32
 
111
        uadd8   data1a, data1a, const_m1        /* Saturating GE<0:3> set.  */
 
112
        add     result, result, #8
 
113
        sel     data1a, const_0, const_m1       /* Select based on GE<0:3>.  */
 
114
        uadd8   data1b, data1b, const_m1
 
115
        sel     data1b, data1a, const_m1        /* Only used if d1a == 0.  */
 
116
        cmp     data1b, #0
 
117
        beq     .Lloop_aligned
 
118
 
 
119
.Lnull_found:
 
120
        cmp     data1a, #0
 
121
        itt     eq
 
122
        addeq   result, result, #4
 
123
        moveq   data1a, data1b
 
124
#ifndef __ARMEB__
 
125
        rev     data1a, data1a
 
126
#endif
 
127
        clz     data1a, data1a
 
128
        ldrd    r4, r5, [sp], #8
 
129
        add     result, result, data1a, lsr #3  /* Bits -> Bytes.  */
 
130
        bx      lr
 
131
 
 
132
.Lmisaligned8:
 
133
        ldrd    data1a, data1b, [src]
 
134
        and     tmp2, tmp1, #3
 
135
        rsb     result, tmp1, #0
 
136
        lsl     tmp2, tmp2, #3                  /* Bytes -> bits.  */
 
137
        tst     tmp1, #4
 
138
        pld     [src, #64]
 
139
        S2HI    tmp2, const_m1, tmp2
 
140
        orn     data1a, data1a, tmp2
 
141
        itt     ne
 
142
        ornne   data1b, data1b, tmp2
 
143
        movne   data1a, const_m1
 
144
        mov     const_0, #0
 
145
        b       .Lstart_realigned
 
146
        .size   strlen, . - strlen
 
147