Warning: That file was not part of the compilation database. It may have many parsing errors.

1/* Copyright (C) 1996-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Richard Henderson (rth@tamu.edu)
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
18
19/* Return the address of a given character within a null-terminated
20 string, or null if it is not found.
21
22 This is generally scheduled for the EV5 (got to look out for my own
23 interests :-), but with EV4 needs in mind. There *should* be no more
24 stalls for the EV4 than there are for the EV5.
25*/
26
27#include <sysdep.h>
28
29 .set noreorder
30 .set noat
31
32ENTRY(strchr)
33#ifdef PROF
34 ldgp gp, 0(pv)
35 lda AT, _mcount
36 jsr AT, (AT), _mcount
37 .prologue 1
38#else
39 .prologue 0
40#endif
41
42 zapnot a1, 1, a1 # e0 : zero extend the search character
43 ldq_u t0, 0(a0) # .. e1 : load first quadword
44 sll a1, 8, t5 # e0 : replicate the search character
45 andnot a0, 7, v0 # .. e1 : align our loop pointer
46 or t5, a1, a1 # e0 :
47 lda t4, -1 # .. e1 : build garbage mask
48 sll a1, 16, t5 # e0 :
49 cmpbge zero, t0, t2 # .. e1 : bits set iff byte == zero
50 mskqh t4, a0, t4 # e0 :
51 or t5, a1, a1 # .. e1 :
52 sll a1, 32, t5 # e0 :
53 cmpbge zero, t4, t4 # .. e1 : bits set iff byte is garbage
54 or t5, a1, a1 # e0 :
55 xor t0, a1, t1 # .. e1 : make bytes == c zero
56 cmpbge zero, t1, t3 # e0 : bits set iff byte == c
57 or t2, t3, t0 # e1 : bits set iff char match or zero match
58 andnot t0, t4, t0 # e0 : clear garbage bits
59 bne t0, $found # .. e1 (zdb)
60
61$loop: ldq t0, 8(v0) # e0 :
62 addq v0, 8, v0 # .. e1 :
63 nop # e0 :
64 xor t0, a1, t1 # .. e1 (ev5 data stall)
65 cmpbge zero, t0, t2 # e0 : bits set iff byte == 0
66 cmpbge zero, t1, t3 # .. e1 : bits set iff byte == c
67 or t2, t3, t0 # e0 :
68 beq t0, $loop # .. e1 (zdb)
69
70$found: negq t0, t1 # e0 : clear all but least set bit
71 and t0, t1, t0 # e1 (stall)
72
73 and t0, t3, t1 # e0 : bit set iff byte was the char
74 beq t1, $retnull # .. e1 (zdb)
75
76 and t0, 0xf0, t2 # e0 : binary search for that set bit
77 and t0, 0xcc, t3 # .. e1 :
78 and t0, 0xaa, t4 # e0 :
79 cmovne t2, 4, t2 # .. e1 :
80 cmovne t3, 2, t3 # e0 :
81 cmovne t4, 1, t4 # .. e1 :
82 addq t2, t3, t2 # e0 :
83 addq v0, t4, v0 # .. e1 :
84 addq v0, t2, v0 # e0 :
85 ret # .. e1 :
86
87$retnull:
88 mov zero, v0 # e0 :
89 ret # .. e1 :
90
91 END(strchr)
92
93weak_alias (strchr, index)
94libc_hidden_builtin_def (strchr)
95

Warning: That file was not part of the compilation database. It may have many parsing errors.