ev67-strncat.S
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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. .text
  23. .align 4
  24. .globl strncat
  25. .ent strncat
  26. strncat:
  27. .frame $30, 0, $26
  28. .prologue 0
  29. mov $16, $0 # set up return value
  30. beq $18, $zerocount # U :
  31. /* Find the end of the string.  */
  32. ldq_u   $1, 0($16) # L : load first quadword ($16 may be misaligned)
  33. lda     $2, -1($31) # E :
  34. insqh   $2, $0, $2 # U :
  35. andnot  $16, 7, $16 # E :
  36. nop # E :
  37. or      $2, $1, $1 # E :
  38. nop # E :
  39. nop # E :
  40. cmpbge  $31, $1, $2 # E : bits set iff byte == 0
  41. bne     $2, $found # U :
  42. $loop: ldq     $1, 8($16) # L :
  43. addq    $16, 8, $16 # E :
  44. cmpbge  $31, $1, $2 # E :
  45. beq     $2, $loop # U :
  46. $found: cttz $2, $3 # U0 :
  47. addq $16, $3, $16 # E :
  48. nop # E :
  49. bsr $23, __stxncpy # L0 :/* Now do the append.  */
  50. /* Worry about the null termination.  */
  51. zapnot $1, $27, $2 # U : was last byte a null?
  52. cmplt $27, $24, $5 # E : did we fill the buffer completely?
  53. bne $2, 0f # U :
  54. ret # L0 :
  55. 0: or $5, $18, $2 # E :
  56. nop
  57. bne $2, 2f # U :
  58. and $24, 0x80, $3 # E : no zero next byte
  59. nop # E :
  60. bne $3, 1f # U :
  61. /* Here there are bytes left in the current word.  Clear one.  */
  62. addq $24, $24, $24 # E : end-of-count bit <<= 1
  63. nop # E :
  64. 2: zap $1, $24, $1 # U :
  65. nop # E :
  66. stq_u $1, 0($16) # L :
  67. ret # L0 :
  68. 1: /* Here we must clear the first byte of the next DST word */
  69. stb $31, 8($16) # L :
  70. nop # E :
  71. nop # E :
  72. ret # L0 :
  73. $zerocount:
  74. nop # E :
  75. nop # E :
  76. nop # E :
  77. ret # L0 :
  78. .end strncat