1*4882a593Smuzhiyun/* SPDX-License-Identifier: GPL-2.0 */ 2*4882a593Smuzhiyun/* 3*4882a593Smuzhiyun * arch/alpha/lib/ev67-strncat.S 4*4882a593Smuzhiyun * 21264 version contributed by Rick Gorton <rick.gorton@api-networks.com> 5*4882a593Smuzhiyun * 6*4882a593Smuzhiyun * Append no more than COUNT characters from the null-terminated string SRC 7*4882a593Smuzhiyun * to the null-terminated string DST. Always null-terminate the new DST. 8*4882a593Smuzhiyun * 9*4882a593Smuzhiyun * This differs slightly from the semantics in libc in that we never write 10*4882a593Smuzhiyun * past count, whereas libc may write to count+1. This follows the generic 11*4882a593Smuzhiyun * implementation in lib/string.c and is, IMHO, more sensible. 12*4882a593Smuzhiyun * 13*4882a593Smuzhiyun * Much of the information about 21264 scheduling/coding comes from: 14*4882a593Smuzhiyun * Compiler Writer's Guide for the Alpha 21264 15*4882a593Smuzhiyun * abbreviated as 'CWG' in other comments here 16*4882a593Smuzhiyun * ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html 17*4882a593Smuzhiyun * Scheduling notation: 18*4882a593Smuzhiyun * E - either cluster 19*4882a593Smuzhiyun * U - upper subcluster; U0 - subcluster U0; U1 - subcluster U1 20*4882a593Smuzhiyun * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1 21*4882a593Smuzhiyun * Try not to change the actual algorithm if possible for consistency. 22*4882a593Smuzhiyun */ 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun#include <asm/export.h> 25*4882a593Smuzhiyun .text 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun .align 4 28*4882a593Smuzhiyun .globl strncat 29*4882a593Smuzhiyun .ent strncat 30*4882a593Smuzhiyunstrncat: 31*4882a593Smuzhiyun .frame $30, 0, $26 32*4882a593Smuzhiyun .prologue 0 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun mov $16, $0 # set up return value 35*4882a593Smuzhiyun beq $18, $zerocount # U : 36*4882a593Smuzhiyun /* Find the end of the string. */ 37*4882a593Smuzhiyun ldq_u $1, 0($16) # L : load first quadword ($16 may be misaligned) 38*4882a593Smuzhiyun lda $2, -1($31) # E : 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun insqh $2, $0, $2 # U : 41*4882a593Smuzhiyun andnot $16, 7, $16 # E : 42*4882a593Smuzhiyun nop # E : 43*4882a593Smuzhiyun or $2, $1, $1 # E : 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun nop # E : 46*4882a593Smuzhiyun nop # E : 47*4882a593Smuzhiyun cmpbge $31, $1, $2 # E : bits set iff byte == 0 48*4882a593Smuzhiyun bne $2, $found # U : 49*4882a593Smuzhiyun 50*4882a593Smuzhiyun$loop: ldq $1, 8($16) # L : 51*4882a593Smuzhiyun addq $16, 8, $16 # E : 52*4882a593Smuzhiyun cmpbge $31, $1, $2 # E : 53*4882a593Smuzhiyun beq $2, $loop # U : 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun$found: cttz $2, $3 # U0 : 56*4882a593Smuzhiyun addq $16, $3, $16 # E : 57*4882a593Smuzhiyun nop # E : 58*4882a593Smuzhiyun bsr $23, __stxncpy # L0 :/* Now do the append. */ 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun /* Worry about the null termination. */ 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun zapnot $1, $27, $2 # U : was last byte a null? 63*4882a593Smuzhiyun cmplt $27, $24, $5 # E : did we fill the buffer completely? 64*4882a593Smuzhiyun bne $2, 0f # U : 65*4882a593Smuzhiyun ret # L0 : 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun0: or $5, $18, $2 # E : 68*4882a593Smuzhiyun nop 69*4882a593Smuzhiyun bne $2, 2f # U : 70*4882a593Smuzhiyun and $24, 0x80, $3 # E : no zero next byte 71*4882a593Smuzhiyun 72*4882a593Smuzhiyun nop # E : 73*4882a593Smuzhiyun bne $3, 1f # U : 74*4882a593Smuzhiyun /* Here there are bytes left in the current word. Clear one. */ 75*4882a593Smuzhiyun addq $24, $24, $24 # E : end-of-count bit <<= 1 76*4882a593Smuzhiyun nop # E : 77*4882a593Smuzhiyun 78*4882a593Smuzhiyun2: zap $1, $24, $1 # U : 79*4882a593Smuzhiyun nop # E : 80*4882a593Smuzhiyun stq_u $1, 0($16) # L : 81*4882a593Smuzhiyun ret # L0 : 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun1: /* Here we must clear the first byte of the next DST word */ 84*4882a593Smuzhiyun stb $31, 8($16) # L : 85*4882a593Smuzhiyun nop # E : 86*4882a593Smuzhiyun nop # E : 87*4882a593Smuzhiyun ret # L0 : 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun$zerocount: 90*4882a593Smuzhiyun nop # E : 91*4882a593Smuzhiyun nop # E : 92*4882a593Smuzhiyun nop # E : 93*4882a593Smuzhiyun ret # L0 : 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun .end strncat 96*4882a593Smuzhiyun EXPORT_SYMBOL(strncat) 97