memset.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * linux/arch/alpha/lib/memset.S
  3. *
  4. * This is an efficient (and small) implementation of the C library "memset()"
  5. * function for the alpha.
  6. *
  7. * (C) Copyright 1996 Linus Torvalds
  8. *
  9. * This routine is "moral-ware": you are free to use it any way you wish, and
  10. * the only obligation I put on you is a moral one: if you make any improvements
  11. * to the routine, please send me your improvements for me to use similarly.
  12. *
  13. * The scheduling comments are according to the EV5 documentation (and done by
  14. * hand, so they might well be incorrect, please do tell me about it..)
  15. */
  16. .set noat
  17. .set noreorder
  18. .text
  19. .globl memset
  20. .globl __memset
  21. .globl ___memset
  22. .globl __memsetw
  23. .globl __constant_c_memset
  24. .ent ___memset
  25. .align 5
  26. ___memset:
  27. .frame $30,0,$26,0
  28. .prologue 0
  29. and $17,255,$1 /* E1 */
  30. insbl $17,1,$17 /* .. E0 */
  31. bis $17,$1,$17 /* E0 (p-c latency, next cycle) */
  32. sll $17,16,$1 /* E1 (p-c latency, next cycle) */
  33. bis $17,$1,$17 /* E0 (p-c latency, next cycle) */
  34. sll $17,32,$1 /* E1 (p-c latency, next cycle) */
  35. bis $17,$1,$17 /* E0 (p-c latency, next cycle) */
  36. ldq_u $31,0($30) /* .. E1 */
  37. .align 5
  38. __constant_c_memset:
  39. addq $18,$16,$6 /* E0 */
  40. bis $16,$16,$0 /* .. E1 */
  41. xor $16,$6,$1 /* E0 */
  42. ble $18,end /* .. E1 */
  43. bic $1,7,$1 /* E0 */
  44. beq $1,within_one_quad /* .. E1 (note EV5 zero-latency forwarding) */
  45. and $16,7,$3 /* E0 */
  46. beq $3,aligned /* .. E1 (note EV5 zero-latency forwarding) */
  47. ldq_u $4,0($16) /* E0 */
  48. bis $16,$16,$5 /* .. E1 */
  49. insql $17,$16,$2 /* E0 */
  50. subq $3,8,$3 /* .. E1 */
  51. addq $18,$3,$18 /* E0 $18 is new count ($3 is negative) */
  52. mskql $4,$16,$4 /* .. E1 (and possible load stall) */
  53. subq $16,$3,$16 /* E0 $16 is new aligned destination */
  54. bis $2,$4,$1 /* .. E1 */
  55. bis $31,$31,$31 /* E0 */
  56. ldq_u $31,0($30) /* .. E1 */
  57. stq_u $1,0($5) /* E0 */
  58. bis $31,$31,$31 /* .. E1 */
  59. .align 4
  60. aligned:
  61. sra $18,3,$3 /* E0 */
  62. and $18,7,$18 /* .. E1 */
  63. bis $16,$16,$5 /* E0 */
  64. beq $3,no_quad /* .. E1 */
  65. .align 3
  66. loop:
  67. stq $17,0($5) /* E0 */
  68. subq $3,1,$3 /* .. E1 */
  69. addq $5,8,$5 /* E0 */
  70. bne $3,loop /* .. E1 */
  71. no_quad:
  72. bis $31,$31,$31 /* E0 */
  73. beq $18,end /* .. E1 */
  74. ldq $7,0($5) /* E0 */
  75. mskqh $7,$6,$2 /* .. E1 (and load stall) */
  76. insqh $17,$6,$4 /* E0 */
  77. bis $2,$4,$1 /* .. E1 */
  78. stq $1,0($5) /* E0 */
  79. ret $31,($26),1 /* .. E1 */
  80. .align 3
  81. within_one_quad:
  82. ldq_u $1,0($16) /* E0 */
  83. insql $17,$16,$2 /* E1 */
  84. mskql $1,$16,$4 /* E0 (after load stall) */
  85. bis $2,$4,$2 /* E0 */
  86. mskql $2,$6,$4 /* E0 */
  87. mskqh $1,$6,$2 /* .. E1 */
  88. bis $2,$4,$1 /* E0 */
  89. stq_u $1,0($16) /* E0 */
  90. end:
  91. ret $31,($26),1 /* E1 */
  92. .end ___memset
  93. .align 5
  94. .ent __memsetw
  95. __memsetw:
  96. .prologue 0
  97. inswl $17,0,$1 /* E0 */
  98. inswl $17,2,$2 /* E0 */
  99. inswl $17,4,$3 /* E0 */
  100. or $1,$2,$1 /* .. E1 */
  101. inswl $17,6,$4 /* E0 */
  102. or $1,$3,$1 /* .. E1 */
  103. or $1,$4,$17 /* E0 */
  104. br __constant_c_memset /* .. E1 */
  105. .end __memsetw
  106. memset = ___memset
  107. __memset = ___memset