]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/sparc/sparc32/strchr.S
e3567aba82a087b17fd8422e34c1c4a28797a0cd
[thirdparty/glibc.git] / sysdeps / sparc / sparc32 / strchr.S
1 /* strchr (str, ch) -- Return pointer to first occurrence of CH in STR.
2 For SPARC v7.
3 Copyright (C) 1996-2019 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Jakub Jelinek <jj@ultra.linux.cz> and
6 David S. Miller <davem@caip.rutgers.edu>.
7
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.
12
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.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library; if not, see
20 <http://www.gnu.org/licenses/>. */
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 ENTRY(strchr)
42 andcc %o1, 0xff, %o1
43 be 12f
44 sll %o1, 8, %o2
45 andcc %o0, 3, %g0
46 or %o1, %o2, %o2
47 sethi %hi(0x80808080), %o4
48 sll %o2, 16, %o3
49 be 13f
50 or %o3, %o2, %g2
51
52 ldub [%o0], %g4
53 cmp %g4, %o1
54 be 11f
55 add %o0, 1, %o0
56 cmp %g4, 0
57 be 9f
58 andcc %o0, 3, %g0
59 be 4f
60 or %o4, %lo(0x80808080), %o3
61 ldub [%o0], %g4
62 cmp %g4, %o1
63 be 11f
64 add %o0, 1, %o0
65 cmp %g4, 0
66 be 9f
67 andcc %o0, 3, %g0
68 be 5f
69 sethi %hi(0x01010101), %o5
70 ldub [%o0], %g4
71 cmp %g4, %o1
72 be 11f
73 add %o0, 1, %o0
74 cmp %g4, 0
75 be 9f
76 or %o5, %lo(0x01010101), %o2
77 b 6f
78 ld [%o0], %g4
79 11: retl
80 sub %o0, 1, %o0
81
82 13: or %o4, %lo(0x80808080), %o3
83 4: sethi %hi(0x01010101), %o5
84 5: or %o5, %lo(0x01010101), %o2
85 7: ld [%o0], %g4
86 6: xor %g4, %g2, %g5
87 sub %g4, %o2, %o4
88 #ifdef EIGHTBIT_NOT_RARE
89 sub %g5, %o2, %g6
90 andn %o4, %g4, %o4
91 andn %g6, %g5, %g5
92 #else
93 sub %g5, %o2, %g5
94 #endif
95 or %g5, %o4, %o4
96 andcc %o4, %o3, %g0
97 be 7b
98 add %o0, 4, %o0
99
100 /* Check every byte. */
101 8: srl %g4, 24, %g5
102 7: andcc %g5, 0xff, %g5
103 be 9f
104 cmp %g5, %o1
105 be 4f
106 srl %g4, 16, %g5
107 andcc %g5, 0xff, %g5
108 be 9f
109 cmp %g5, %o1
110 be 3f
111 srl %g4, 8, %g5
112 andcc %g5, 0xff, %g5
113 be 9f
114 cmp %g5, %o1
115 be 2f
116 andcc %g4, 0xff, %g5
117 be 9f
118 cmp %g5, %o1
119 bne,a 6b
120 ld [%o0], %g4
121 retl
122 sub %o0, 1, %o0
123 2: retl
124 sub %o0, 2, %o0
125 3: retl
126 sub %o0, 3, %o0
127 4: retl
128 sub %o0, 4, %o0
129 9: retl
130 clr %o0
131
132 11: ldub [%o0], %o5
133 cmp %o5, 0
134 be 1f
135 add %o0, 1, %o0
136 andcc %o0, 3, %g0
137 be 4f
138 or %o4, %lo(0x80808080), %o3
139 ldub [%o0], %o5
140 cmp %o5, 0
141 be 1f
142 add %o0, 1, %o0
143 andcc %o0, 3, %g0
144 be 5f
145 sethi %hi(0x01010101), %o4
146 ldub [%o0], %o5
147 cmp %o5, 0
148 be 1f
149 add %o0, 1, %o0
150 b 6f
151 or %o4, %lo(0x01010101), %o2
152 1: retl
153 sub %o0, 1, %o0
154
155 12: andcc %o0, 3, %g0
156 bne 11b
157 sethi %hi(0x80808080), %o4
158 or %o4, %lo(0x80808080), %o3
159 4: sethi %hi(0x01010101), %o4
160 5: or %o4, %lo(0x01010101), %o2
161 6: ld [%o0], %o5
162 7: sub %o5, %o2, %o4
163 #ifdef EIGHTBIT_NOT_RARE
164 andn %o4, %o5, %o4
165 #endif
166 andcc %o4, %o3, %g0
167 be 6b
168 add %o0, 4, %o0
169
170 /* Check every byte. */
171 srl %o5, 24, %g5
172 andcc %g5, 0xff, %g0
173 be 8f
174 add %o0, -4, %o4
175 srl %o5, 16, %g5
176 andcc %g5, 0xff, %g0
177 be 8f
178 add %o4, 1, %o4
179 srl %o5, 8, %g5
180 andcc %g5, 0xff, %g0
181 be 8f
182 add %o4, 1, %o4
183 andcc %o5, 0xff, %g0
184 bne,a 7b
185 ld [%o0], %o5
186 add %o4, 1, %o4
187 8: retl
188 mov %o4, %o0
189
190 13: ldub [%o0], %g4
191 cmp %g4, %o1
192 add %o0, 1, %o0
193 be,a 1f
194 sub %o0, 1, %o5
195 cmp %g4, 0
196 be 9f
197 1: andcc %o0, 3, %g0
198 be 4f
199 or %o4, %lo(0x80808080), %o3
200 ldub [%o0], %g4
201 cmp %g4, %o1
202 add %o0, 1, %o0
203 be,a 1f
204 sub %o0, 1, %o5
205 cmp %g4, 0
206 be 9f
207 1: andcc %o0, 3, %g0
208 be 5f
209 sethi %hi(0x01010101), %o4
210 ldub [%o0], %g4
211 cmp %g4, %o1
212 add %o0, 1, %o0
213 be,a 1f
214 sub %o0, 1, %o5
215 cmp %g4, 0
216 be 9f
217 1: or %o4, %lo(0x01010101), %o2
218 b 7f
219 ld [%o0], %g4
220 END(strchr)
221
222 ENTRY(strrchr)
223 andcc %o1, 0xff, %o1
224 clr %o5
225 be 12b
226 sll %o1, 8, %o2
227 andcc %o0, 3, %g0
228 or %o1, %o2, %o2
229 sethi %hi(0x80808080), %o4
230 sll %o2, 16, %o3
231 bne 13b
232 or %o3, %o2, %g2
233 or %o4, %lo(0x80808080), %o3
234 4: sethi %hi(0x01010101), %o4
235 5: or %o4, %lo(0x01010101), %o2
236 6: ld [%o0], %g4
237 7: xor %g4, %g2, %g5
238 sub %g4, %o2, %o4
239 #ifdef EIGHTBIT_NOT_RARE
240 sub %g5, %o2, %g6
241 andn %o4, %g4, %o4
242 andn %g6, %g5, %g5
243 #else
244 sub %g5, %o2, %g5
245 #endif
246 or %g5, %o4, %o4
247 andcc %o4, %o3, %g0
248 be 6b
249 add %o0, 4, %o0
250
251 /* Check every byte. */
252 3: srl %g4, 24, %g5
253 8: andcc %g5, 0xff, %g5
254 be 9f
255 cmp %g5, %o1
256 be,a 1f
257 sub %o0, 4, %o5
258 1: srl %g4, 16, %g5
259 andcc %g5, 0xff, %g5
260 be 9f
261 cmp %g5, %o1
262 be,a 1f
263 sub %o0, 3, %o5
264 1: srl %g4, 8, %g5
265 andcc %g5, 0xff, %g5
266 be 9f
267 cmp %g5, %o1
268 be,a 1f
269 sub %o0, 2, %o5
270 1: andcc %g4, 0xff, %g5
271 be 9f
272 cmp %g5, %o1
273 be,a 1f
274 sub %o0, 1, %o5
275 1: b 7b
276 ld [%o0], %g4
277 9: retl
278 mov %o5, %o0
279 END(strrchr)
280
281 weak_alias (strchr, index)
282 weak_alias (strrchr, rindex)
283 libc_hidden_builtin_def (strchr)
284 libc_hidden_builtin_def (strrchr)