/*1* arch/alpha/lib/strncat.S2* Contributed by Richard Henderson ([email protected])3*4* Append no more than COUNT characters from the null-terminated string SRC5* to the null-terminated string DST. Always null-terminate the new DST.6*7* This differs slightly from the semantics in libc in that we never write8* past count, whereas libc may write to count+1. This follows the generic9* implementation in lib/string.c and is, IMHO, more sensible.10*/1112.text1314.align 315.globl strncat16.ent strncat17strncat:18.frame $30, 0, $2619.prologue 02021mov $16, $0 # set up return value22beq $18, $zerocount2324/* Find the end of the string. */2526ldq_u $1, 0($16) # load first quadword ($16 may be misaligned)27lda $2, -1($31)28insqh $2, $16, $229andnot $16, 7, $1630or $2, $1, $131cmpbge $31, $1, $2 # bits set iff byte == 032bne $2, $found3334$loop: ldq $1, 8($16)35addq $16, 8, $1636cmpbge $31, $1, $237beq $2, $loop3839$found: negq $2, $3 # clear all but least set bit40and $2, $3, $24142and $2, 0xf0, $3 # binary search for that set bit43and $2, 0xcc, $444and $2, 0xaa, $545cmovne $3, 4, $346cmovne $4, 2, $447cmovne $5, 1, $548addq $3, $4, $349addq $16, $5, $1650addq $16, $3, $165152/* Now do the append. */5354bsr $23, __stxncpy5556/* Worry about the null termination. */5758zapnot $1, $27, $2 # was last byte a null?59bne $2, 0f60ret61620: cmplt $27, $24, $2 # did we fill the buffer completely?63or $2, $18, $264bne $2, 2f6566and $24, 0x80, $2 # no zero next byte67bne $2, 1f6869/* Here there are bytes left in the current word. Clear one. */70addq $24, $24, $24 # end-of-count bit <<= 1712: zap $1, $24, $172stq_u $1, 0($16)73ret74751: /* Here we must read the next DST word and clear the first byte. */76ldq_u $1, 8($16)77zap $1, 1, $178stq_u $1, 8($16)7980$zerocount:81ret8283.end strncat848586