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