ev67-strncat.S 2.4 KB

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