Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * arch/alpha/lib/ev67-strncat.S
0004  * 21264 version contributed by Rick Gorton <rick.gorton@api-networks.com>
0005  *
0006  * Append no more than COUNT characters from the null-terminated string SRC
0007  * to the null-terminated string DST.  Always null-terminate the new DST.
0008  *
0009  * This differs slightly from the semantics in libc in that we never write
0010  * past count, whereas libc may write to count+1.  This follows the generic
0011  * implementation in lib/string.c and is, IMHO, more sensible.
0012  *
0013  * Much of the information about 21264 scheduling/coding comes from:
0014  *  Compiler Writer's Guide for the Alpha 21264
0015  *  abbreviated as 'CWG' in other comments here
0016  *  ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html
0017  * Scheduling notation:
0018  *  E   - either cluster
0019  *  U   - upper subcluster; U0 - subcluster U0; U1 - subcluster U1
0020  *  L   - lower subcluster; L0 - subcluster L0; L1 - subcluster L1
0021  * Try not to change the actual algorithm if possible for consistency.
0022  */
0023 
0024 #include <asm/export.h>
0025     .text
0026 
0027     .align 4
0028     .globl strncat
0029     .ent strncat
0030 strncat:
0031     .frame $30, 0, $26
0032     .prologue 0
0033 
0034     mov $16, $0     # set up return value
0035     beq $18, $zerocount # U :
0036     /* Find the end of the string.  */
0037     ldq_u   $1, 0($16)  # L : load first quadword ($16 may be misaligned)
0038     lda     $2, -1($31) # E :
0039 
0040     insqh   $2, $0, $2  # U :
0041     andnot  $16, 7, $16 # E :
0042     nop         # E :
0043     or      $2, $1, $1  # E :
0044 
0045     nop         # E :
0046     nop         # E :
0047     cmpbge  $31, $1, $2 # E : bits set iff byte == 0
0048     bne     $2, $found  # U :
0049 
0050 $loop:  ldq     $1, 8($16)  # L :
0051     addq    $16, 8, $16 # E :
0052     cmpbge  $31, $1, $2 # E :
0053     beq     $2, $loop   # U :
0054 
0055 $found: cttz    $2, $3      # U0 :
0056     addq    $16, $3, $16    # E :
0057     nop         # E :
0058     bsr $23, __stxncpy  # L0 :/* Now do the append.  */
0059 
0060     /* Worry about the null termination.  */
0061 
0062     zapnot  $1, $27, $2 # U : was last byte a null?
0063     cmplt   $27, $24, $5    # E : did we fill the buffer completely?
0064     bne $2, 0f      # U :
0065     ret         # L0 :
0066 
0067 0:  or  $5, $18, $2 # E :
0068     nop
0069     bne $2, 2f      # U :
0070     and $24, 0x80, $3   # E : no zero next byte
0071 
0072     nop         # E :
0073     bne $3, 1f      # U :
0074     /* Here there are bytes left in the current word.  Clear one.  */
0075     addq    $24, $24, $24   # E : end-of-count bit <<= 1
0076     nop         # E :
0077 
0078 2:  zap $1, $24, $1 # U :
0079     nop         # E :
0080     stq_u   $1, 0($16)  # L :
0081     ret         # L0 :
0082 
0083 1:  /* Here we must clear the first byte of the next DST word */
0084     stb $31, 8($16) # L :
0085     nop         # E :
0086     nop         # E :
0087     ret         # L0 :
0088 
0089 $zerocount:
0090     nop         # E :
0091     nop         # E :
0092     nop         # E :
0093     ret         # L0 :
0094 
0095     .end strncat
0096     EXPORT_SYMBOL(strncat)