ev67-strncat.S 2.4 KB

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