1 /* Compare two strings for differences.
3 Copyright (C) 1997, 1999, 2003 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Jan Vondrak <jvon4518@ss1000.ms.mff.cuni.cz> and
6 Jakub Jelinek <jj@ultra.linux.cz>.
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library; if not, write to the Free
20 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 .register %g2, #scratch
27 .register %g3, #scratch
28 .register %g6, #scratch
31 /* Normally, this uses
32 ((xword - 0x0101010101010101) & 0x8080808080808080) test
33 to find out if any byte in xword could be zero. This is fast, but
34 also gives false alarm for any byte in range 0x81-0xff. It does
35 not matter for correctness, as if this test tells us there could
36 be some zero byte, we check it byte by byte, but if bytes with
37 high bits set are common in the strings, then this will give poor
38 performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
39 will use one tick slower, but more precise test
40 ((xword - 0x0101010101010101) & (~xword) & 0x8080808080808080),
41 which does not give any false alarms (but if some bits are set,
42 one cannot assume from it which bytes are zero and which are not).
43 It is yet to be measured, what is the correct default for glibc
44 in these days for an average user.
50 sethi %hi(0x01010101), %g1 /* IEU0 Group */
51 andcc %o0, 7, %g0 /* IEU1 */
52 bne,pn %icc, 7f /* CTI */
53 or %g1, %lo(0x01010101), %g1 /* IEU0 Group */
55 andcc %o1, 7, %g3 /* IEU1 */
56 bne,pn %icc, 9f /* CTI */
57 sllx %g1, 32, %g2 /* IEU0 Group */
58 ldx [%o0], %o2 /* Load */
60 or %g1, %g2, %g1 /* IEU0 Group */
61 1: ldx [%o1], %o3 /* Load */
62 sub %o1, %o0, %o1 /* IEU1 */
63 sllx %g1, 7, %g2 /* IEU0 Group */
65 2: add %o0, 8, %o0 /* IEU1 */
66 sub %o2, %g1, %g3 /* IEU0 Group */
67 subcc %o2, %o3, %g0 /* IEU1 */
68 bne,pn %xcc, 13f /* CTI */
70 #ifdef EIGHTBIT_NOT_RARE
71 andn %g3, %o2, %g4 /* IEU0 Group */
72 ldxa [%o0] ASI_PNF, %o2 /* Load */
73 andcc %g4, %g2, %g0 /* IEU1 Group */
75 ldxa [%o0] ASI_PNF, %o2 /* Load Group */
76 andcc %g3, %g2, %g0 /* IEU1 */
78 be,a,pt %xcc, 2b /* CTI */
79 ldxa [%o1 + %o0] ASI_PNF, %o3 /* Load Group */
81 addcc %g3, %g1, %o4 /* IEU1 */
82 srlx %g3, 32, %g3 /* IEU0 */
83 andcc %g3, %g2, %g0 /* IEU1 Group */
84 be,pt %xcc, 3f /* CTI */
86 srlx %o4, 56, %o5 /* IEU0 */
87 andcc %o5, 0xff, %g0 /* IEU1 Group */
88 be,pn %icc, 4f /* CTI */
89 srlx %o4, 48, %o5 /* IEU0 */
91 andcc %o5, 0xff, %g0 /* IEU1 Group */
92 be,pn %icc, 4f /* CTI */
93 srlx %o4, 40, %o5 /* IEU0 */
94 andcc %o5, 0xff, %g0 /* IEU1 Group */
96 be,pn %icc, 4f /* CTI */
97 srlx %o4, 32, %o5 /* IEU0 */
98 andcc %o5, 0xff, %g0 /* IEU1 Group */
99 be,pn %icc, 4f /* CTI */
101 3: srlx %o4, 24, %o5 /* IEU0 */
102 andcc %o5, 0xff, %g0 /* IEU1 Group */
103 be,pn %icc, 4f /* CTI */
104 srlx %o4, 16, %o5 /* IEU0 */
106 andcc %o5, 0xff, %g0 /* IEU1 Group */
107 be,pn %icc, 4f /* CTI */
108 srlx %o4, 8, %o5 /* IEU0 */
109 andcc %o5, 0xff, %g0 /* IEU1 Group */
111 be,pn %icc, 4f /* CTI */
112 andcc %o4, 0xff, %g0 /* IEU1 Group */
113 bne,a,pn %icc, 2b /* CTI */
114 ldxa [%o1 + %o0] ASI_PNF, %o3 /* Load */
116 4: retl /* CTI+IEU1 Group */
120 13: mov 0xff, %g6 /* IEU0 Group */
121 #ifdef EIGHTBIT_NOT_RARE
122 andcc %g4, %g2, %g0 /* IEU1 */
124 andcc %g3, %g2, %g0 /* IEU1 */
126 be,pt %xcc, 25f /* CTI */
127 addcc %g3, %g1, %o4 /* IEU1 Group */
129 srlx %g3, 32, %g3 /* IEU0 */
130 andcc %g3, %g2, %g0 /* IEU1 Group */
131 be,pt %xcc, 23f /* CTI */
132 sllx %g6, 56, %o5 /* IEU0 */
134 andcc %o4, %o5, %g0 /* IEU1 Group */
135 be,pn %xcc, 24f /* CTI */
136 sllx %g6, 48, %o5 /* IEU0 */
137 andcc %o4, %o5, %g0 /* IEU1 Group */
139 be,pn %xcc, 24f /* CTI */
140 sllx %g6, 40, %o5 /* IEU0 */
141 andcc %o4, %o5, %g0 /* IEU1 Group */
142 be,pn %xcc, 24f /* CTI */
144 sllx %g6, 32, %o5 /* IEU0 */
145 andcc %o4, %o5, %g0 /* IEU1 Group */
146 be,pn %xcc, 24f /* CTI */
147 23: sllx %g6, 24, %o5 /* IEU0 */
149 andcc %o4, %o5, %g0 /* IEU1 Group */
150 be,pn %icc, 24f /* CTI */
151 sllx %g6, 16, %o5 /* IEU0 */
152 andcc %o4, %o5, %g0 /* IEU1 Group */
154 be,pn %icc, 24f /* CTI */
155 sllx %g6, 8, %o5 /* IEU0 */
156 andcc %o4, %o5, %g0 /* IEU1 Group */
157 be,pn %icc, 24f /* CTI */
159 mov %g6, %o5 /* IEU0 */
160 25: cmp %o4, %o3 /* IEU1 Group */
161 5: mov -1, %o0 /* IEU0 */
162 retl /* CTI+IEU1 Group */
164 movgu %xcc, 1, %o0 /* Single Group */
167 24: sub %o5, 1, %g6 /* IEU0 Group */
169 or %o5, %g6, %o5 /* IEU0 Group */
170 andn %o4, %o5, %o4 /* IEU0 Group */
172 andn %o3, %o5, %o3 /* IEU1 */
173 cmp %o4, %o3 /* IEU1 Group */
174 movgu %xcc, 1, %o0 /* Single Group */
175 retl /* CTI+IEU1 Group */
177 movlu %xcc, -1, %o0 /* Single Group */
178 6: retl /* CTI+IEU1 Group */
179 mov %o4, %o0 /* IEU0 */
182 7: ldub [%o0], %o2 /* Load */
183 add %o0, 1, %o0 /* IEU1 */
184 ldub [%o1], %o3 /* Load Group */
185 sllx %g1, 32, %g2 /* IEU0 */
187 8: add %o1, 1, %o1 /* IEU1 */
188 subcc %o2, %o3, %o4 /* IEU1 Group */
189 bne,pn %xcc, 6b /* CTI */
190 lduba [%o0] ASI_PNF, %o2 /* Load */
192 brz,pn %o3, 4b /* CTI+IEU1 Group */
193 lduba [%o1] ASI_PNF, %o3 /* Load */
194 andcc %o0, 7, %g0 /* IEU1 Group */
195 bne,a,pn %icc, 8b /* CTI */
197 add %o0, 1, %o0 /* IEU0 */
198 or %g1, %g2, %g1 /* IEU0 Group */
199 andcc %o1, 7, %g3 /* IEU1 */
200 be,a,pn %icc, 1b /* CTI */
202 ldxa [%o0] ASI_PNF, %o2 /* Load Group */
203 9: sllx %g3, 3, %g5 /* IEU0 */
204 mov 64, %o5 /* IEU1 */
205 sub %o1, %g3, %o1 /* IEU0 Group */
207 sub %o5, %g5, %o5 /* IEU1 */
208 ldxa [%o1] ASI_PNF, %g6 /* Load Group */
209 or %g1, %g2, %g1 /* IEU0 */
210 sub %o1, %o0, %o1 /* IEU1 */
212 sllx %g1, 7, %g2 /* IEU0 Group */
213 add %o1, 8, %o1 /* IEU1 */
214 /* %g1 = 0101010101010101
215 * %g2 = 8080808080800880
216 * %g5 = number of bits to shift left
217 * %o5 = number of bits to shift right */
218 10: sllx %g6, %g5, %o3 /* IEU0 Group */
219 ldxa [%o1 + %o0] ASI_PNF, %g6 /* Load */
221 11: srlx %g6, %o5, %o4 /* IEU0 Group */
222 ldxa [%o0] ASI_PNF, %o2 /* Load */
223 or %o3, %o4, %o3 /* IEU1 */
224 add %o0, 8, %o0 /* IEU0 Group */
226 subcc %o2, %o3, %g0 /* IEU1 */
227 #ifdef EIGHTBIT_NOT_RARE
228 sub %o2, %g1, %g3 /* IEU0 Group */
229 bne,pn %xcc, 13b /* CTI */
230 andn %g3, %o2, %g4 /* IEU0 Group */
232 andcc %g4, %g2, %g0 /* IEU1 Group */
233 be,pt %xcc, 10b /* CTI */
234 srlx %g4, 32, %g4 /* IEU0 */
235 andcc %g4, %g2, %g0 /* IEU1 Group */
237 bne,pn %xcc, 13b /* CTI */
238 sub %o2, %g1, %g3 /* IEU0 Group */
239 andcc %g3, %g2, %g0 /* IEU1 Group */
241 be,pt %xcc, 10b /* CTI */
242 srlx %g3, 32, %g3 /* IEU0 */
243 andcc %g3, %g2, %g0 /* IEU1 Group */
245 be,pt %xcc, 12f /* CTI */
247 srlx %o2, 56, %g3 /* IEU0 */
248 andcc %g3, 0xff, %g0 /* IEU1 Group */
249 be,pn %icc, 4b /* CTI */
250 srlx %o2, 48, %g3 /* IEU0 */
252 andcc %g3, 0xff, %g0 /* IEU1 Group */
253 be,pn %icc, 4b /* CTI */
254 srlx %o2, 40, %g3 /* IEU0 */
255 andcc %g3, 0xff, %g0 /* IEU1 Group */
257 be,pn %icc, 4b /* CTI */
258 srlx %o2, 32, %g3 /* IEU0 */
259 andcc %g3, 0xff, %g0 /* IEU1 Group */
260 be,pn %icc, 4b /* CTI */
262 12: srlx %o2, 24, %g3 /* IEU0 */
263 andcc %g3, 0xff, %g0 /* IEU1 Group */
264 be,pn %icc, 4b /* CTI */
265 srlx %o2, 16, %g3 /* IEU0 */
267 andcc %g3, 0xff, %g0 /* IEU1 Group */
268 be,pn %icc, 4b /* CTI */
269 srlx %o2, 8, %g3 /* IEU0 */
270 andcc %g3, 0xff, %g0 /* IEU1 Group */
272 be,pn %icc, 4b /* CTI */
273 andcc %o2, 0xff, %g0 /* IEU1 Group */
274 be,pn %icc, 4b /* CTI */
275 sllx %g6, %g5, %o3 /* IEU0 */
277 ba,pt %xcc, 11b /* CTI Group */
278 ldxa [%o1 + %o0] ASI_PNF, %g6 /* Load */
280 libc_hidden_builtin_def (strcmp)