1 /* Compare no more than N characters of S1 and S2, returning less than,
2 equal to or greater than zero if S1 is lexicographically less than,
3 equal to or greater than S2.
5 Copyright (C) 1997, 1999, 2003 Free Software Foundation, Inc.
6 This file is part of the GNU C Library.
7 Contributed by Jan Vondrak <jvon4518@ss1000.ms.mff.cuni.cz> and
8 Jakub Jelinek <jj@ultra.linux.cz>.
10 The GNU C Library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
15 The GNU C Library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with the GNU C Library; if not, see
22 <http://www.gnu.org/licenses/>. */
29 .register %g2, #scratch
30 .register %g3, #scratch
31 .register %g6, #scratch
34 /* Normally, this uses
35 ((xword - 0x0101010101010101) & 0x8080808080808080) test
36 to find out if any byte in xword could be zero. This is fast, but
37 also gives false alarm for any byte in range 0x81-0xff. It does
38 not matter for correctness, as if this test tells us there could
39 be some zero byte, we check it byte by byte, but if bytes with
40 high bits set are common in the strings, then this will give poor
41 performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
42 will use one tick slower, but more precise test
43 ((xword - 0x0101010101010101) & (~xword) & 0x8080808080808080),
44 which does not give any false alarms (but if some bits are set,
45 one cannot assume from it which bytes are zero and which are not).
46 It is yet to be measured, what is the correct default for glibc
47 in these days for an average user.
54 brz,pn %o2, 4f /* CTI+IEU1 Group */
56 tst %o2 /* IEU1 Group */
57 be,pn %XCC, 4f /* CTI */
59 sethi %hi(0x1010101), %g1 /* IEU0 */
60 andcc %o0, 7, %g0 /* IEU1 Group */
61 bne,pn %icc, 9f /* CTI */
63 or %g1, %lo(0x1010101), %g1 /* IEU0 */
64 andcc %o1, 7, %g3 /* IEU1 Group */
65 bne,pn %icc, 11f /* CTI */
66 sllx %g1, 32, %g2 /* IEU0 */
68 ldx [%o0], %g4 /* Load Group */
69 or %g1, %g2, %g1 /* IEU0 */
70 1: ldx [%o1], %o3 /* Load Group */
71 sllx %g1, 7, %g2 /* IEU0 */
73 add %o0, 8, %o0 /* IEU1 */
74 2: subcc %o2, 8, %o2 /* IEU1 Group */
75 bl,pn %XCC, 5f /* CTI */
76 add %o1, 8, %o1 /* IEU0 */
78 sub %g4, %g1, %g3 /* IEU0 Group */
79 subcc %g4, %o3, %o4 /* IEU1 */
80 #ifdef EIGHTBIT_NOT_RARE
81 andn %g3, %g4, %g6 /* IEU0 Group */
83 bne,pn %xcc, 6f /* CTI */
84 ldxa [%o0] ASI_PNF, %g4 /* Load Group */
86 add %o0, 8, %o0 /* IEU0 */
87 #ifdef EIGHTBIT_NOT_RARE
88 andcc %g6, %g2, %g0 /* IEU1 */
90 andcc %g3, %g2, %g0 /* IEU1 */
92 be,a,pt %xcc, 2b /* CTI */
93 ldxa [%o1] ASI_PNF, %o3 /* Load Group */
95 addcc %g3, %g1, %o4 /* IEU1 */
96 #ifdef EIGHTBIT_NOT_RARE
97 srlx %g6, 32, %g6 /* IEU0 */
98 andcc %g6, %g2, %g0 /* IEU1 Group */
100 srlx %g3, 32, %g3 /* IEU0 */
101 andcc %g3, %g2, %g0 /* IEU1 Group */
103 be,pt %xcc, 3f /* CTI */
105 srlx %o4, 56, %o5 /* IEU0 */
106 andcc %o5, 0xff, %g0 /* IEU1 Group */
107 be,pn %icc, 4f /* CTI */
108 srlx %o4, 48, %o5 /* IEU0 */
110 andcc %o5, 0xff, %g0 /* IEU1 Group */
111 be,pn %icc, 4f /* CTI */
112 srlx %o4, 40, %o5 /* IEU0 */
113 andcc %o5, 0xff, %g0 /* IEU1 Group */
115 be,pn %icc, 4f /* CTI */
116 srlx %o4, 32, %o5 /* IEU0 */
117 andcc %o5, 0xff, %g0 /* IEU1 Group */
118 be,pn %icc, 4f /* CTI */
120 3: srlx %o4, 24, %o5 /* IEU0 */
121 andcc %o5, 0xff, %g0 /* IEU1 Group */
122 be,pn %icc, 4f /* CTI */
123 srlx %o4, 16, %o5 /* IEU0 */
125 andcc %o5, 0xff, %g0 /* IEU1 Group */
126 be,pn %icc, 4f /* CTI */
127 srlx %o4, 8, %o5 /* IEU0 */
128 andcc %o5, 0xff, %g0 /* IEU1 Group */
130 be,pn %icc, 4f /* CTI */
131 andcc %o4, 0xff, %g0 /* IEU1 Group */
132 bne,a,pn %icc, 2b /* CTI */
133 ldxa [%o1] ASI_PNF, %o3 /* Load */
135 4: retl /* CTI+IEU1 Group */
139 5: srlx %g4, 56, %o4 /* IEU0 Group */
140 cmp %o2, -8 /* IEU1 */
141 be,pn %XCC, 4b /* CTI */
142 srlx %o3, 56, %o5 /* IEU0 Group */
144 andcc %o4, 0xff, %g0 /* IEU1 */
145 be,pn %xcc, 8f /* CTI */
146 subcc %o4, %o5, %o4 /* IEU1 Group */
147 bne,pn %xcc, 8f /* CTI */
149 srlx %o3, 48, %o5 /* IEU0 */
150 cmp %o2, -7 /* IEU1 Group */
151 be,pn %XCC, 4b /* CTI */
152 srlx %g4, 48, %o4 /* IEU0 */
154 andcc %o4, 0xff, %g0 /* IEU1 Group */
155 be,pn %xcc, 8f /* CTI */
156 subcc %o4, %o5, %o4 /* IEU1 Group */
157 bne,pn %xcc, 8f /* CTI */
159 srlx %o3, 40, %o5 /* IEU0 */
160 cmp %o2, -6 /* IEU1 Group */
161 be,pn %XCC, 4b /* CTI */
162 srlx %g4, 40, %o4 /* IEU0 */
164 andcc %o4, 0xff, %g0 /* IEU1 Group */
165 be,pn %xcc, 8f /* CTI */
166 subcc %o4, %o5, %o4 /* IEU1 Group */
167 bne,pn %xcc, 8f /* CTI */
169 srlx %o3, 32, %o5 /* IEU0 */
170 cmp %o2, -5 /* IEU1 Group */
171 be,pn %XCC, 4b /* CTI */
172 srlx %g4, 32, %o4 /* IEU0 */
174 andcc %o4, 0xff, %g0 /* IEU1 Group */
175 be,pn %xcc, 8f /* CTI */
176 subcc %o4, %o5, %o4 /* IEU1 Group */
177 bne,pn %xcc, 8f /* CTI */
179 srlx %o3, 24, %o5 /* IEU0 */
180 cmp %o2, -4 /* IEU1 Group */
181 be,pn %XCC, 4b /* CTI */
182 srlx %g4, 24, %o4 /* IEU0 */
184 andcc %o4, 0xff, %g0 /* IEU1 Group */
185 be,pn %xcc, 8f /* CTI */
186 subcc %o4, %o5, %o4 /* IEU1 Group */
187 bne,pn %xcc, 8f /* CTI */
189 srlx %o3, 16, %o5 /* IEU0 */
190 cmp %o2, -3 /* IEU1 Group */
191 be,pn %XCC, 4b /* CTI */
192 srlx %g4, 16, %o4 /* IEU0 */
194 andcc %o4, 0xff, %g0 /* IEU1 Group */
195 be,pn %xcc, 8f /* CTI */
196 subcc %o4, %o5, %o4 /* IEU1 Group */
197 bne,pn %xcc, 8f /* CTI */
199 srlx %o3, 8, %o5 /* IEU0 */
200 cmp %o2, -2 /* IEU1 Group */
201 be,pn %XCC, 4b /* CTI */
202 srlx %g4, 8, %o4 /* IEU0 */
204 retl /* CTI+IEU1 Group */
205 sub %o4, %o5, %o0 /* IEU0 */
206 6: addcc %o3, %o4, %g4 /* IEU1 */
207 7: srlx %o3, 56, %o5 /* IEU0 */
209 srlx %g4, 56, %o4 /* IEU0 Group */
210 andcc %o4, 0xff, %g0 /* IEU1 Group */
211 be,pn %xcc, 8f /* CTI */
212 subcc %o4, %o5, %o4 /* IEU1 Group */
214 bne,pn %xcc, 8f /* CTI */
215 srlx %o3, 48, %o5 /* IEU0 */
216 srlx %g4, 48, %o4 /* IEU0 Group */
217 andcc %o4, 0xff, %g0 /* IEU1 Group */
219 be,pn %xcc, 8f /* CTI */
220 subcc %o4, %o5, %o4 /* IEU1 Group */
221 bne,pn %xcc, 8f /* CTI */
222 srlx %o3, 40, %o5 /* IEU0 */
224 srlx %g4, 40, %o4 /* IEU0 Group */
225 andcc %o4, 0xff, %g0 /* IEU1 Group */
226 be,pn %xcc, 8f /* CTI */
227 subcc %o4, %o5, %o4 /* IEU1 Group */
229 bne,pn %xcc, 8f /* CTI */
230 srlx %o3, 32, %o5 /* IEU0 */
231 srlx %g4, 32, %o4 /* IEU0 Group */
232 andcc %o4, 0xff, %g0 /* IEU1 Group */
234 be,pn %xcc, 8f /* CTI */
235 subcc %o4, %o5, %o4 /* IEU1 Group */
236 bne,pn %xcc, 8f /* CTI */
237 srlx %o3, 24, %o5 /* IEU0 */
239 srlx %g4, 24, %o4 /* IEU0 Group */
240 andcc %o4, 0xff, %g0 /* IEU1 Group */
241 be,pn %xcc, 8f /* CTI */
242 subcc %o4, %o5, %o4 /* IEU1 Group */
244 bne,pn %xcc, 8f /* CTI */
245 srlx %o3, 16, %o5 /* IEU0 */
246 srlx %g4, 16, %o4 /* IEU0 Group */
247 andcc %o4, 0xff, %g0 /* IEU1 Group */
249 be,pn %xcc, 8f /* CTI */
250 subcc %o4, %o5, %o4 /* IEU1 Group */
251 bne,pn %xcc, 8f /* CTI */
252 srlx %o3, 8, %o5 /* IEU0 */
254 srlx %g4, 8, %o4 /* IEU0 Group */
255 andcc %o4, 0xff, %g0 /* IEU1 Group */
256 be,pn %xcc, 8f /* CTI */
257 subcc %o4, %o5, %o4 /* IEU1 Group */
259 retl /* CTI+IEU1 Group */
260 sub %g4, %o3, %o0 /* IEU0 */
261 8: retl /* CTI+IEU1 Group */
262 mov %o4, %o0 /* IEU0 */
264 9: ldub [%o0], %g4 /* Load Group */
265 add %o0, 1, %o0 /* IEU0 */
266 ldub [%o1], %o3 /* Load Group */
267 sllx %g1, 32, %g2 /* IEU0 */
269 10: subcc %o2, 1, %o2 /* IEU1 Group */
270 be,pn %XCC, 8b /* CTI */
271 sub %g4, %o3, %o4 /* IEU0 */
272 add %o1, 1, %o1 /* IEU0 Group */
274 cmp %g4, %o3 /* IEU1 */
275 bne,pn %xcc, 8b /* CTI */
276 lduba [%o0] ASI_PNF, %g4 /* Load Group */
277 andcc %o3, 0xff, %g0 /* IEU1 */
279 be,pn %icc, 4b /* CTI */
280 lduba [%o1] ASI_PNF, %o3 /* Load Group */
281 andcc %o0, 7, %g0 /* IEU1 */
282 bne,a,pn %icc, 10b /* CTI */
284 add %o0, 1, %o0 /* IEU0 Group */
285 or %g1, %g2, %g1 /* IEU1 */
286 andcc %o1, 7, %g3 /* IEU1 Group */
287 be,pn %icc, 1b /* CTI */
289 ldxa [%o0] ASI_PNF, %g4 /* Load */
290 11: sllx %g3, 3, %g5 /* IEU0 Group */
291 mov 64, %g6 /* IEU1 */
292 or %g1, %g2, %g1 /* IEU0 Group */
293 sub %o1, %g3, %o1 /* IEU1 */
295 sub %g6, %g5, %g6 /* IEU0 Group */
296 ldxa [%o1] ASI_PNF, %o4 /* Load */
297 sllx %g1, 7, %g2 /* IEU1 */
298 add %o1, 8, %o1 /* IEU0 Group */
299 /* %g1 = 0101010101010101
300 %g2 = 8080808080808080
302 %g5 = number of bits to shift left
303 %g6 = number of bits to shift right */
305 12: sllx %o4, %g5, %o3 /* IEU0 Group */
306 ldxa [%o1] ASI_PNF, %o4 /* Load */
307 add %o1, 8, %o1 /* IEU1 */
308 13: ldxa [%o0] ASI_PNF, %g4 /* Load Group */
310 addcc %o0, 8, %o0 /* IEU1 */
311 srlx %o4, %g6, %o5 /* IEU0 */
312 subcc %o2, 8, %o2 /* IEU1 Group */
313 bl,pn %XCC, 5b /* CTI */
315 or %o3, %o5, %o3 /* IEU0 */
316 cmp %g4, %o3 /* IEU1 Group */
317 bne,pn %xcc, 7b /* CTI */
318 sub %g4, %g1, %o5 /* IEU0 */
320 #ifdef EIGHTBIT_NOT_RARE
321 andn %o5, %g4, %o5 /* IEU0 Group */
323 andcc %o5, %g2, %g0 /* IEU1 Group */
324 be,pt %xcc, 12b /* CTI */
325 srlx %o5, 32, %o5 /* IEU0 */
326 andcc %o5, %g2, %g0 /* IEU1 Group */
328 be,pt %xcc, 14f /* CTI */
329 srlx %g4, 56, %o5 /* IEU0 */
330 andcc %o5, 0xff, %g0 /* IEU1 Group */
331 be,pn %icc, 4b /* CTI */
333 srlx %g4, 48, %o5 /* IEU0 */
334 andcc %o5, 0xff, %g0 /* IEU1 Group */
335 be,pn %icc, 4b /* CTI */
336 srlx %g4, 40, %o5 /* IEU0 */
338 andcc %o5, 0xff, %g0 /* IEU1 Group */
339 be,pn %icc, 4b /* CTI */
340 srlx %g4, 32, %o5 /* IEU0 */
341 andcc %o5, 0xff, %g0 /* IEU1 Group */
343 be,pn %icc, 4b /* CTI */
344 14: srlx %g4, 24, %o5 /* IEU0 */
345 andcc %o5, 0xff, %g0 /* IEU1 Group */
346 be,pn %icc, 4b /* CTI */
348 srlx %g4, 16, %o5 /* IEU0 */
349 andcc %o5, 0xff, %g0 /* IEU1 Group */
350 be,pn %icc, 4b /* CTI */
351 srlx %g4, 8, %o5 /* IEU0 */
353 andcc %o5, 0xff, %g0 /* IEU1 Group */
354 be,pn %icc, 4b /* CTI */
355 andcc %g4, 0xff, %g0 /* IEU1 Group */
356 be,pn %icc, 4b /* CTI */
358 sllx %o4, %g5, %o3 /* IEU0 */
359 ldxa [%o1] ASI_PNF, %o4 /* Load Group */
360 ba,pt %xcc, 13b /* CTI */
361 add %o1, 8, %o1 /* IEU0 */
363 libc_hidden_builtin_def (strncmp)