/* SPDX-License-Identifier: GPL-2.0 */1/*2* arch/alpha/lib/strncat.S3* Contributed by Richard Henderson ([email protected])4*5* Append no more than COUNT characters from the null-terminated string SRC6* 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 write9* past count, whereas libc may write to count+1. This follows the generic10* implementation in lib/string.c and is, IMHO, more sensible.11*/12#include <linux/export.h>13.text1415.align 316.globl strncat17.ent strncat18strncat:19.frame $30, 0, $2620.prologue 02122mov $16, $0 # set up return value23beq $18, $zerocount2425/* Find the end of the string. */2627ldq_u $1, 0($16) # load first quadword ($16 may be misaligned)28lda $2, -1($31)29insqh $2, $16, $230andnot $16, 7, $1631or $2, $1, $132cmpbge $31, $1, $2 # bits set iff byte == 033bne $2, $found3435$loop: ldq $1, 8($16)36addq $16, 8, $1637cmpbge $31, $1, $238beq $2, $loop3940$found: negq $2, $3 # clear all but least set bit41and $2, $3, $24243and $2, 0xf0, $3 # binary search for that set bit44and $2, 0xcc, $445and $2, 0xaa, $546cmovne $3, 4, $347cmovne $4, 2, $448cmovne $5, 1, $549addq $3, $4, $350addq $16, $5, $1651addq $16, $3, $165253/* Now do the append. */5455bsr $23, __stxncpy5657/* Worry about the null termination. */5859zapnot $1, $27, $2 # was last byte a null?60bne $2, 0f61ret62630: cmplt $27, $24, $2 # did we fill the buffer completely?64or $2, $18, $265bne $2, 2f6667and $24, 0x80, $2 # no zero next byte68bne $2, 1f6970/* Here there are bytes left in the current word. Clear one. */71addq $24, $24, $24 # end-of-count bit <<= 1722: zap $1, $24, $173stq_u $1, 0($16)74ret75761: /* Here we must read the next DST word and clear the first byte. */77ldq_u $1, 8($16)78zap $1, 1, $179stq_u $1, 8($16)8081$zerocount:82ret8384.end strncat85EXPORT_SYMBOL(strncat)868788