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