bzero.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* bzero.S: Simple prefetching memset, bzero, and clear_user
  3. * implementations.
  4. *
  5. * Copyright (C) 2005 David S. Miller <davem@davemloft.net>
  6. */
  7. #include <linux/linkage.h>
  8. #include <asm/export.h>
  9. .text
  10. ENTRY(memset) /* %o0=buf, %o1=pat, %o2=len */
  11. and %o1, 0xff, %o3
  12. mov %o2, %o1
  13. sllx %o3, 8, %g1
  14. or %g1, %o3, %o2
  15. sllx %o2, 16, %g1
  16. or %g1, %o2, %o2
  17. sllx %o2, 32, %g1
  18. ba,pt %xcc, 1f
  19. or %g1, %o2, %o2
  20. ENTRY(__bzero) /* %o0=buf, %o1=len */
  21. clr %o2
  22. 1: mov %o0, %o3
  23. brz,pn %o1, __bzero_done
  24. cmp %o1, 16
  25. bl,pn %icc, __bzero_tiny
  26. prefetch [%o0 + 0x000], #n_writes
  27. andcc %o0, 0x3, %g0
  28. be,pt %icc, 2f
  29. 1: stb %o2, [%o0 + 0x00]
  30. add %o0, 1, %o0
  31. andcc %o0, 0x3, %g0
  32. bne,pn %icc, 1b
  33. sub %o1, 1, %o1
  34. 2: andcc %o0, 0x7, %g0
  35. be,pt %icc, 3f
  36. stw %o2, [%o0 + 0x00]
  37. sub %o1, 4, %o1
  38. add %o0, 4, %o0
  39. 3: and %o1, 0x38, %g1
  40. cmp %o1, 0x40
  41. andn %o1, 0x3f, %o4
  42. bl,pn %icc, 5f
  43. and %o1, 0x7, %o1
  44. prefetch [%o0 + 0x040], #n_writes
  45. prefetch [%o0 + 0x080], #n_writes
  46. prefetch [%o0 + 0x0c0], #n_writes
  47. prefetch [%o0 + 0x100], #n_writes
  48. prefetch [%o0 + 0x140], #n_writes
  49. 4: prefetch [%o0 + 0x180], #n_writes
  50. stx %o2, [%o0 + 0x00]
  51. stx %o2, [%o0 + 0x08]
  52. stx %o2, [%o0 + 0x10]
  53. stx %o2, [%o0 + 0x18]
  54. stx %o2, [%o0 + 0x20]
  55. stx %o2, [%o0 + 0x28]
  56. stx %o2, [%o0 + 0x30]
  57. stx %o2, [%o0 + 0x38]
  58. subcc %o4, 0x40, %o4
  59. bne,pt %icc, 4b
  60. add %o0, 0x40, %o0
  61. brz,pn %g1, 6f
  62. nop
  63. 5: stx %o2, [%o0 + 0x00]
  64. subcc %g1, 8, %g1
  65. bne,pt %icc, 5b
  66. add %o0, 0x8, %o0
  67. 6: brz,pt %o1, __bzero_done
  68. nop
  69. __bzero_tiny:
  70. 1: stb %o2, [%o0 + 0x00]
  71. subcc %o1, 1, %o1
  72. bne,pt %icc, 1b
  73. add %o0, 1, %o0
  74. __bzero_done:
  75. retl
  76. mov %o3, %o0
  77. ENDPROC(__bzero)
  78. ENDPROC(memset)
  79. EXPORT_SYMBOL(__bzero)
  80. EXPORT_SYMBOL(memset)
  81. #define EX_ST(x,y) \
  82. 98: x,y; \
  83. .section __ex_table,"a";\
  84. .align 4; \
  85. .word 98b, __retl_o1; \
  86. .text; \
  87. .align 4;
  88. ENTRY(__clear_user) /* %o0=buf, %o1=len */
  89. brz,pn %o1, __clear_user_done
  90. cmp %o1, 16
  91. bl,pn %icc, __clear_user_tiny
  92. EX_ST(prefetcha [%o0 + 0x00] %asi, #n_writes)
  93. andcc %o0, 0x3, %g0
  94. be,pt %icc, 2f
  95. 1: EX_ST(stba %g0, [%o0 + 0x00] %asi)
  96. add %o0, 1, %o0
  97. andcc %o0, 0x3, %g0
  98. bne,pn %icc, 1b
  99. sub %o1, 1, %o1
  100. 2: andcc %o0, 0x7, %g0
  101. be,pt %icc, 3f
  102. EX_ST(stwa %g0, [%o0 + 0x00] %asi)
  103. sub %o1, 4, %o1
  104. add %o0, 4, %o0
  105. 3: and %o1, 0x38, %g1
  106. cmp %o1, 0x40
  107. andn %o1, 0x3f, %o4
  108. bl,pn %icc, 5f
  109. and %o1, 0x7, %o1
  110. EX_ST(prefetcha [%o0 + 0x040] %asi, #n_writes)
  111. EX_ST(prefetcha [%o0 + 0x080] %asi, #n_writes)
  112. EX_ST(prefetcha [%o0 + 0x0c0] %asi, #n_writes)
  113. EX_ST(prefetcha [%o0 + 0x100] %asi, #n_writes)
  114. EX_ST(prefetcha [%o0 + 0x140] %asi, #n_writes)
  115. 4: EX_ST(prefetcha [%o0 + 0x180] %asi, #n_writes)
  116. EX_ST(stxa %g0, [%o0 + 0x00] %asi)
  117. EX_ST(stxa %g0, [%o0 + 0x08] %asi)
  118. EX_ST(stxa %g0, [%o0 + 0x10] %asi)
  119. EX_ST(stxa %g0, [%o0 + 0x18] %asi)
  120. EX_ST(stxa %g0, [%o0 + 0x20] %asi)
  121. EX_ST(stxa %g0, [%o0 + 0x28] %asi)
  122. EX_ST(stxa %g0, [%o0 + 0x30] %asi)
  123. EX_ST(stxa %g0, [%o0 + 0x38] %asi)
  124. subcc %o4, 0x40, %o4
  125. bne,pt %icc, 4b
  126. add %o0, 0x40, %o0
  127. brz,pn %g1, 6f
  128. nop
  129. 5: EX_ST(stxa %g0, [%o0 + 0x00] %asi)
  130. subcc %g1, 8, %g1
  131. bne,pt %icc, 5b
  132. add %o0, 0x8, %o0
  133. 6: brz,pt %o1, __clear_user_done
  134. nop
  135. __clear_user_tiny:
  136. 1: EX_ST(stba %g0, [%o0 + 0x00] %asi)
  137. subcc %o1, 1, %o1
  138. bne,pt %icc, 1b
  139. add %o0, 1, %o0
  140. __clear_user_done:
  141. retl
  142. clr %o0
  143. ENDPROC(__clear_user)
  144. EXPORT_SYMBOL(__clear_user)