1 /* Copyright (C) 2000, 2003 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@tamu.edu>, 1996.
3 EV67 optimized by Rick Gorton <rick.gorton@alpha-processor.com>.
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 Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the 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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 /* Return the address of a given character within a null-terminated
22 string, or null if it is not found. */
40 ldq_u t0, 0(a0) # L : load first quadword Latency=3
41 and a1, 0xff, t3 # E : 00000000000000ch
42 insbl a1, 1, t5 # U : 000000000000ch00
43 insbl a1, 7, a2 # U : ch00000000000000
45 insbl t3, 6, a3 # U : 00ch000000000000
46 or t5, t3, a1 # E : 000000000000chch
47 andnot a0, 7, v0 # E : align our loop pointer
48 lda t4, -1 # E : build garbage mask
50 mskqh t4, a0, t4 # U : only want relevant part of first quad
51 or a2, a3, a2 # E : chch000000000000
52 inswl a1, 2, t5 # E : 00000000chch0000
53 inswl a1, 4, a3 # E : 0000chch00000000
55 or a1, a2, a1 # E : chch00000000chch
56 or a3, t5, t5 # E : 0000chchchch0000
57 cmpbge zero, t0, t2 # E : bits set iff byte == zero
58 cmpbge zero, t4, t4 # E : bits set iff byte is garbage
60 /* This quad is _very_ serialized. Lots of stalling happens */
61 or t5, a1, a1 # E : chchchchchchchch
62 xor t0, a1, t1 # E : make bytes == c zero
63 cmpbge zero, t1, t3 # E : bits set iff byte == c
64 or t2, t3, t0 # E : bits set iff char match or zero match
66 andnot t0, t4, t0 # E : clear garbage bits
67 cttz t0, a2 # U0 : speculative (in case we get a match)
72 * Yuk. This loop is going to stall like crazy waiting for the
73 * data to be loaded. Not much can be done about it unless it's
74 * unrolled multiple times, which is generally unsafe.
77 ldq t0, 8(v0) # L : Latency=3
80 cmpbge zero, t0, t2 # E : bits set iff byte == 0
82 cmpbge zero, t1, t3 # E : bits set iff byte == c
84 cttz t3, a2 # U0 : speculative (in case we get a match)
88 negq t0, t1 # E : clear all but least set bit
90 and t0, t3, t1 # E : bit set iff byte was the char
91 addq v0, a2, v0 # E : Add in the bit number from above
93 cmoveq t1, $31, v0 # E : Two mapping slots, latency = 2
100 weak_alias (strchr, index)
101 libc_hidden_builtin_def (strchr)