1
2
3
4
5
6
7
8
9
10
11
12
13 #include <asm/export.h>
14 .text
15
16 .align 3
17 .globl strncat
18 .ent strncat
19 strncat:
20 .frame $30, 0, $26
21 .prologue 0
22
23 mov $16, $0 # set up return value
24 beq $18, $zerocount
25
26
27
28 ldq_u $1, 0($16) # load first quadword ($16 may be misaligned)
29 lda $2, -1($31)
30 insqh $2, $16, $2
31 andnot $16, 7, $16
32 or $2, $1, $1
33 cmpbge $31, $1, $2 # bits set iff byte == 0
34 bne $2, $found
35
36 $loop: ldq $1, 8($16)
37 addq $16, 8, $16
38 cmpbge $31, $1, $2
39 beq $2, $loop
40
41 $found: negq $2, $3 # clear all but least set bit
42 and $2, $3, $2
43
44 and $2, 0xf0, $3 # binary search for that set bit
45 and $2, 0xcc, $4
46 and $2, 0xaa, $5
47 cmovne $3, 4, $3
48 cmovne $4, 2, $4
49 cmovne $5, 1, $5
50 addq $3, $4, $3
51 addq $16, $5, $16
52 addq $16, $3, $16
53
54
55
56 bsr $23, __stxncpy
57
58
59
60 zapnot $1, $27, $2 # was last byte a null?
61 bne $2, 0f
62 ret
63
64 0: cmplt $27, $24, $2 # did we fill the buffer completely?
65 or $2, $18, $2
66 bne $2, 2f
67
68 and $24, 0x80, $2 # no zero next byte
69 bne $2, 1f
70
71
72 addq $24, $24, $24 # end-of-count bit <<= 1
73 2: zap $1, $24, $1
74 stq_u $1, 0($16)
75 ret
76
77 1:
78 ldq_u $1, 8($16)
79 zap $1, 1, $1
80 stq_u $1, 8($16)
81
82 $zerocount:
83 ret
84
85 .end strncat
86 EXPORT_SYMBOL(strncat)