2
* arch/alpha/lib/strncat.S
3
* Contributed by Richard Henderson (rth@tamu.edu)
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.
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.
22
mov $16, $0 # set up return value
25
/* Find the end of the string. */
27
ldq_u $1, 0($16) # load first quadword ($16 may be misaligned)
32
cmpbge $31, $1, $2 # bits set iff byte == 0
40
$found: negq $2, $3 # clear all but least set bit
43
and $2, 0xf0, $3 # binary search for that set bit
53
/* Now do the append. */
57
/* Worry about the null termination. */
59
zapnot $1, $27, $2 # was last byte a null?
63
0: cmplt $27, $24, $2 # did we fill the buffer completely?
67
and $24, 0x80, $2 # no zero next byte
70
/* Here there are bytes left in the current word. Clear one. */
71
addq $24, $24, $24 # end-of-count bit <<= 1
76
1: /* Here we must read the next DST word and clear the first byte. */