diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/alpha/lib/strncat.S |
Linux-2.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/strncat.S')
-rw-r--r-- | arch/alpha/lib/strncat.S | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/arch/alpha/lib/strncat.S b/arch/alpha/lib/strncat.S new file mode 100644 index 00000000000..a8278163c97 --- /dev/null +++ b/arch/alpha/lib/strncat.S | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | * arch/alpha/lib/strncat.S | ||
3 | * Contributed by Richard Henderson (rth@tamu.edu) | ||
4 | * | ||
5 | * Append no more than COUNT characters from the null-terminated string SRC | ||
6 | * to the null-terminated string DST. Always null-terminate the new DST. | ||
7 | * | ||
8 | * This differs slightly from the semantics in libc in that we never write | ||
9 | * past count, whereas libc may write to count+1. This follows the generic | ||
10 | * implementation in lib/string.c and is, IMHO, more sensible. | ||
11 | */ | ||
12 | |||
13 | .text | ||
14 | |||
15 | .align 3 | ||
16 | .globl strncat | ||
17 | .ent strncat | ||
18 | strncat: | ||
19 | .frame $30, 0, $26 | ||
20 | .prologue 0 | ||
21 | |||
22 | mov $16, $0 # set up return value | ||
23 | beq $18, $zerocount | ||
24 | |||
25 | /* Find the end of the string. */ | ||
26 | |||
27 | ldq_u $1, 0($16) # load first quadword ($16 may be misaligned) | ||
28 | lda $2, -1($31) | ||
29 | insqh $2, $16, $2 | ||
30 | andnot $16, 7, $16 | ||
31 | or $2, $1, $1 | ||
32 | cmpbge $31, $1, $2 # bits set iff byte == 0 | ||
33 | bne $2, $found | ||
34 | |||
35 | $loop: ldq $1, 8($16) | ||
36 | addq $16, 8, $16 | ||
37 | cmpbge $31, $1, $2 | ||
38 | beq $2, $loop | ||
39 | |||
40 | $found: negq $2, $3 # clear all but least set bit | ||
41 | and $2, $3, $2 | ||
42 | |||
43 | and $2, 0xf0, $3 # binary search for that set bit | ||
44 | and $2, 0xcc, $4 | ||
45 | and $2, 0xaa, $5 | ||
46 | cmovne $3, 4, $3 | ||
47 | cmovne $4, 2, $4 | ||
48 | cmovne $5, 1, $5 | ||
49 | addq $3, $4, $3 | ||
50 | addq $16, $5, $16 | ||
51 | addq $16, $3, $16 | ||
52 | |||
53 | /* Now do the append. */ | ||
54 | |||
55 | bsr $23, __stxncpy | ||
56 | |||
57 | /* Worry about the null termination. */ | ||
58 | |||
59 | zapnot $1, $27, $2 # was last byte a null? | ||
60 | bne $2, 0f | ||
61 | ret | ||
62 | |||
63 | 0: cmplt $27, $24, $2 # did we fill the buffer completely? | ||
64 | or $2, $18, $2 | ||
65 | bne $2, 2f | ||
66 | |||
67 | and $24, 0x80, $2 # no zero next byte | ||
68 | bne $2, 1f | ||
69 | |||
70 | /* Here there are bytes left in the current word. Clear one. */ | ||
71 | addq $24, $24, $24 # end-of-count bit <<= 1 | ||
72 | 2: zap $1, $24, $1 | ||
73 | stq_u $1, 0($16) | ||
74 | ret | ||
75 | |||
76 | 1: /* Here we must read the next DST word and clear the first byte. */ | ||
77 | ldq_u $1, 8($16) | ||
78 | zap $1, 1, $1 | ||
79 | stq_u $1, 8($16) | ||
80 | |||
81 | $zerocount: | ||
82 | ret | ||
83 | |||
84 | .end strncat | ||