ev6-clear_user.S 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * arch/alpha/lib/ev6-clear_user.S
  3. * 21264 version contributed by Rick Gorton <rick.gorton@alpha-processor.com>
  4. *
  5. * Zero user space, handling exceptions as we go.
  6. *
  7. * We have to make sure that $0 is always up-to-date and contains the
  8. * right "bytes left to zero" value (and that it is updated only _after_
  9. * a successful copy). There is also some rather minor exception setup
  10. * stuff.
  11. *
  12. * NOTE! This is not directly C-callable, because the calling semantics
  13. * are different:
  14. *
  15. * Inputs:
  16. * length in $0
  17. * destination address in $6
  18. * exception pointer in $7
  19. * return address in $28 (exceptions expect it there)
  20. *
  21. * Outputs:
  22. * bytes left to copy in $0
  23. *
  24. * Clobbers:
  25. * $1,$2,$3,$4,$5,$6
  26. *
  27. * Much of the information about 21264 scheduling/coding comes from:
  28. * Compiler Writer's Guide for the Alpha 21264
  29. * abbreviated as 'CWG' in other comments here
  30. * ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html
  31. * Scheduling notation:
  32. * E - either cluster
  33. * U - upper subcluster; U0 - subcluster U0; U1 - subcluster U1
  34. * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1
  35. * Try not to change the actual algorithm if possible for consistency.
  36. * Determining actual stalls (other than slotting) doesn't appear to be easy to do.
  37. * From perusing the source code context where this routine is called, it is
  38. * a fair assumption that significant fractions of entire pages are zeroed, so
  39. * it's going to be worth the effort to hand-unroll a big loop, and use wh64.
  40. * ASSUMPTION:
  41. * The believed purpose of only updating $0 after a store is that a signal
  42. * may come along during the execution of this chunk of code, and we don't
  43. * want to leave a hole (and we also want to avoid repeating lots of work)
  44. */
  45. /* Allow an exception for an insn; exit if we get one. */
  46. #define EX(x,y...) \
  47. 99: x,##y; \
  48. .section __ex_table,"a"; \
  49. .long 99b - .; \
  50. lda $31, $exception-99b($31); \
  51. .previous
  52. .set noat
  53. .set noreorder
  54. .align 4
  55. .globl __do_clear_user
  56. .ent __do_clear_user
  57. .frame $30, 0, $28
  58. .prologue 0
  59. # Pipeline info : Slotting & Comments
  60. __do_clear_user:
  61. and $6, 7, $4 # .. E .. .. : find dest head misalignment
  62. beq $0, $zerolength # U .. .. .. : U L U L
  63. addq $0, $4, $1 # .. .. .. E : bias counter
  64. and $1, 7, $2 # .. .. E .. : number of misaligned bytes in tail
  65. # Note - we never actually use $2, so this is a moot computation
  66. # and we can rewrite this later...
  67. srl $1, 3, $1 # .. E .. .. : number of quadwords to clear
  68. beq $4, $headalign # U .. .. .. : U L U L
  69. /*
  70. * Head is not aligned. Write (8 - $4) bytes to head of destination
  71. * This means $6 is known to be misaligned
  72. */
  73. EX( ldq_u $5, 0($6) ) # .. .. .. L : load dst word to mask back in
  74. beq $1, $onebyte # .. .. U .. : sub-word store?
  75. mskql $5, $6, $5 # .. U .. .. : take care of misaligned head
  76. addq $6, 8, $6 # E .. .. .. : L U U L
  77. EX( stq_u $5, -8($6) ) # .. .. .. L :
  78. subq $1, 1, $1 # .. .. E .. :
  79. addq $0, $4, $0 # .. E .. .. : bytes left -= 8 - misalignment
  80. subq $0, 8, $0 # E .. .. .. : U L U L
  81. .align 4
  82. /*
  83. * (The .align directive ought to be a moot point)
  84. * values upon initial entry to the loop
  85. * $1 is number of quadwords to clear (zero is a valid value)
  86. * $2 is number of trailing bytes (0..7) ($2 never used...)
  87. * $6 is known to be aligned 0mod8
  88. */
  89. $headalign:
  90. subq $1, 16, $4 # .. .. .. E : If < 16, we can not use the huge loop
  91. and $6, 0x3f, $2 # .. .. E .. : Forward work for huge loop
  92. subq $2, 0x40, $3 # .. E .. .. : bias counter (huge loop)
  93. blt $4, $trailquad # U .. .. .. : U L U L
  94. /*
  95. * We know that we're going to do at least 16 quads, which means we are
  96. * going to be able to use the large block clear loop at least once.
  97. * Figure out how many quads we need to clear before we are 0mod64 aligned
  98. * so we can use the wh64 instruction.
  99. */
  100. nop # .. .. .. E
  101. nop # .. .. E ..
  102. nop # .. E .. ..
  103. beq $3, $bigalign # U .. .. .. : U L U L : Aligned 0mod64
  104. $alignmod64:
  105. EX( stq_u $31, 0($6) ) # .. .. .. L
  106. addq $3, 8, $3 # .. .. E ..
  107. subq $0, 8, $0 # .. E .. ..
  108. nop # E .. .. .. : U L U L
  109. nop # .. .. .. E
  110. subq $1, 1, $1 # .. .. E ..
  111. addq $6, 8, $6 # .. E .. ..
  112. blt $3, $alignmod64 # U .. .. .. : U L U L
  113. $bigalign:
  114. /*
  115. * $0 is the number of bytes left
  116. * $1 is the number of quads left
  117. * $6 is aligned 0mod64
  118. * we know that we'll be taking a minimum of one trip through
  119. * CWG Section 3.7.6: do not expect a sustained store rate of > 1/cycle
  120. * We are _not_ going to update $0 after every single store. That
  121. * would be silly, because there will be cross-cluster dependencies
  122. * no matter how the code is scheduled. By doing it in slightly
  123. * staggered fashion, we can still do this loop in 5 fetches
  124. * The worse case will be doing two extra quads in some future execution,
  125. * in the event of an interrupted clear.
  126. * Assumes the wh64 needs to be for 2 trips through the loop in the future
  127. * The wh64 is issued on for the starting destination address for trip +2
  128. * through the loop, and if there are less than two trips left, the target
  129. * address will be for the current trip.
  130. */
  131. nop # E :
  132. nop # E :
  133. nop # E :
  134. bis $6,$6,$3 # E : U L U L : Initial wh64 address is dest
  135. /* This might actually help for the current trip... */
  136. $do_wh64:
  137. wh64 ($3) # .. .. .. L1 : memory subsystem hint
  138. subq $1, 16, $4 # .. .. E .. : Forward calculation - repeat the loop?
  139. EX( stq_u $31, 0($6) ) # .. L .. ..
  140. subq $0, 8, $0 # E .. .. .. : U L U L
  141. addq $6, 128, $3 # E : Target address of wh64
  142. EX( stq_u $31, 8($6) ) # L :
  143. EX( stq_u $31, 16($6) ) # L :
  144. subq $0, 16, $0 # E : U L L U
  145. nop # E :
  146. EX( stq_u $31, 24($6) ) # L :
  147. EX( stq_u $31, 32($6) ) # L :
  148. subq $0, 168, $5 # E : U L L U : two trips through the loop left?
  149. /* 168 = 192 - 24, since we've already completed some stores */
  150. subq $0, 16, $0 # E :
  151. EX( stq_u $31, 40($6) ) # L :
  152. EX( stq_u $31, 48($6) ) # L :
  153. cmovlt $5, $6, $3 # E : U L L U : Latency 2, extra mapping cycle
  154. subq $1, 8, $1 # E :
  155. subq $0, 16, $0 # E :
  156. EX( stq_u $31, 56($6) ) # L :
  157. nop # E : U L U L
  158. nop # E :
  159. subq $0, 8, $0 # E :
  160. addq $6, 64, $6 # E :
  161. bge $4, $do_wh64 # U : U L U L
  162. $trailquad:
  163. # zero to 16 quadwords left to store, plus any trailing bytes
  164. # $1 is the number of quadwords left to go.
  165. #
  166. nop # .. .. .. E
  167. nop # .. .. E ..
  168. nop # .. E .. ..
  169. beq $1, $trailbytes # U .. .. .. : U L U L : Only 0..7 bytes to go
  170. $onequad:
  171. EX( stq_u $31, 0($6) ) # .. .. .. L
  172. subq $1, 1, $1 # .. .. E ..
  173. subq $0, 8, $0 # .. E .. ..
  174. nop # E .. .. .. : U L U L
  175. nop # .. .. .. E
  176. nop # .. .. E ..
  177. addq $6, 8, $6 # .. E .. ..
  178. bgt $1, $onequad # U .. .. .. : U L U L
  179. # We have an unknown number of bytes left to go.
  180. $trailbytes:
  181. nop # .. .. .. E
  182. nop # .. .. E ..
  183. nop # .. E .. ..
  184. beq $0, $zerolength # U .. .. .. : U L U L
  185. # $0 contains the number of bytes left to copy (0..31)
  186. # so we will use $0 as the loop counter
  187. # We know for a fact that $0 > 0 zero due to previous context
  188. $onebyte:
  189. EX( stb $31, 0($6) ) # .. .. .. L
  190. subq $0, 1, $0 # .. .. E .. :
  191. addq $6, 1, $6 # .. E .. .. :
  192. bgt $0, $onebyte # U .. .. .. : U L U L
  193. $zerolength:
  194. $exception: # Destination for exception recovery(?)
  195. nop # .. .. .. E :
  196. nop # .. .. E .. :
  197. nop # .. E .. .. :
  198. ret $31, ($28), 1 # L0 .. .. .. : L U L U
  199. .end __do_clear_user