]>
Commit | Line | Data |
---|---|---|
bfff8b1b | 1 | /* Copyright (C) 2000-2017 Free Software Foundation, Inc. |
63b2d532 UD |
2 | Contributed by Richard Henderson <rth@tamu.edu>, 1996. |
3 | EV67 optimized by Rick Gorton <rick.gorton@alpha-processor.com>. | |
63b2d532 UD |
4 | This file is part of the GNU C Library. |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
3214b89b AJ |
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. | |
63b2d532 UD |
10 | |
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 | |
3214b89b | 14 | Lesser General Public License for more details. |
63b2d532 | 15 | |
3214b89b | 16 | You should have received a copy of the GNU Lesser General Public |
ab84e3ff PE |
17 | License along with the GNU C Library. If not, see |
18 | <http://www.gnu.org/licenses/>. */ | |
63b2d532 UD |
19 | |
20 | /* Return the address of a given character within a null-terminated | |
21 | string, or null if it is not found. */ | |
22 | ||
23 | #include <sysdep.h> | |
24 | ||
25 | .arch ev6 | |
26 | .set noreorder | |
27 | .set noat | |
28 | ||
29 | ENTRY(strchr) | |
30 | #ifdef PROF | |
31 | ldgp gp, 0(pv) | |
32 | lda AT, _mcount | |
33 | jsr AT, (AT), _mcount | |
34 | .prologue 1 | |
35 | #else | |
36 | .prologue 0 | |
37 | #endif | |
38 | ||
39 | ldq_u t0, 0(a0) # L : load first quadword Latency=3 | |
40 | and a1, 0xff, t3 # E : 00000000000000ch | |
41 | insbl a1, 1, t5 # U : 000000000000ch00 | |
42 | insbl a1, 7, a2 # U : ch00000000000000 | |
43 | ||
44 | insbl t3, 6, a3 # U : 00ch000000000000 | |
45 | or t5, t3, a1 # E : 000000000000chch | |
46 | andnot a0, 7, v0 # E : align our loop pointer | |
47 | lda t4, -1 # E : build garbage mask | |
48 | ||
49 | mskqh t4, a0, t4 # U : only want relevant part of first quad | |
50 | or a2, a3, a2 # E : chch000000000000 | |
51 | inswl a1, 2, t5 # E : 00000000chch0000 | |
52 | inswl a1, 4, a3 # E : 0000chch00000000 | |
53 | ||
54 | or a1, a2, a1 # E : chch00000000chch | |
55 | or a3, t5, t5 # E : 0000chchchch0000 | |
56 | cmpbge zero, t0, t2 # E : bits set iff byte == zero | |
57 | cmpbge zero, t4, t4 # E : bits set iff byte is garbage | |
58 | ||
59 | /* This quad is _very_ serialized. Lots of stalling happens */ | |
60 | or t5, a1, a1 # E : chchchchchchchch | |
61 | xor t0, a1, t1 # E : make bytes == c zero | |
62 | cmpbge zero, t1, t3 # E : bits set iff byte == c | |
63 | or t2, t3, t0 # E : bits set iff char match or zero match | |
64 | ||
65 | andnot t0, t4, t0 # E : clear garbage bits | |
66 | cttz t0, a2 # U0 : speculative (in case we get a match) | |
67 | nop # E : | |
68 | bne t0, $found # U : | |
69 | ||
70 | /* | |
71 | * Yuk. This loop is going to stall like crazy waiting for the | |
72 | * data to be loaded. Not much can be done about it unless it's | |
73 | * unrolled multiple times, which is generally unsafe. | |
74 | */ | |
75 | $loop: | |
76 | ldq t0, 8(v0) # L : Latency=3 | |
77 | addq v0, 8, v0 # E : | |
78 | xor t0, a1, t1 # E : | |
79 | cmpbge zero, t0, t2 # E : bits set iff byte == 0 | |
80 | ||
81 | cmpbge zero, t1, t3 # E : bits set iff byte == c | |
82 | or t2, t3, t0 # E : | |
83 | cttz t3, a2 # U0 : speculative (in case we get a match) | |
84 | beq t0, $loop # U : | |
85 | ||
86 | $found: | |
87 | negq t0, t1 # E : clear all but least set bit | |
88 | and t0, t1, t0 # E : | |
89 | and t0, t3, t1 # E : bit set iff byte was the char | |
90 | addq v0, a2, v0 # E : Add in the bit number from above | |
91 | ||
92 | cmoveq t1, $31, v0 # E : Two mapping slots, latency = 2 | |
93 | nop | |
94 | nop | |
95 | ret # L0 : | |
96 | ||
97 | END(strchr) | |
98 | ||
99 | weak_alias (strchr, index) | |
79b7c863 | 100 | libc_hidden_builtin_def (strchr) |