copy_template.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013 ARM Ltd.
  4. * Copyright (C) 2013 Linaro.
  5. *
  6. * This code is based on glibc cortex strings work originally authored by Linaro
  7. * be found @
  8. *
  9. * http://bazaar.launchpad.net/~linaro-toolchain-dev/cortex-strings/trunk/
  10. * files/head:/src/aarch64/
  11. */
  12. /*
  13. * Copy a buffer from src to dest (alignment handled by the hardware)
  14. *
  15. * Parameters:
  16. * x0 - dest
  17. * x1 - src
  18. * x2 - n
  19. * Returns:
  20. * x0 - dest
  21. */
  22. dstin .req x0
  23. src .req x1
  24. count .req x2
  25. tmp1 .req x3
  26. tmp1w .req w3
  27. tmp2 .req x4
  28. tmp2w .req w4
  29. dst .req x6
  30. A_l .req x7
  31. A_h .req x8
  32. B_l .req x9
  33. B_h .req x10
  34. C_l .req x11
  35. C_h .req x12
  36. D_l .req x13
  37. D_h .req x14
  38. mov dst, dstin
  39. #ifdef CONFIG_AS_HAS_MOPS
  40. alternative_if_not ARM64_HAS_MOPS
  41. b .Lno_mops
  42. alternative_else_nop_endif
  43. cpy1 dst, src, count
  44. b .Lexitfunc
  45. .Lno_mops:
  46. #endif
  47. cmp count, #16
  48. /*When memory length is less than 16, the accessed are not aligned.*/
  49. b.lo .Ltiny15
  50. neg tmp2, src
  51. ands tmp2, tmp2, #15/* Bytes to reach alignment. */
  52. b.eq .LSrcAligned
  53. sub count, count, tmp2
  54. /*
  55. * Copy the leading memory data from src to dst in an increasing
  56. * address order.By this way,the risk of overwriting the source
  57. * memory data is eliminated when the distance between src and
  58. * dst is less than 16. The memory accesses here are alignment.
  59. */
  60. tbz tmp2, #0, 1f
  61. ldrb1 tmp1w, src, #1
  62. strb1 tmp1w, dst, #1
  63. 1:
  64. tbz tmp2, #1, 2f
  65. ldrh1 tmp1w, src, #2
  66. strh1 tmp1w, dst, #2
  67. 2:
  68. tbz tmp2, #2, 3f
  69. ldr1 tmp1w, src, #4
  70. str1 tmp1w, dst, #4
  71. 3:
  72. tbz tmp2, #3, .LSrcAligned
  73. ldr1 tmp1, src, #8
  74. str1 tmp1, dst, #8
  75. .LSrcAligned:
  76. cmp count, #64
  77. b.ge .Lcpy_over64
  78. /*
  79. * Deal with small copies quickly by dropping straight into the
  80. * exit block.
  81. */
  82. .Ltail63:
  83. /*
  84. * Copy up to 48 bytes of data. At this point we only need the
  85. * bottom 6 bits of count to be accurate.
  86. */
  87. ands tmp1, count, #0x30
  88. b.eq .Ltiny15
  89. cmp tmp1w, #0x20
  90. b.eq 1f
  91. b.lt 2f
  92. ldp1 A_l, A_h, src, #16
  93. stp1 A_l, A_h, dst, #16
  94. 1:
  95. ldp1 A_l, A_h, src, #16
  96. stp1 A_l, A_h, dst, #16
  97. 2:
  98. ldp1 A_l, A_h, src, #16
  99. stp1 A_l, A_h, dst, #16
  100. .Ltiny15:
  101. /*
  102. * Prefer to break one ldp/stp into several load/store to access
  103. * memory in an increasing address order,rather than to load/store 16
  104. * bytes from (src-16) to (dst-16) and to backward the src to aligned
  105. * address,which way is used in original cortex memcpy. If keeping
  106. * the original memcpy process here, memmove need to satisfy the
  107. * precondition that src address is at least 16 bytes bigger than dst
  108. * address,otherwise some source data will be overwritten when memove
  109. * call memcpy directly. To make memmove simpler and decouple the
  110. * memcpy's dependency on memmove, withdrew the original process.
  111. */
  112. tbz count, #3, 1f
  113. ldr1 tmp1, src, #8
  114. str1 tmp1, dst, #8
  115. 1:
  116. tbz count, #2, 2f
  117. ldr1 tmp1w, src, #4
  118. str1 tmp1w, dst, #4
  119. 2:
  120. tbz count, #1, 3f
  121. ldrh1 tmp1w, src, #2
  122. strh1 tmp1w, dst, #2
  123. 3:
  124. tbz count, #0, .Lexitfunc
  125. ldrb1 tmp1w, src, #1
  126. strb1 tmp1w, dst, #1
  127. b .Lexitfunc
  128. .Lcpy_over64:
  129. subs count, count, #128
  130. b.ge .Lcpy_body_large
  131. /*
  132. * Less than 128 bytes to copy, so handle 64 here and then jump
  133. * to the tail.
  134. */
  135. ldp1 A_l, A_h, src, #16
  136. stp1 A_l, A_h, dst, #16
  137. ldp1 B_l, B_h, src, #16
  138. ldp1 C_l, C_h, src, #16
  139. stp1 B_l, B_h, dst, #16
  140. stp1 C_l, C_h, dst, #16
  141. ldp1 D_l, D_h, src, #16
  142. stp1 D_l, D_h, dst, #16
  143. tst count, #0x3f
  144. b.ne .Ltail63
  145. b .Lexitfunc
  146. /*
  147. * Critical loop. Start at a new cache line boundary. Assuming
  148. * 64 bytes per line this ensures the entire loop is in one line.
  149. */
  150. .p2align L1_CACHE_SHIFT
  151. .Lcpy_body_large:
  152. /* pre-get 64 bytes data. */
  153. ldp1 A_l, A_h, src, #16
  154. ldp1 B_l, B_h, src, #16
  155. ldp1 C_l, C_h, src, #16
  156. ldp1 D_l, D_h, src, #16
  157. 1:
  158. /*
  159. * interlace the load of next 64 bytes data block with store of the last
  160. * loaded 64 bytes data.
  161. */
  162. stp1 A_l, A_h, dst, #16
  163. ldp1 A_l, A_h, src, #16
  164. stp1 B_l, B_h, dst, #16
  165. ldp1 B_l, B_h, src, #16
  166. stp1 C_l, C_h, dst, #16
  167. ldp1 C_l, C_h, src, #16
  168. stp1 D_l, D_h, dst, #16
  169. ldp1 D_l, D_h, src, #16
  170. subs count, count, #64
  171. b.ge 1b
  172. stp1 A_l, A_h, dst, #16
  173. stp1 B_l, B_h, dst, #16
  174. stp1 C_l, C_h, dst, #16
  175. stp1 D_l, D_h, dst, #16
  176. tst count, #0x3f
  177. b.ne .Ltail63
  178. .Lexitfunc: