1 /* SPDX-License-Identifier: GPL-2.0 */
3 * arch/alpha/lib/ev67-strncat.S
4 * 21264 version contributed by Rick Gorton <rick.gorton@api-networks.com>
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 * Much of the information about 21264 scheduling/coding comes from:
14 * Compiler Writer's Guide for the Alpha 21264
15 * abbreviated as 'CWG' in other comments here
16 * ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html
17 * Scheduling notation:
19 * U - upper subcluster; U0 - subcluster U0; U1 - subcluster U1
20 * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1
21 * Try not to change the actual algorithm if possible for consistency.
24 #include <asm/export.h>
34 mov $16, $0 # set up return value
35 beq $18, $zerocount # U :
36 /* Find the end of the string. */
37 ldq_u $1, 0($16) # L : load first quadword ($16 may be misaligned)
40 insqh $2, $0, $2 # U :
41 andnot $16, 7, $16 # E :
47 cmpbge $31, $1, $2 # E : bits set iff byte == 0
50 $loop: ldq $1, 8($16) # L :
51 addq $16, 8, $16 # E :
52 cmpbge $31, $1, $2 # E :
55 $found: cttz $2, $3 # U0 :
56 addq $16, $3, $16 # E :
58 bsr $23, __stxncpy # L0 :/* Now do the append. */
60 /* Worry about the null termination. */
62 zapnot $1, $27, $2 # U : was last byte a null?
63 cmplt $27, $24, $5 # E : did we fill the buffer completely?
67 0: or $5, $18, $2 # E :
70 and $24, 0x80, $3 # E : no zero next byte
74 /* Here there are bytes left in the current word. Clear one. */
75 addq $24, $24, $24 # E : end-of-count bit <<= 1
78 2: zap $1, $24, $1 # U :
80 stq_u $1, 0($16) # L :
83 1: /* Here we must clear the first byte of the next DST word */
96 EXPORT_SYMBOL(strncat)