memset.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* Copyright (C) 2012-2017 Free Software Foundation, Inc.
  2. The GNU C Library is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU Lesser General Public
  4. License as published by the Free Software Foundation; either
  5. version 2.1 of the License, or (at your option) any later version.
  6. The GNU C Library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Lesser General Public License for more details.
  10. You should have received a copy of the GNU Lesser General Public
  11. License along with the GNU C Library. If not, see
  12. <http://www.gnu.org/licenses/>. */
  13. #include <sysdep.h>
  14. /* Assumptions:
  15. *
  16. * ARMv8-a, AArch64, unaligned accesses
  17. *
  18. */
  19. #define dstin x0
  20. #define val x1
  21. #define valw w1
  22. #define count x2
  23. #define dst x3
  24. #define dstend x4
  25. #define tmp1 x5
  26. #define tmp1w w5
  27. #define tmp2 x6
  28. #define tmp2w w6
  29. #define zva_len x7
  30. #define zva_lenw w7
  31. ENTRY_ALIGN (memset, 6)
  32. dup v0.16B, valw
  33. add dstend, dstin, count
  34. cmp count, 96
  35. b.hi L(set_long)
  36. cmp count, 16
  37. b.hs L(set_medium)
  38. mov val, v0.D[0]
  39. /* Set 0..15 bytes. */
  40. tbz count, 3, 1f
  41. str val, [dstin]
  42. str val, [dstend, -8]
  43. ret
  44. nop
  45. 1: tbz count, 2, 2f
  46. str valw, [dstin]
  47. str valw, [dstend, -4]
  48. ret
  49. 2: cbz count, 3f
  50. strb valw, [dstin]
  51. tbz count, 1, 3f
  52. strh valw, [dstend, -2]
  53. 3: ret
  54. /* Set 17..96 bytes. */
  55. L(set_medium):
  56. str q0, [dstin]
  57. tbnz count, 6, L(set96)
  58. str q0, [dstend, -16]
  59. tbz count, 5, 1f
  60. str q0, [dstin, 16]
  61. str q0, [dstend, -32]
  62. 1: ret
  63. .p2align 4
  64. /* Set 64..96 bytes. Write 64 bytes from the start and
  65. 32 bytes from the end. */
  66. L(set96):
  67. str q0, [dstin, 16]
  68. stp q0, q0, [dstin, 32]
  69. stp q0, q0, [dstend, -32]
  70. ret
  71. .p2align 3
  72. nop
  73. L(set_long):
  74. and valw, valw, 255
  75. bic dst, dstin, 15
  76. str q0, [dstin]
  77. cmp count, 256
  78. ccmp valw, 0, 0, cs
  79. b.eq L(try_zva)
  80. L(no_zva):
  81. sub count, dstend, dst /* Count is 16 too large. */
  82. add dst, dst, 16
  83. sub count, count, 64 + 16 /* Adjust count and bias for loop. */
  84. 1: stp q0, q0, [dst], 64
  85. stp q0, q0, [dst, -32]
  86. L(tail64):
  87. subs count, count, 64
  88. b.hi 1b
  89. 2: stp q0, q0, [dstend, -64]
  90. stp q0, q0, [dstend, -32]
  91. ret
  92. .p2align 3
  93. L(try_zva):
  94. mrs tmp1, dczid_el0
  95. tbnz tmp1w, 4, L(no_zva)
  96. and tmp1w, tmp1w, 15
  97. cmp tmp1w, 4 /* ZVA size is 64 bytes. */
  98. b.ne L(zva_128)
  99. /* Write the first and last 64 byte aligned block using stp rather
  100. than using DC ZVA. This is faster on some cores.
  101. */
  102. L(zva_64):
  103. str q0, [dst, 16]
  104. stp q0, q0, [dst, 32]
  105. bic dst, dst, 63
  106. stp q0, q0, [dst, 64]
  107. stp q0, q0, [dst, 96]
  108. sub count, dstend, dst /* Count is now 128 too large. */
  109. sub count, count, 128+64+64 /* Adjust count and bias for loop. */
  110. add dst, dst, 128
  111. nop
  112. 1: dc zva, dst
  113. add dst, dst, 64
  114. subs count, count, 64
  115. b.hi 1b
  116. stp q0, q0, [dst, 0]
  117. stp q0, q0, [dst, 32]
  118. stp q0, q0, [dstend, -64]
  119. stp q0, q0, [dstend, -32]
  120. ret
  121. .p2align 3
  122. L(zva_128):
  123. cmp tmp1w, 5 /* ZVA size is 128 bytes. */
  124. b.ne L(zva_other)
  125. str q0, [dst, 16]
  126. stp q0, q0, [dst, 32]
  127. stp q0, q0, [dst, 64]
  128. stp q0, q0, [dst, 96]
  129. bic dst, dst, 127
  130. sub count, dstend, dst /* Count is now 128 too large. */
  131. sub count, count, 128+128 /* Adjust count and bias for loop. */
  132. add dst, dst, 128
  133. 1: dc zva, dst
  134. add dst, dst, 128
  135. subs count, count, 128
  136. b.hi 1b
  137. stp q0, q0, [dstend, -128]
  138. stp q0, q0, [dstend, -96]
  139. stp q0, q0, [dstend, -64]
  140. stp q0, q0, [dstend, -32]
  141. ret
  142. L(zva_other):
  143. mov tmp2w, 4
  144. lsl zva_lenw, tmp2w, tmp1w
  145. add tmp1, zva_len, 64 /* Max alignment bytes written. */
  146. cmp count, tmp1
  147. blo L(no_zva)
  148. sub tmp2, zva_len, 1
  149. add tmp1, dst, zva_len
  150. add dst, dst, 16
  151. subs count, tmp1, dst /* Actual alignment bytes to write. */
  152. bic tmp1, tmp1, tmp2 /* Aligned dc zva start address. */
  153. beq 2f
  154. 1: stp q0, q0, [dst], 64
  155. stp q0, q0, [dst, -32]
  156. subs count, count, 64
  157. b.hi 1b
  158. 2: mov dst, tmp1
  159. sub count, dstend, tmp1 /* Remaining bytes to write. */
  160. subs count, count, zva_len
  161. b.lo 4f
  162. 3: dc zva, dst
  163. add dst, dst, zva_len
  164. subs count, count, zva_len
  165. b.hs 3b
  166. 4: add count, count, zva_len
  167. b L(tail64)
  168. END (memset)
  169. libc_hidden_def (memset)