copy_template.S 4.6 KB

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