1 | /* Compare two strings for differences. |
2 | For SPARC v7. |
3 | Copyright (C) 1996-2024 Free Software Foundation, Inc. |
4 | This file is part of the GNU C Library. |
5 | |
6 | The GNU C Library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2.1 of the License, or (at your option) any later version. |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Lesser General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Lesser General Public |
17 | License along with the GNU C Library; if not, see |
18 | <https://www.gnu.org/licenses/>. */ |
19 | |
20 | #include <sysdep.h> |
21 | |
22 | /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test |
23 | to find out if any byte in xword could be zero. This is fast, but |
24 | also gives false alarm for any byte in range 0x81-0xff. It does |
25 | not matter for correctness, as if this test tells us there could |
26 | be some zero byte, we check it byte by byte, but if bytes with |
27 | high bits set are common in the strings, then this will give poor |
28 | performance. You can #define EIGHTBIT_NOT_RARE and the algorithm |
29 | will use one tick slower, but more precise test |
30 | ((xword - 0x01010101) & (~xword) & 0x80808080), |
31 | which does not give any false alarms (but if some bits are set, |
32 | one cannot assume from it which bytes are zero and which are not). |
33 | It is yet to be measured, what is the correct default for glibc |
34 | in these days for an average user. |
35 | */ |
36 | |
37 | .text |
38 | .align 4 |
39 | |
40 | ENTRY(strcmp) |
41 | andcc %o0, 3, %g0 |
42 | be 13f |
43 | sethi %hi(0x80808080), %g1 |
44 | |
45 | ldub [%o0], %o4 |
46 | add %o0, 1, %o0 |
47 | ldub [%o1], %o5 |
48 | cmp %o4, 0 |
49 | add %o1, 1, %o1 |
50 | be 2f |
51 | subcc %o4, %o5, %o4 |
52 | bne 2f |
53 | andcc %o0, 3, %g0 |
54 | be 4f |
55 | or %g1, %lo(0x80808080), %o3 |
56 | ldub [%o0], %o4 |
57 | add %o0, 1, %o0 |
58 | ldub [%o1], %o5 |
59 | cmp %o4, 0 |
60 | add %o1, 1, %o1 |
61 | be 2f |
62 | subcc %o4, %o5, %o4 |
63 | bne 2f |
64 | andcc %o0, 3, %g0 |
65 | be 5f |
66 | sethi %hi(0x01010101), %g1 |
67 | ldub [%o0], %o4 |
68 | add %o0, 1, %o0 |
69 | ldub [%o1], %o5 |
70 | cmp %o4, 0 |
71 | add %o1, 1, %o1 |
72 | be 2f |
73 | subcc %o4, %o5, %o4 |
74 | bne 2f |
75 | andcc %o1, 3, %g2 |
76 | bne 12f |
77 | or %g1, %lo(0x01010101), %o2 |
78 | b 1f |
79 | ld [%o0], %o4 |
80 | 2: retl |
81 | mov %o4, %o0 |
82 | |
83 | 13: 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 |
147 | mov -1, %g6 |
148 | add %i1, 4, %i1 |
149 | sub %l1, %g3, %l1 |
150 | sll %g6, %g3, %g6 |
151 | |
152 | 1: sll %l2, %g3, %g5 |
153 | and %i4, %g6, %l3 |
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) |
258 | libc_hidden_builtin_def (strcmp) |
259 | |