1 /* SPDX-License-Identifier: GPL-2.0 */
3 * arch/alpha/lib/strncat.S
4 * Contributed by Richard Henderson (rth@tamu.edu)
6 * Append no more than COUNT characters from the null-terminated string SRC
7 * to the null-terminated string DST. Always null-terminate the new DST.
9 * This differs slightly from the semantics in libc in that we never write
10 * past count, whereas libc may write to count+1. This follows the generic
11 * implementation in lib/string.c and is, IMHO, more sensible.
13 #include <asm/export.h>
23 mov $16, $0 # set up return value
26 /* Find the end of the string. */
28 ldq_u $1, 0($16) # load first quadword ($16 may be misaligned)
33 cmpbge $31, $1, $2 # bits set iff byte == 0
41 $found: negq $2, $3 # clear all but least set bit
44 and $2, 0xf0, $3 # binary search for that set bit
54 /* Now do the append. */
58 /* Worry about the null termination. */
60 zapnot $1, $27, $2 # was last byte a null?
64 0: cmplt $27, $24, $2 # did we fill the buffer completely?
68 and $24, 0x80, $2 # no zero next byte
71 /* Here there are bytes left in the current word. Clear one. */
72 addq $24, $24, $24 # end-of-count bit <<= 1
77 1: /* Here we must read the next DST word and clear the first byte. */
86 EXPORT_SYMBOL(strncat)