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