/*1* arch/alpha/lib/ev67-strncat.S2* 21264 version contributed by Rick Gorton <[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*11* Much of the information about 21264 scheduling/coding comes from:12* Compiler Writer's Guide for the Alpha 2126413* abbreviated as 'CWG' in other comments here14* ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html15* Scheduling notation:16* E - either cluster17* U - upper subcluster; U0 - subcluster U0; U1 - subcluster U118* L - lower subcluster; L0 - subcluster L0; L1 - subcluster L119* Try not to change the actual algorithm if possible for consistency.20*/212223.text2425.align 426.globl strncat27.ent strncat28strncat:29.frame $30, 0, $2630.prologue 03132mov $16, $0 # set up return value33beq $18, $zerocount # U :34/* Find the end of the string. */35ldq_u $1, 0($16) # L : load first quadword ($16 may be misaligned)36lda $2, -1($31) # E :3738insqh $2, $0, $2 # U :39andnot $16, 7, $16 # E :40nop # E :41or $2, $1, $1 # E :4243nop # E :44nop # E :45cmpbge $31, $1, $2 # E : bits set iff byte == 046bne $2, $found # U :4748$loop: ldq $1, 8($16) # L :49addq $16, 8, $16 # E :50cmpbge $31, $1, $2 # E :51beq $2, $loop # U :5253$found: cttz $2, $3 # U0 :54addq $16, $3, $16 # E :55nop # E :56bsr $23, __stxncpy # L0 :/* Now do the append. */5758/* Worry about the null termination. */5960zapnot $1, $27, $2 # U : was last byte a null?61cmplt $27, $24, $5 # E : did we fill the buffer completely?62bne $2, 0f # U :63ret # L0 :64650: or $5, $18, $2 # E :66nop67bne $2, 2f # U :68and $24, 0x80, $3 # E : no zero next byte6970nop # E :71bne $3, 1f # U :72/* Here there are bytes left in the current word. Clear one. */73addq $24, $24, $24 # E : end-of-count bit <<= 174nop # E :75762: zap $1, $24, $1 # U :77nop # E :78stq_u $1, 0($16) # L :79ret # L0 :80811: /* Here we must clear the first byte of the next DST word */82stb $31, 8($16) # L :83nop # E :84nop # E :85ret # L0 :8687$zerocount:88nop # E :89nop # E :90nop # E :91ret # L0 :9293.end strncat949596