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