1 /* strchr (str, ch) -- Return pointer to first occurrence of CH in STR.
3 Copyright (C) 1996, 1999 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>.
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.
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.
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library; if not, write to the Free
20 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test
26 to find out if any byte in xword could be zero. This is fast, but
27 also gives false alarm for any byte in range 0x81-0xff. It does
28 not matter for correctness, as if this test tells us there could
29 be some zero byte, we check it byte by byte, but if bytes with
30 high bits set are common in the strings, then this will give poor
31 performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
32 will use one tick slower, but more precise test
33 ((xword - 0x01010101) & (~xword) & 0x80808080),
34 which does not give any false alarms (but if some bits are set,
35 one cannot assume from it which bytes are zero and which are not).
36 It is yet to be measured, what is the correct default for glibc
37 in these days for an average user.
50 or %o4, %lo(0x80808080), %o3
59 sethi %hi(0x01010101), %o5
66 or %o5, %lo(0x01010101), %o2
78 sethi %hi(0x80808080), %o4
82 or %o4, %lo(0x80808080), %o3
83 4: sethi %hi(0x01010101), %o5
84 5: or %o5, %lo(0x01010101), %o2
88 #ifdef EIGHTBIT_NOT_RARE
100 /* Check every byte. */
102 7: andcc %g5, 0xff, %g5
138 or %o4, %lo(0x80808080), %o3
145 sethi %hi(0x01010101), %o4
151 or %o4, %lo(0x01010101), %o2
155 12: andcc %o0, 3, %g0
157 sethi %hi(0x80808080), %o4
158 or %o4, %lo(0x80808080), %o3
159 4: sethi %hi(0x01010101), %o4
160 5: or %o4, %lo(0x01010101), %o2
163 #ifdef EIGHTBIT_NOT_RARE
170 /* Check every byte. */
199 or %o4, %lo(0x80808080), %o3
209 sethi %hi(0x01010101), %o4
217 1: or %o4, %lo(0x01010101), %o2
229 sethi %hi(0x80808080), %o4
233 or %o4, %lo(0x80808080), %o3
234 4: sethi %hi(0x01010101), %o4
235 5: or %o4, %lo(0x01010101), %o2
239 #ifdef EIGHTBIT_NOT_RARE
251 /* Check every byte. */
253 8: andcc %g5, 0xff, %g5
270 1: andcc %g4, 0xff, %g5
281 weak_alias(strchr, index)
282 weak_alias(strrchr, rindex)