1 /* strchr (str, ch) -- Return pointer to first occurrence of CH in STR.
3 Copyright (C) 1996, 1999, 2003 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.
48 sethi %hi(0x80808080), %o4
61 or %o4, %lo(0x80808080), %o3
70 sethi %hi(0x01010101), %o5
77 or %o5, %lo(0x01010101), %o2
83 13: or %o4, %lo(0x80808080), %o3
84 4: sethi %hi(0x01010101), %o5
85 5: or %o5, %lo(0x01010101), %o2
89 #ifdef EIGHTBIT_NOT_RARE
101 /* Check every byte. */
103 7: andcc %g5, 0xff, %g5
139 or %o4, %lo(0x80808080), %o3
146 sethi %hi(0x01010101), %o4
152 or %o4, %lo(0x01010101), %o2
156 12: andcc %o0, 3, %g0
158 sethi %hi(0x80808080), %o4
159 or %o4, %lo(0x80808080), %o3
160 4: sethi %hi(0x01010101), %o4
161 5: or %o4, %lo(0x01010101), %o2
164 #ifdef EIGHTBIT_NOT_RARE
171 /* Check every byte. */
200 or %o4, %lo(0x80808080), %o3
210 sethi %hi(0x01010101), %o4
218 1: or %o4, %lo(0x01010101), %o2
230 sethi %hi(0x80808080), %o4
234 or %o4, %lo(0x80808080), %o3
235 4: sethi %hi(0x01010101), %o4
236 5: or %o4, %lo(0x01010101), %o2
240 #ifdef EIGHTBIT_NOT_RARE
252 /* Check every byte. */
254 8: andcc %g5, 0xff, %g5
271 1: andcc %g4, 0xff, %g5
282 weak_alias (strchr, index)
283 weak_alias (strrchr, rindex)
284 libc_hidden_builtin_def (strchr)
285 libc_hidden_builtin_def (strrchr)