]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/sparc/sparc32/strchr.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / sparc / sparc32 / strchr.S
CommitLineData
ae6b8730
RH
1/* strchr (str, ch) -- Return pointer to first occurrence of CH in STR.
2 For SPARC v7.
f7a9f785 3 Copyright (C) 1996-2016 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> and
6 David S. Miller <davem@caip.rutgers.edu>.
7
8 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
ae6b8730
RH
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
41bdb6e2 16 Lesser General Public License for more details.
ae6b8730 17
41bdb6e2 18 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
19 License along with the GNU C Library; if not, see
20 <http://www.gnu.org/licenses/>. */
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
043cee37
RM
41ENTRY(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
ae6b8730 53 cmp %g4, %o1
043cee37 54 be 11f
ae6b8730
RH
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
043cee37 63 be 11f
ae6b8730
RH
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
043cee37 72 be 11f
ae6b8730
RH
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
043cee37 7911: retl
ae6b8730
RH
80 sub %o0, 1, %o0
81
043cee37 8213: or %o4, %lo(0x80808080), %o3
ae6b8730
RH
834: sethi %hi(0x01010101), %o5
845: or %o5, %lo(0x01010101), %o2
857: ld [%o0], %g4
866: xor %g4, %g2, %g5
87 sub %g4, %o2, %o4
88#ifdef EIGHTBIT_NOT_RARE
62f29da7 89 sub %g5, %o2, %g6
ae6b8730 90 andn %o4, %g4, %o4
62f29da7 91 andn %g6, %g5, %g5
ae6b8730
RH
92#else
93 sub %g5, %o2, %g5
94#endif
9c84384c 95 or %g5, %o4, %o4
ae6b8730
RH
96 andcc %o4, %o3, %g0
97 be 7b
98 add %o0, 4, %o0
99
100 /* Check every byte. */
9c84384c 1018: srl %g4, 24, %g5
ae6b8730
RH
1027: 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
1232: retl
124 sub %o0, 2, %o0
1253: retl
126 sub %o0, 3, %o0
1274: retl
128 sub %o0, 4, %o0
1299: retl
130 clr %o0
131
13211: 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
1521: retl
153 sub %o0, 1, %o0
154
15512: andcc %o0, 3, %g0
156 bne 11b
157 sethi %hi(0x80808080), %o4
158 or %o4, %lo(0x80808080), %o3
1594: sethi %hi(0x01010101), %o4
1605: or %o4, %lo(0x01010101), %o2
1616: ld [%o0], %o5
1627: 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
1878: retl
188 mov %o4, %o0
189
19013: 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
1971: 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
2071: 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
2171: or %o4, %lo(0x01010101), %o2
218 b 7f
219 ld [%o0], %g4
220END(strchr)
221
222ENTRY(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
2344: sethi %hi(0x01010101), %o4
2355: or %o4, %lo(0x01010101), %o2
2366: ld [%o0], %g4
2377: xor %g4, %g2, %g5
238 sub %g4, %o2, %o4
239#ifdef EIGHTBIT_NOT_RARE
62f29da7 240 sub %g5, %o2, %g6
ae6b8730 241 andn %o4, %g4, %o4
62f29da7 242 andn %g6, %g5, %g5
ae6b8730
RH
243#else
244 sub %g5, %o2, %g5
245#endif
9c84384c 246 or %g5, %o4, %o4
ae6b8730
RH
247 andcc %o4, %o3, %g0
248 be 6b
249 add %o0, 4, %o0
250
251 /* Check every byte. */
9c84384c 2523: srl %g4, 24, %g5
ae6b8730
RH
2538: andcc %g5, 0xff, %g5
254 be 9f
255 cmp %g5, %o1
256 be,a 1f
257 sub %o0, 4, %o5
2581: 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
2641: 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
2701: andcc %g4, 0xff, %g5
271 be 9f
272 cmp %g5, %o1
273 be,a 1f
274 sub %o0, 1, %o5
2751: b 7b
276 ld [%o0], %g4
2779: retl
278 mov %o5, %o0
279END(strrchr)
280
1ab18a5b
UD
281weak_alias (strchr, index)
282weak_alias (strrchr, rindex)
85dd1003
UD
283libc_hidden_builtin_def (strchr)
284libc_hidden_builtin_def (strrchr)