2
* Copyright (c) 2011 The Android Open Source Project
3
* Copyright (c) 2008 ARM Ltd
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. 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
* 3. The name of the company may not be used to endorse or promote
15
* products derived from this software without specific prior written
18
* THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
19
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
* IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
.type strcmp, %function
36
#define SHFT2LSBEQ lsleq
38
#define SHFT2MSBEQ lsreq
39
#define MSB 0x000000ff
40
#define LSB 0xff000000
43
#define SHFT2LSBEQ lsreq
45
#define SHFT2MSBEQ lsleq
46
#define MSB 0xff000000
47
#define LSB 0x000000ff
50
#define magic1(REG) REG
51
#define magic2(REG) REG, lsl #7
60
/* Strings not at same byte offset from a word boundary. */
61
bne .Lstrcmp_unaligned
70
/* Although s1 and s2 have identical initial alignment, they are
71
* not currently word aligned. Rather than comparing bytes,
72
* make sure that any bytes fetched from before the addressed
73
* bytes are forced to 0xff. Then they will always compare
84
/* Load the 'magic' constant 0x01010101. */
87
orr r4, r4, r4, lsl #8
88
orr r4, r4, r4, lsl #16
93
sub r2, ip, magic1(r4)
97
/* check for any zero bytes in first word */
104
/* There's a zero or a different byte in the word */
109
cmpcs r0, r3, SHFT2MSB #24
111
SHFT2LSBEQ r3, r3, #8
113
/* On a big-endian machine, r0 contains the desired byte in bits
114
* 0-7; on a little-endian machine they are in bits 24-31. In
115
* both cases the other bits in r0 are all zero. For r3 the
116
* interesting byte is at the other end of the word, but the
117
* other bits are not necessarily zero. We need a signed result
118
* representing the differnece in the unsigned bytes, so for the
119
* little-endian case we can't just shift the interesting bits up.
122
sub r0, r0, r3, lsr #24
125
/* No RSB instruction in Thumb2 */
130
rsb r0, r3, r0, lsr #24
145
/* First of all, compare bytes until wp1(sp1) is word-aligned. */
162
orr b1, b1, b1, lsl #8
163
orr b1, b1, b1, lsl #16
173
/* Critical inner Loop: Block with 3 bytes initial overlap */
177
cmp t1, w2, SHFT2LSB #8
181
ands r3, r3, b1, lsl #7
186
cmp t1, w2, SHFT2MSB #24
196
/* The syndrome value may contain false ones if the string ends
197
* with the bytes 0x01 0x00
201
tstne w1, #0x00ff0000
202
tstne w1, #0x0000ff00
205
bics r3, r3, #0xff000000
220
/* Critical inner Loop: Block with 2 bytes initial overlap */
227
cmp t1, w2, SHFT2LSB #16
229
ands r3, r3, b1, lsl #7
234
cmp t1, w2, SHFT2MSB #16
241
/* The syndrome value may contain false ones if the string ends
242
* with the bytes 0x01 0x00
246
tstne w1, #0x00ff0000
266
/* Critical inner Loop: Block with 1 byte initial overlap */
270
cmp t1, w2, SHFT2LSB #24
274
ands r3, r3, b1, lsl #7
279
cmp t1, w2, SHFT2MSB #8
287
/* The syndrome value may contain false ones if the string ends
288
* with the bytes 0x01 0x00
310
SHFT2LSBEQ t1, t1, #8
311
SHFT2LSBEQ w2, w2, #8