]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/alpha/alphaev67/rawmemchr.S
Alpha ev67 rawmemchr implementation.
[thirdparty/glibc.git] / sysdeps / alpha / alphaev67 / rawmemchr.S
CommitLineData
f345d77f
UD
1/* Copyright (C) 2000 Free Software Foundation, Inc.
2
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20/* Return pointer to first occurrence of CH in STR. */
21
22#include <sysdep.h>
23
24 .arch ev6
25 .set noreorder
26 .set noat
27
28ENTRY(__rawmemchr)
29#ifdef PROF
30 ldgp gp, 0(pv)
31 lda AT, _mcount
32 jsr AT, (AT), _mcount
33 .prologue 1
34#else
35 .prologue 0
36#endif
37
38 ldq_u t0, 0(a0) # L : load first quadword Latency=3
39 and a1, 0xff, t3 # E : 00000000000000ch
40 insbl a1, 1, t5 # U : 000000000000ch00
41 insbl a1, 7, a2 # U : ch00000000000000
42
43 insbl t3, 6, a3 # U : 00ch000000000000
44 or t5, t3, a1 # E : 000000000000chch
45 andnot a0, 7, v0 # E : align our loop pointer
46 lda t4, -1 # E : build garbage mask
47
48 mskqh t4, a0, t4 # U : only want relevant part of first quad
49 or a2, a3, a2 # E : chch000000000000
50 inswl a1, 2, t5 # E : 00000000chch0000
51 inswl a1, 4, a3 # E : 0000chch00000000
52
53 or a1, a2, a1 # E : chch00000000chch
54 or a3, t5, t5 # E : 0000chchchch0000
55 cmpbge zero, t4, t4 # E : bits set iff byte is garbage
56 nop # E :
57
58 /* This quad is _very_ serialized. Lots of stalling happens */
59 or t5, a1, a1 # E : chchchchchchchch
60 xor t0, a1, t1 # E : make bytes == c zero
61 cmpbge zero, t1, t0 # E : bits set iff byte == c
62 andnot t0, t4, t0 # E : clear garbage bits
63
64 cttz t0, a2 # U0 : speculative (in case we get a match)
65 nop # E :
66 nop # E :
67 bne t0, $found # U :
68
69 /*
70 * Yuk. This loop is going to stall like crazy waiting for the
71 * data to be loaded. Not much can be done about it unless it's
72 * unrolled multiple times, which is generally unsafe.
73 */
74$loop:
75 ldq t0, 8(v0) # L : Latency=3
76 addq v0, 8, v0 # E :
77 xor t0, a1, t1 # E :
78 cmpbge zero, t1, t0 # E : bits set iff byte == c
79
80 cttz t0, a2 # U0 : speculative (in case we get a match)
81 nop # E :
82 nop # E :
83 beq t0, $loop # U :
84
85$found:
86 negq t0, t1 # E : clear all but least set bit
87 and t0, t1, t0 # E :
88 addq v0, a2, v0 # E : Add in the bit number from above
89 ret # L0 :
90
91 END(__rawmemchr)
92
93weak_alias (__rawmemchr, rawmemchr)