1 /* Optimized strchr implementation for PowerPC.
2 Copyright (C) 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
22 /* See strlen.s for comments on how this works. */
24 /* char * [r3] strchr (const char *s [r3] , int c [r4] )
27 r3: our return result.
28 r4: byte we're looking for, spread over the whole word
30 r6: the constant 0xfefefeff (-0x01010101)
31 r7: the constant 0x7f7f7f7f
32 r8: pointer to the current word.
34 r10: the number of bits we should ignore in the first word
35 r11: a mask with the bits to ignore set to 0
38 rlwimi %r4,%r4,8,16,23
40 rlwimi %r4,%r4,16,0,15
45 addi %r6,%r6,0xfffffeff
46 rlwinm %r10,%r3,3,27,28
47 /* Test the first (partial?) word. */
60 L(loop):lwzu %r5,4(%r8)
67 /* Start test for the bytes we're looking for. */
73 /* There is a zero byte in the word, but may also be a matching byte (either
74 before or after the zero byte). In fact, we may be looking for a
75 zero byte, in which case we return a match. We guess that this hasn't
81 /* It did happen. Decide which one was first...
82 I'm not sure if this is actually faster than a sequence of
83 rotates, compares, and branches (we use it anyway because it's shorter). */
111 weak_alias(strchr,index)