ev6-clear_user.S 7.0 KB

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