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.
20 # See strlen.s for comments on how this works.
25 .type strchr,@function
27 # char * [r3] strchr (const char *s [r3] , int c [r4] )
30 # r3: our return result.
31 # r4: byte we're looking for, spread over the whole word
32 # r5: the current word
33 # r6: the constant 0xfefefeff (-0x01010101)
34 # r7: the constant 0x7f7f7f7f
35 # r8: pointer to the current word.
37 # r10: the number of bits we should ignore in the first word
38 # r11: a mask with the bits to ignore set to 0
41 rlwimi %r4,%r4,8,16,23
43 rlwimi %r4,%r4,16,0,15
48 addi %r6,%r6,0xfffffeff
49 rlwinm %r10,%r3,3,27,28
50 # Test the first (partial?) word.
70 # Start test for the bytes we're looking for
76 # There is a zero byte in the word, but may also be a matching byte (either
77 # before or after the zero byte). In fact, we may be looking for a
78 # zero byte, in which case we return a match. We guess that this hasn't
84 # It did happen. Decide which one was first...
85 # I'm not sure if this is actually faster than a sequence of
86 # rotates, compares, and branches (we use it anyway because it's shorter).
114 .size strchr,0b-strchr