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.
35
#define SHFT2LSBEQ lsleq
37
#define SHFT2MSBEQ lsreq
38
#define MSB 0x000000ff
39
#define LSB 0xff000000
42
#define SHFT2LSBEQ lsreq
44
#define SHFT2MSBEQ lsleq
45
#define MSB 0xff000000
46
#define LSB 0x000000ff
49
#define magic1(REG) REG
50
#define magic2(REG) REG, lsl #7
59
/* Strings not at same byte offset from a word boundary. */
60
bne .Lstrcmp_unaligned
69
/* Although s1 and s2 have identical initial alignment, they are
70
* not currently word aligned. Rather than comparing bytes,
71
* make sure that any bytes fetched from before the addressed
72
* bytes are forced to 0xff. Then they will always compare
83
/* Load the 'magic' constant 0x01010101. */
86
orr r4, r4, r4, lsl #8
87
orr r4, r4, r4, lsl #16
92
sub r2, ip, magic1(r4)
96
/* check for any zero bytes in first word */
103
/* There's a zero or a different byte in the word */
108
cmpcs r0, r3, SHFT2MSB #24
110
SHFT2LSBEQ r3, r3, #8
112
/* On a big-endian machine, r0 contains the desired byte in bits
113
* 0-7; on a little-endian machine they are in bits 24-31. In
114
* both cases the other bits in r0 are all zero. For r3 the
115
* interesting byte is at the other end of the word, but the
116
* other bits are not necessarily zero. We need a signed result
117
* representing the differnece in the unsigned bytes, so for the
118
* little-endian case we can't just shift the interesting bits up.
121
sub r0, r0, r3, lsr #24
124
/* No RSB instruction in Thumb2 */
129
rsb r0, r3, r0, lsr #24
144
/* First of all, compare bytes until wp1(sp1) is word-aligned. */
161
orr b1, b1, b1, lsl #8
162
orr b1, b1, b1, lsl #16
172
/* Critical inner Loop: Block with 3 bytes initial overlap */
176
cmp t1, w2, SHFT2LSB #8
180
ands r3, r3, b1, lsl #7
185
cmp t1, w2, SHFT2MSB #24
195
/* The syndrome value may contain false ones if the string ends
196
* with the bytes 0x01 0x00
200
tstne w1, #0x00ff0000
201
tstne w1, #0x0000ff00
204
bics r3, r3, #0xff000000
219
/* Critical inner Loop: Block with 2 bytes initial overlap */
226
cmp t1, w2, SHFT2LSB #16
228
ands r3, r3, b1, lsl #7
233
cmp t1, w2, SHFT2MSB #16
240
/* The syndrome value may contain false ones if the string ends
241
* with the bytes 0x01 0x00
245
tstne w1, #0x00ff0000
265
/* Critical inner Loop: Block with 1 byte initial overlap */
269
cmp t1, w2, SHFT2LSB #24
273
ands r3, r3, b1, lsl #7
278
cmp t1, w2, SHFT2MSB #8
286
/* The syndrome value may contain false ones if the string ends
287
* with the bytes 0x01 0x00
309
SHFT2LSBEQ t1, t1, #8
310
SHFT2LSBEQ w2, w2, #8