ev6-copy_page.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * arch/alpha/lib/ev6-copy_page.S
  3. *
  4. * Copy an entire page.
  5. */
  6. /* The following comparison of this routine vs the normal copy_page.S
  7. was written by an unnamed ev6 hardware designer and forwarded to me
  8. via Steven Hobbs <hobbs@steven.zko.dec.com>.
  9. First Problem: STQ overflows.
  10. -----------------------------
  11. It would be nice if EV6 handled every resource overflow efficiently,
  12. but for some it doesn't. Including store queue overflows. It causes
  13. a trap and a restart of the pipe.
  14. To get around this we sometimes use (to borrow a term from a VSSAD
  15. researcher) "aeration". The idea is to slow the rate at which the
  16. processor receives valid instructions by inserting nops in the fetch
  17. path. In doing so, you can prevent the overflow and actually make
  18. the code run faster. You can, of course, take advantage of the fact
  19. that the processor can fetch at most 4 aligned instructions per cycle.
  20. I inserted enough nops to force it to take 10 cycles to fetch the
  21. loop code. In theory, EV6 should be able to execute this loop in
  22. 9 cycles but I was not able to get it to run that fast -- the initial
  23. conditions were such that I could not reach this optimum rate on
  24. (chaotic) EV6. I wrote the code such that everything would issue
  25. in order.
  26. Second Problem: Dcache index matches.
  27. -------------------------------------
  28. If you are going to use this routine on random aligned pages, there
  29. is a 25% chance that the pages will be at the same dcache indices.
  30. This results in many nasty memory traps without care.
  31. The solution is to schedule the prefetches to avoid the memory
  32. conflicts. I schedule the wh64 prefetches farther ahead of the
  33. read prefetches to avoid this problem.
  34. Third Problem: Needs more prefetching.
  35. --------------------------------------
  36. In order to improve the code I added deeper prefetching to take the
  37. most advantage of EV6's bandwidth.
  38. I also prefetched the read stream. Note that adding the read prefetch
  39. forced me to add another cycle to the inner-most kernel - up to 11
  40. from the original 8 cycles per iteration. We could improve performance
  41. further by unrolling the loop and doing multiple prefetches per cycle.
  42. I think that the code below will be very robust and fast code for the
  43. purposes of copying aligned pages. It is slower when both source and
  44. destination pages are in the dcache, but it is my guess that this is
  45. less important than the dcache miss case. */
  46. .text
  47. .align 4
  48. .global copy_page
  49. .ent copy_page
  50. copy_page:
  51. .prologue 0
  52. /* Prefetch 5 read cachelines; write-hint 10 cache lines. */
  53. wh64 ($16)
  54. ldl $31,0($17)
  55. ldl $31,64($17)
  56. lda $1,1*64($16)
  57. wh64 ($1)
  58. ldl $31,128($17)
  59. ldl $31,192($17)
  60. lda $1,2*64($16)
  61. wh64 ($1)
  62. ldl $31,256($17)
  63. lda $18,118
  64. lda $1,3*64($16)
  65. wh64 ($1)
  66. nop
  67. lda $1,4*64($16)
  68. lda $2,5*64($16)
  69. wh64 ($1)
  70. wh64 ($2)
  71. lda $1,6*64($16)
  72. lda $2,7*64($16)
  73. wh64 ($1)
  74. wh64 ($2)
  75. lda $1,8*64($16)
  76. lda $2,9*64($16)
  77. wh64 ($1)
  78. wh64 ($2)
  79. lda $19,10*64($16)
  80. nop
  81. /* Main prefetching/write-hinting loop. */
  82. 1: ldq $0,0($17)
  83. ldq $1,8($17)
  84. unop
  85. unop
  86. unop
  87. unop
  88. ldq $2,16($17)
  89. ldq $3,24($17)
  90. ldq $4,32($17)
  91. ldq $5,40($17)
  92. unop
  93. unop
  94. unop
  95. unop
  96. ldq $6,48($17)
  97. ldq $7,56($17)
  98. ldl $31,320($17)
  99. unop
  100. unop
  101. unop
  102. /* This gives the extra cycle of aeration above the minimum. */
  103. unop
  104. unop
  105. unop
  106. unop
  107. wh64 ($19)
  108. unop
  109. unop
  110. unop
  111. stq $0,0($16)
  112. subq $18,1,$18
  113. stq $1,8($16)
  114. unop
  115. unop
  116. stq $2,16($16)
  117. addq $17,64,$17
  118. stq $3,24($16)
  119. stq $4,32($16)
  120. stq $5,40($16)
  121. addq $19,64,$19
  122. unop
  123. stq $6,48($16)
  124. stq $7,56($16)
  125. addq $16,64,$16
  126. bne $18, 1b
  127. /* Prefetch the final 5 cache lines of the read stream. */
  128. lda $18,10
  129. ldl $31,320($17)
  130. ldl $31,384($17)
  131. ldl $31,448($17)
  132. ldl $31,512($17)
  133. ldl $31,576($17)
  134. nop
  135. nop
  136. /* Non-prefetching, non-write-hinting cleanup loop for the
  137. final 10 cache lines. */
  138. 2: ldq $0,0($17)
  139. ldq $1,8($17)
  140. ldq $2,16($17)
  141. ldq $3,24($17)
  142. ldq $4,32($17)
  143. ldq $5,40($17)
  144. ldq $6,48($17)
  145. ldq $7,56($17)
  146. stq $0,0($16)
  147. subq $18,1,$18
  148. stq $1,8($16)
  149. addq $17,64,$17
  150. stq $2,16($16)
  151. stq $3,24($16)
  152. stq $4,32($16)
  153. stq $5,40($16)
  154. stq $6,48($16)
  155. stq $7,56($16)
  156. addq $16,64,$16
  157. bne $18, 2b
  158. ret
  159. nop
  160. unop
  161. nop
  162. .end copy_page