aboutsummaryrefslogtreecommitdiffstats
path: root/arch/alpha/lib/strchr.S
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/alpha/lib/strchr.S
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/alpha/lib/strchr.S')
-rw-r--r--arch/alpha/lib/strchr.S70
1 files changed, 70 insertions, 0 deletions
diff --git a/arch/alpha/lib/strchr.S b/arch/alpha/lib/strchr.S
new file mode 100644
index 000000000000..011a175e8329
--- /dev/null
+++ b/arch/alpha/lib/strchr.S
@@ -0,0 +1,70 @@
1/*
2 * arch/alpha/lib/strchr.S
3 * Contributed by Richard Henderson (rth@tamu.edu)
4 *
5 * Return the address of a given character within a null-terminated
6 * string, or null if it is not found.
7 */
8
9#include <asm/regdef.h>
10
11 .set noreorder
12 .set noat
13
14 .align 3
15 .globl strchr
16 .ent strchr
17strchr:
18 .frame sp, 0, ra
19 .prologue 0
20
21 zapnot a1, 1, a1 # e0 : zero extend the search character
22 ldq_u t0, 0(a0) # .. e1 : load first quadword
23 sll a1, 8, t5 # e0 : replicate the search character
24 andnot a0, 7, v0 # .. e1 : align our loop pointer
25 or t5, a1, a1 # e0 :
26 lda t4, -1 # .. e1 : build garbage mask
27 sll a1, 16, t5 # e0 :
28 cmpbge zero, t0, t2 # .. e1 : bits set iff byte == zero
29 mskqh t4, a0, t4 # e0 :
30 or t5, a1, a1 # .. e1 :
31 sll a1, 32, t5 # e0 :
32 cmpbge zero, t4, t4 # .. e1 : bits set iff byte is garbage
33 or t5, a1, a1 # e0 :
34 xor t0, a1, t1 # .. e1 : make bytes == c zero
35 cmpbge zero, t1, t3 # e0 : bits set iff byte == c
36 or t2, t3, t0 # e1 : bits set iff char match or zero match
37 andnot t0, t4, t0 # e0 : clear garbage bits
38 bne t0, $found # .. e1 (zdb)
39
40$loop: ldq t0, 8(v0) # e0 :
41 addq v0, 8, v0 # .. e1 :
42 nop # e0 :
43 xor t0, a1, t1 # .. e1 (ev5 data stall)
44 cmpbge zero, t0, t2 # e0 : bits set iff byte == 0
45 cmpbge zero, t1, t3 # .. e1 : bits set iff byte == c
46 or t2, t3, t0 # e0 :
47 beq t0, $loop # .. e1 (zdb)
48
49$found: negq t0, t1 # e0 : clear all but least set bit
50 and t0, t1, t0 # e1 (stall)
51
52 and t0, t3, t1 # e0 : bit set iff byte was the char
53 beq t1, $retnull # .. e1 (zdb)
54
55 and t0, 0xf0, t2 # e0 : binary search for that set bit
56 and t0, 0xcc, t3 # .. e1 :
57 and t0, 0xaa, t4 # e0 :
58 cmovne t2, 4, t2 # .. e1 :
59 cmovne t3, 2, t3 # e0 :
60 cmovne t4, 1, t4 # .. e1 :
61 addq t2, t3, t2 # e0 :
62 addq v0, t4, v0 # .. e1 :
63 addq v0, t2, v0 # e0 :
64 ret # .. e1 :
65
66$retnull:
67 mov zero, v0 # e0 :
68 ret # .. e1 :
69
70 .end strchr