18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * arch/alpha/lib/ev67-strncat.S 48c2ecf20Sopenharmony_ci * 21264 version contributed by Rick Gorton <rick.gorton@api-networks.com> 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Append no more than COUNT characters from the null-terminated string SRC 78c2ecf20Sopenharmony_ci * to the null-terminated string DST. Always null-terminate the new DST. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * This differs slightly from the semantics in libc in that we never write 108c2ecf20Sopenharmony_ci * past count, whereas libc may write to count+1. This follows the generic 118c2ecf20Sopenharmony_ci * implementation in lib/string.c and is, IMHO, more sensible. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * Much of the information about 21264 scheduling/coding comes from: 148c2ecf20Sopenharmony_ci * Compiler Writer's Guide for the Alpha 21264 158c2ecf20Sopenharmony_ci * abbreviated as 'CWG' in other comments here 168c2ecf20Sopenharmony_ci * ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html 178c2ecf20Sopenharmony_ci * Scheduling notation: 188c2ecf20Sopenharmony_ci * E - either cluster 198c2ecf20Sopenharmony_ci * U - upper subcluster; U0 - subcluster U0; U1 - subcluster U1 208c2ecf20Sopenharmony_ci * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1 218c2ecf20Sopenharmony_ci * Try not to change the actual algorithm if possible for consistency. 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#include <asm/export.h> 258c2ecf20Sopenharmony_ci .text 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci .align 4 288c2ecf20Sopenharmony_ci .globl strncat 298c2ecf20Sopenharmony_ci .ent strncat 308c2ecf20Sopenharmony_cistrncat: 318c2ecf20Sopenharmony_ci .frame $30, 0, $26 328c2ecf20Sopenharmony_ci .prologue 0 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci mov $16, $0 # set up return value 358c2ecf20Sopenharmony_ci beq $18, $zerocount # U : 368c2ecf20Sopenharmony_ci /* Find the end of the string. */ 378c2ecf20Sopenharmony_ci ldq_u $1, 0($16) # L : load first quadword ($16 may be misaligned) 388c2ecf20Sopenharmony_ci lda $2, -1($31) # E : 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci insqh $2, $0, $2 # U : 418c2ecf20Sopenharmony_ci andnot $16, 7, $16 # E : 428c2ecf20Sopenharmony_ci nop # E : 438c2ecf20Sopenharmony_ci or $2, $1, $1 # E : 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci nop # E : 468c2ecf20Sopenharmony_ci nop # E : 478c2ecf20Sopenharmony_ci cmpbge $31, $1, $2 # E : bits set iff byte == 0 488c2ecf20Sopenharmony_ci bne $2, $found # U : 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci$loop: ldq $1, 8($16) # L : 518c2ecf20Sopenharmony_ci addq $16, 8, $16 # E : 528c2ecf20Sopenharmony_ci cmpbge $31, $1, $2 # E : 538c2ecf20Sopenharmony_ci beq $2, $loop # U : 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci$found: cttz $2, $3 # U0 : 568c2ecf20Sopenharmony_ci addq $16, $3, $16 # E : 578c2ecf20Sopenharmony_ci nop # E : 588c2ecf20Sopenharmony_ci bsr $23, __stxncpy # L0 :/* Now do the append. */ 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci /* Worry about the null termination. */ 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci zapnot $1, $27, $2 # U : was last byte a null? 638c2ecf20Sopenharmony_ci cmplt $27, $24, $5 # E : did we fill the buffer completely? 648c2ecf20Sopenharmony_ci bne $2, 0f # U : 658c2ecf20Sopenharmony_ci ret # L0 : 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci0: or $5, $18, $2 # E : 688c2ecf20Sopenharmony_ci nop 698c2ecf20Sopenharmony_ci bne $2, 2f # U : 708c2ecf20Sopenharmony_ci and $24, 0x80, $3 # E : no zero next byte 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci nop # E : 738c2ecf20Sopenharmony_ci bne $3, 1f # U : 748c2ecf20Sopenharmony_ci /* Here there are bytes left in the current word. Clear one. */ 758c2ecf20Sopenharmony_ci addq $24, $24, $24 # E : end-of-count bit <<= 1 768c2ecf20Sopenharmony_ci nop # E : 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci2: zap $1, $24, $1 # U : 798c2ecf20Sopenharmony_ci nop # E : 808c2ecf20Sopenharmony_ci stq_u $1, 0($16) # L : 818c2ecf20Sopenharmony_ci ret # L0 : 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci1: /* Here we must clear the first byte of the next DST word */ 848c2ecf20Sopenharmony_ci stb $31, 8($16) # L : 858c2ecf20Sopenharmony_ci nop # E : 868c2ecf20Sopenharmony_ci nop # E : 878c2ecf20Sopenharmony_ci ret # L0 : 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci$zerocount: 908c2ecf20Sopenharmony_ci nop # E : 918c2ecf20Sopenharmony_ci nop # E : 928c2ecf20Sopenharmony_ci nop # E : 938c2ecf20Sopenharmony_ci ret # L0 : 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci .end strncat 968c2ecf20Sopenharmony_ci EXPORT_SYMBOL(strncat) 97