1 /* Copyright (C) 1996 Free Software Foundation, Inc.
2 Contributed by Richard Henderson (rth@tamu.edu)
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If
18 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 Cambridge, MA 02139, USA. */
21 /* Return the address of a given character within a null-terminated
22 string, or null if it is not found.
24 This is generally scheduled for the EV5 (got to look out for my own
25 interests :-), but with EV4 needs in mind. There *should* be no more
26 stalls for the EV4 than there are for the EV5.
37 zapnot a1, 1, a1 # e0 : zero extend the search character
38 ldq_u t0, 0(a0) # .. e1 : load first quadword
39 sll a1, 8, t5 # e0 : replicate the search character
40 andnot a0, 7, v0 # .. e1 : align our loop pointer
42 lda t4, -1 # .. e1 : build garbage mask
44 cmpbge zero, t0, t2 # .. e1 : bits set iff byte == zero
45 mskqh t4, a0, t4 # e0 :
46 or t5, a1, a1 # .. e1 :
48 cmpbge zero, t4, t4 # .. e1 : bits set iff byte is garbage
50 xor t0, a1, t1 # .. e1 : make bytes == c zero
51 cmpbge zero, t1, t3 # e0 : bits set iff byte == c
52 or t2, t3, t0 # e1 : bits set iff char match or zero match
53 andnot t0, t4, t0 # e0 : clear garbage bits
54 bne t0, $found # .. e1 (zdb)
56 $loop: ldq t0, 8(v0) # e0 :
57 addq v0, 8, v0 # .. e1 :
59 xor t0, a1, t1 # .. e1 (ev5 data stall)
60 cmpbge zero, t0, t2 # e0 : bits set iff byte == 0
61 cmpbge zero, t1, t3 # .. e1 : bits set iff byte == c
63 beq t0, $loop # .. e1 (zdb)
65 $found: negq t0, t1 # e0 : clear all but least set bit
66 and t0, t1, t0 # e1 (stall)
68 and t0, t3, t1 # e0 : bit set iff byte was the char
69 beq t1, $retnull # .. e1 (zdb)
71 and t0, 0xf0, t2 # e0 : binary search for that set bit
72 and t0, 0xcc, t3 # .. e1 :
73 and t0, 0xaa, t4 # e0 :
74 cmovne t2, 4, t2 # .. e1 :
75 cmovne t3, 2, t3 # e0 :
76 cmovne t4, 1, t4 # .. e1 :
77 addq t2, t3, t2 # e0 :
78 addq v0, t4, v0 # .. e1 :
79 addq v0, t2, v0 # e0 :
88 weak_alias (strchr, index)