]>
Commit | Line | Data |
---|---|---|
ae6b8730 RH |
1 | /* Compare two strings for differences. |
2 | For SPARC v7. | |
62f29da7 | 3 | Copyright (C) 1996, 97, 99, 2003 Free Software Foundation, Inc. |
ae6b8730 RH |
4 | This file is part of the GNU C Library. |
5 | Contributed by Jakub Jelinek <jj@ultra.linux.cz>. | |
6 | ||
7 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
8 | modify it under the terms of the GNU Lesser General Public |
9 | License as published by the Free Software Foundation; either | |
10 | version 2.1 of the License, or (at your option) any later version. | |
ae6b8730 RH |
11 | |
12 | The GNU C Library is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 15 | Lesser General Public License for more details. |
ae6b8730 | 16 | |
41bdb6e2 AJ |
17 | You should have received a copy of the GNU Lesser General Public |
18 | License along with the GNU C Library; if not, write to the Free | |
19 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
20 | 02111-1307 USA. */ | |
ae6b8730 RH |
21 | |
22 | #include <sysdep.h> | |
23 | ||
24 | /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test | |
25 | to find out if any byte in xword could be zero. This is fast, but | |
26 | also gives false alarm for any byte in range 0x81-0xff. It does | |
27 | not matter for correctness, as if this test tells us there could | |
28 | be some zero byte, we check it byte by byte, but if bytes with | |
29 | high bits set are common in the strings, then this will give poor | |
30 | performance. You can #define EIGHTBIT_NOT_RARE and the algorithm | |
31 | will use one tick slower, but more precise test | |
32 | ((xword - 0x01010101) & (~xword) & 0x80808080), | |
33 | which does not give any false alarms (but if some bits are set, | |
34 | one cannot assume from it which bytes are zero and which are not). | |
35 | It is yet to be measured, what is the correct default for glibc | |
36 | in these days for an average user. | |
37 | */ | |
38 | ||
39 | .text | |
40 | .align 4 | |
41 | 10: ldub [%o0], %o4 | |
42 | add %o0, 1, %o0 | |
43 | ldub [%o1], %o5 | |
44 | cmp %o4, 0 | |
45 | add %o1, 1, %o1 | |
46 | be 2f | |
47 | subcc %o4, %o5, %o4 | |
48 | bne 2f | |
49 | andcc %o0, 3, %g0 | |
50 | be 4f | |
51 | or %g1, %lo(0x80808080), %o3 | |
52 | ldub [%o0], %o4 | |
53 | add %o0, 1, %o0 | |
54 | ldub [%o1], %o5 | |
55 | cmp %o4, 0 | |
56 | add %o1, 1, %o1 | |
57 | be 2f | |
58 | subcc %o4, %o5, %o4 | |
59 | bne 2f | |
60 | andcc %o0, 3, %g0 | |
61 | be 5f | |
62 | sethi %hi(0x01010101), %g1 | |
63 | ldub [%o0], %o4 | |
64 | add %o0, 1, %o0 | |
65 | ldub [%o1], %o5 | |
66 | cmp %o4, 0 | |
67 | add %o1, 1, %o1 | |
68 | be 2f | |
69 | subcc %o4, %o5, %o4 | |
70 | bne 2f | |
71 | andcc %o1, 3, %g2 | |
72 | bne 12f | |
73 | or %g1, %lo(0x01010101), %o2 | |
74 | b 1f | |
75 | ld [%o0], %o4 | |
76 | 2: retl | |
77 | mov %o4, %o0 | |
78 | ||
79 | ENTRY(strcmp) | |
80 | andcc %o0, 3, %g0 | |
81 | bne 10b | |
82 | sethi %hi(0x80808080), %g1 | |
83 | or %g1, %lo(0x80808080), %o3 | |
84 | 4: sethi %hi(0x01010101), %g1 | |
85 | 5: andcc %o1, 3, %g2 | |
86 | bne 12f | |
87 | or %g1, %lo(0x01010101), %o2 | |
88 | ||
89 | 0: ld [%o0], %o4 | |
90 | 1: ld [%o1], %o5 | |
91 | sub %o4, %o2, %g1 | |
92 | add %o0, 4, %o0 | |
93 | cmp %o4, %o5 | |
94 | #ifdef EIGHTBIT_NOT_RARE | |
95 | andn %g1, %o4, %g1 | |
96 | #endif | |
97 | bne 11f | |
98 | andcc %g1, %o3, %g0 | |
99 | be 0b | |
100 | add %o1, 4, %o1 | |
101 | ||
102 | srl %o4, 24, %g4 | |
103 | andcc %g4, 0xff, %g0 | |
104 | be 2f | |
105 | srl %o4, 16, %g4 | |
106 | andcc %g4, 0xff, %g0 | |
107 | be 2f | |
108 | srl %o4, 8, %g4 | |
109 | andcc %g4, 0xff, %g0 | |
110 | be 2f | |
111 | andcc %o4, 0xff, %g0 | |
112 | bne,a 1b | |
113 | ld [%o0], %o4 | |
114 | 2: retl | |
115 | clr %o0 | |
116 | ||
117 | 11: srl %o4, 24, %g4 | |
118 | srl %o5, 24, %g5 | |
119 | andcc %g4, 0xff, %g0 | |
120 | be 3f | |
121 | subcc %g4, %g5, %g4 | |
122 | bne 3f | |
123 | srl %o5, 16, %g5 | |
124 | srl %o4, 16, %g4 | |
125 | andcc %g4, 0xff, %g0 | |
126 | be 3f | |
127 | subcc %g4, %g5, %g4 | |
128 | bne 3f | |
129 | srl %o5, 8, %g5 | |
130 | srl %o4, 8, %g4 | |
131 | andcc %g4, 0xff, %g0 | |
132 | be 3f | |
133 | subcc %g4, %g5, %g4 | |
134 | bne 3f | |
135 | subcc %o4, %o5, %o4 | |
136 | retl | |
137 | mov %o4, %o0 | |
138 | 3: retl | |
139 | mov %g4, %o0 | |
140 | ||
141 | 12: save %sp, -64, %sp | |
142 | ld [%i0], %i4 | |
143 | sll %g2, 3, %g3 | |
144 | andn %i1, 3, %i1 | |
145 | mov 32, %l1 | |
146 | ld [%i1], %l2 | |
62f29da7 | 147 | mov -1, %g6 |
ae6b8730 RH |
148 | add %i1, 4, %i1 |
149 | sub %l1, %g3, %l1 | |
62f29da7 | 150 | sll %g6, %g3, %g6 |
ae6b8730 RH |
151 | |
152 | 1: sll %l2, %g3, %g5 | |
62f29da7 | 153 | and %i4, %g6, %l3 |
ae6b8730 RH |
154 | sub %i4, %i2, %g1 |
155 | #ifdef EIGHTBIT_NOT_RARE | |
156 | andn %g1, %i4, %g1 | |
157 | #endif | |
158 | andcc %g1, %i3, %g1 | |
159 | bne 3f | |
160 | cmp %g5, %l3 | |
161 | bne 2f | |
162 | add %i0, 4, %i0 | |
163 | ld [%i1], %l2 | |
164 | add %i1, 4, %i1 | |
165 | srl %l2, %l1, %l4 | |
166 | or %l4, %g5, %l4 | |
167 | cmp %l4, %i4 | |
168 | be,a 1b | |
169 | ld [%i0], %i4 | |
170 | restore %l4, %g0, %o3 | |
171 | retl | |
172 | sub %o4, %o3, %o0 | |
173 | ||
174 | 2: sll %l2, %g3, %i2 | |
175 | srl %i4, %g3, %i3 | |
176 | srl %i2, %g3, %i2 | |
177 | restore | |
178 | retl | |
179 | sub %o3, %o2, %o0 | |
180 | ||
181 | 3: srl %i4, 24, %g4 | |
182 | srl %g5, 24, %l6 | |
183 | andcc %g4, 0xff, %g0 | |
184 | be 4f | |
185 | subcc %g4, %l6, %g4 | |
186 | bne 4f | |
187 | cmp %g2, 3 | |
188 | be 6f | |
189 | srl %i4, 16, %g4 | |
190 | srl %g5, 16, %l6 | |
191 | andcc %g4, 0xff, %g0 | |
192 | be 4f | |
193 | subcc %g4, %l6, %g4 | |
194 | bne 4f | |
195 | cmp %g2, 2 | |
196 | be 5f | |
197 | srl %i4, 8, %g4 | |
198 | srl %g5, 8, %l6 | |
199 | andcc %g4, 0xff, %g0 | |
200 | be 4f | |
201 | subcc %g4, %l6, %g4 | |
202 | bne 4f | |
203 | add %i0, 4, %i0 | |
204 | ld [%i1], %l2 | |
205 | add %i1, 4, %i1 | |
206 | srl %l2, 24, %g5 | |
207 | andcc %i4, 0xff, %g4 | |
208 | be 4f | |
209 | subcc %g4, %g5, %g4 | |
210 | be,a 1b | |
211 | ld [%i0], %i4 | |
212 | 4: jmpl %i7 + 8, %g0 | |
213 | restore %g4, %g0, %o0 | |
214 | ||
215 | 5: ld [%i1], %l2 | |
216 | add %i1, 4, %i1 | |
217 | add %i0, 4, %i0 | |
218 | srl %l2, 24, %l6 | |
219 | andcc %g4, 0xff, %g4 | |
220 | be 4b | |
221 | subcc %g4, %l6, %g4 | |
222 | bne 4b | |
223 | srl %l2, 16, %l6 | |
224 | andcc %i4, 0xff, %g4 | |
225 | and %l6, 0xff, %l6 | |
226 | be 4b | |
227 | subcc %g4, %l6, %g4 | |
228 | be,a 1b | |
229 | ld [%i0], %i4 | |
230 | jmpl %i7 + 8, %g0 | |
231 | restore %g4, %g0, %o0 | |
232 | ||
233 | 6: ld [%i1], %l2 | |
234 | add %i1, 4, %i1 | |
235 | add %i0, 4, %i0 | |
236 | srl %l2, 24, %l6 | |
237 | andcc %g4, 0xff, %g4 | |
238 | be 4b | |
239 | subcc %g4, %l6, %g4 | |
240 | bne 4b | |
241 | srl %l2, 16, %l6 | |
242 | srl %i4, 8, %g4 | |
243 | and %l6, 0xff, %l6 | |
244 | andcc %g4, 0xff, %g4 | |
245 | be 4b | |
246 | subcc %g4, %l6, %g4 | |
247 | bne 4b | |
248 | srl %l2, 8, %l6 | |
249 | andcc %i4, 0xff, %g4 | |
250 | and %l6, 0xff, %l6 | |
251 | be 4b | |
252 | subcc %g4, %l6, %g4 | |
253 | be,a 1b | |
254 | ld [%i0], %i4 | |
255 | jmpl %i7 + 8, %g0 | |
256 | restore %g4, %g0, %o0 | |
257 | END(strcmp) |