memcpy.S 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
  3. * Copyright (C) 2008-2009 PetaLogix
  4. * Copyright (C) 2008 Jim Law - Iris LP All rights reserved.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General
  7. * Public License. See the file COPYING in the main directory of this
  8. * archive for more details.
  9. *
  10. * Written by Jim Law <jlaw@irispower.com>
  11. *
  12. * intended to replace:
  13. * memcpy in memcpy.c and
  14. * memmove in memmove.c
  15. * ... in arch/microblaze/lib
  16. *
  17. *
  18. * assly_fastcopy.S
  19. *
  20. * Attempt at quicker memcpy and memmove for MicroBlaze
  21. * Input : Operand1 in Reg r5 - destination address
  22. * Operand2 in Reg r6 - source address
  23. * Operand3 in Reg r7 - number of bytes to transfer
  24. * Output: Result in Reg r3 - starting destinaition address
  25. *
  26. *
  27. * Explanation:
  28. * Perform (possibly unaligned) copy of a block of memory
  29. * between mem locations with size of xfer spec'd in bytes
  30. */
  31. .text
  32. .globl memcpy
  33. .type memcpy, @function
  34. .ent memcpy
  35. #ifdef __MICROBLAZEEL__
  36. # define BSLLI bsrli
  37. # define BSRLI bslli
  38. #else
  39. # define BSLLI bslli
  40. # define BSRLI bsrli
  41. #endif
  42. memcpy:
  43. fast_memcpy_ascending:
  44. /* move d to return register as value of function */
  45. addi r3, r5, 0
  46. addi r4, r0, 4 /* n = 4 */
  47. cmpu r4, r4, r7 /* n = c - n (unsigned) */
  48. blti r4, a_xfer_end /* if n < 0, less than one word to transfer */
  49. /* transfer first 0~3 bytes to get aligned dest address */
  50. andi r4, r5, 3 /* n = d & 3 */
  51. /* if zero, destination already aligned */
  52. beqi r4, a_dalign_done
  53. /* n = 4 - n (yields 3, 2, 1 transfers for 1, 2, 3 addr offset) */
  54. rsubi r4, r4, 4
  55. rsub r7, r4, r7 /* c = c - n adjust c */
  56. a_xfer_first_loop:
  57. /* if no bytes left to transfer, transfer the bulk */
  58. beqi r4, a_dalign_done
  59. lbui r11, r6, 0 /* h = *s */
  60. sbi r11, r5, 0 /* *d = h */
  61. addi r6, r6, 1 /* s++ */
  62. addi r5, r5, 1 /* d++ */
  63. brid a_xfer_first_loop /* loop */
  64. addi r4, r4, -1 /* n-- (IN DELAY SLOT) */
  65. a_dalign_done:
  66. addi r4, r0, 32 /* n = 32 */
  67. cmpu r4, r4, r7 /* n = c - n (unsigned) */
  68. /* if n < 0, less than one block to transfer */
  69. blti r4, a_block_done
  70. a_block_xfer:
  71. andi r9, r6, 3 /* t1 = s & 3 */
  72. /* if temp == 0, everything is word-aligned */
  73. beqi r9, a_word_xfer
  74. a_block_unaligned:
  75. andi r4, r7, 0xffffffe0 /* n = c & ~31 */
  76. rsub r7, r4, r7 /* c = c - n */
  77. andi r8, r6, 0xfffffffc /* as = s & ~3 */
  78. add r6, r6, r4 /* s = s + n */
  79. lwi r11, r8, 0 /* h = *(as + 0) */
  80. addi r9, r9, -1
  81. beqi r9, a_block_u1 /* t1 was 1 => 1 byte offset */
  82. addi r9, r9, -1
  83. beqi r9, a_block_u2 /* t1 was 2 => 2 byte offset */
  84. a_block_u3:
  85. BSLLI r11, r11, 24 /* h = h << 24 */
  86. a_bu3_loop:
  87. lwi r12, r8, 4 /* v = *(as + 4) */
  88. BSRLI r9, r12, 8 /* t1 = v >> 8 */
  89. or r9, r11, r9 /* t1 = h | t1 */
  90. swi r9, r5, 0 /* *(d + 0) = t1 */
  91. BSLLI r11, r12, 24 /* h = v << 24 */
  92. lwi r12, r8, 8 /* v = *(as + 8) */
  93. BSRLI r9, r12, 8 /* t1 = v >> 8 */
  94. or r9, r11, r9 /* t1 = h | t1 */
  95. swi r9, r5, 4 /* *(d + 4) = t1 */
  96. BSLLI r11, r12, 24 /* h = v << 24 */
  97. lwi r12, r8, 12 /* v = *(as + 12) */
  98. BSRLI r9, r12, 8 /* t1 = v >> 8 */
  99. or r9, r11, r9 /* t1 = h | t1 */
  100. swi r9, r5, 8 /* *(d + 8) = t1 */
  101. BSLLI r11, r12, 24 /* h = v << 24 */
  102. lwi r12, r8, 16 /* v = *(as + 16) */
  103. BSRLI r9, r12, 8 /* t1 = v >> 8 */
  104. or r9, r11, r9 /* t1 = h | t1 */
  105. swi r9, r5, 12 /* *(d + 12) = t1 */
  106. BSLLI r11, r12, 24 /* h = v << 24 */
  107. lwi r12, r8, 20 /* v = *(as + 20) */
  108. BSRLI r9, r12, 8 /* t1 = v >> 8 */
  109. or r9, r11, r9 /* t1 = h | t1 */
  110. swi r9, r5, 16 /* *(d + 16) = t1 */
  111. BSLLI r11, r12, 24 /* h = v << 24 */
  112. lwi r12, r8, 24 /* v = *(as + 24) */
  113. BSRLI r9, r12, 8 /* t1 = v >> 8 */
  114. or r9, r11, r9 /* t1 = h | t1 */
  115. swi r9, r5, 20 /* *(d + 20) = t1 */
  116. BSLLI r11, r12, 24 /* h = v << 24 */
  117. lwi r12, r8, 28 /* v = *(as + 28) */
  118. BSRLI r9, r12, 8 /* t1 = v >> 8 */
  119. or r9, r11, r9 /* t1 = h | t1 */
  120. swi r9, r5, 24 /* *(d + 24) = t1 */
  121. BSLLI r11, r12, 24 /* h = v << 24 */
  122. lwi r12, r8, 32 /* v = *(as + 32) */
  123. BSRLI r9, r12, 8 /* t1 = v >> 8 */
  124. or r9, r11, r9 /* t1 = h | t1 */
  125. swi r9, r5, 28 /* *(d + 28) = t1 */
  126. BSLLI r11, r12, 24 /* h = v << 24 */
  127. addi r8, r8, 32 /* as = as + 32 */
  128. addi r4, r4, -32 /* n = n - 32 */
  129. bneid r4, a_bu3_loop /* while (n) loop */
  130. addi r5, r5, 32 /* d = d + 32 (IN DELAY SLOT) */
  131. bri a_block_done
  132. a_block_u1:
  133. BSLLI r11, r11, 8 /* h = h << 8 */
  134. a_bu1_loop:
  135. lwi r12, r8, 4 /* v = *(as + 4) */
  136. BSRLI r9, r12, 24 /* t1 = v >> 24 */
  137. or r9, r11, r9 /* t1 = h | t1 */
  138. swi r9, r5, 0 /* *(d + 0) = t1 */
  139. BSLLI r11, r12, 8 /* h = v << 8 */
  140. lwi r12, r8, 8 /* v = *(as + 8) */
  141. BSRLI r9, r12, 24 /* t1 = v >> 24 */
  142. or r9, r11, r9 /* t1 = h | t1 */
  143. swi r9, r5, 4 /* *(d + 4) = t1 */
  144. BSLLI r11, r12, 8 /* h = v << 8 */
  145. lwi r12, r8, 12 /* v = *(as + 12) */
  146. BSRLI r9, r12, 24 /* t1 = v >> 24 */
  147. or r9, r11, r9 /* t1 = h | t1 */
  148. swi r9, r5, 8 /* *(d + 8) = t1 */
  149. BSLLI r11, r12, 8 /* h = v << 8 */
  150. lwi r12, r8, 16 /* v = *(as + 16) */
  151. BSRLI r9, r12, 24 /* t1 = v >> 24 */
  152. or r9, r11, r9 /* t1 = h | t1 */
  153. swi r9, r5, 12 /* *(d + 12) = t1 */
  154. BSLLI r11, r12, 8 /* h = v << 8 */
  155. lwi r12, r8, 20 /* v = *(as + 20) */
  156. BSRLI r9, r12, 24 /* t1 = v >> 24 */
  157. or r9, r11, r9 /* t1 = h | t1 */
  158. swi r9, r5, 16 /* *(d + 16) = t1 */
  159. BSLLI r11, r12, 8 /* h = v << 8 */
  160. lwi r12, r8, 24 /* v = *(as + 24) */
  161. BSRLI r9, r12, 24 /* t1 = v >> 24 */
  162. or r9, r11, r9 /* t1 = h | t1 */
  163. swi r9, r5, 20 /* *(d + 20) = t1 */
  164. BSLLI r11, r12, 8 /* h = v << 8 */
  165. lwi r12, r8, 28 /* v = *(as + 28) */
  166. BSRLI r9, r12, 24 /* t1 = v >> 24 */
  167. or r9, r11, r9 /* t1 = h | t1 */
  168. swi r9, r5, 24 /* *(d + 24) = t1 */
  169. BSLLI r11, r12, 8 /* h = v << 8 */
  170. lwi r12, r8, 32 /* v = *(as + 32) */
  171. BSRLI r9, r12, 24 /* t1 = v >> 24 */
  172. or r9, r11, r9 /* t1 = h | t1 */
  173. swi r9, r5, 28 /* *(d + 28) = t1 */
  174. BSLLI r11, r12, 8 /* h = v << 8 */
  175. addi r8, r8, 32 /* as = as + 32 */
  176. addi r4, r4, -32 /* n = n - 32 */
  177. bneid r4, a_bu1_loop /* while (n) loop */
  178. addi r5, r5, 32 /* d = d + 32 (IN DELAY SLOT) */
  179. bri a_block_done
  180. a_block_u2:
  181. BSLLI r11, r11, 16 /* h = h << 16 */
  182. a_bu2_loop:
  183. lwi r12, r8, 4 /* v = *(as + 4) */
  184. BSRLI r9, r12, 16 /* t1 = v >> 16 */
  185. or r9, r11, r9 /* t1 = h | t1 */
  186. swi r9, r5, 0 /* *(d + 0) = t1 */
  187. BSLLI r11, r12, 16 /* h = v << 16 */
  188. lwi r12, r8, 8 /* v = *(as + 8) */
  189. BSRLI r9, r12, 16 /* t1 = v >> 16 */
  190. or r9, r11, r9 /* t1 = h | t1 */
  191. swi r9, r5, 4 /* *(d + 4) = t1 */
  192. BSLLI r11, r12, 16 /* h = v << 16 */
  193. lwi r12, r8, 12 /* v = *(as + 12) */
  194. BSRLI r9, r12, 16 /* t1 = v >> 16 */
  195. or r9, r11, r9 /* t1 = h | t1 */
  196. swi r9, r5, 8 /* *(d + 8) = t1 */
  197. BSLLI r11, r12, 16 /* h = v << 16 */
  198. lwi r12, r8, 16 /* v = *(as + 16) */
  199. BSRLI r9, r12, 16 /* t1 = v >> 16 */
  200. or r9, r11, r9 /* t1 = h | t1 */
  201. swi r9, r5, 12 /* *(d + 12) = t1 */
  202. BSLLI r11, r12, 16 /* h = v << 16 */
  203. lwi r12, r8, 20 /* v = *(as + 20) */
  204. BSRLI r9, r12, 16 /* t1 = v >> 16 */
  205. or r9, r11, r9 /* t1 = h | t1 */
  206. swi r9, r5, 16 /* *(d + 16) = t1 */
  207. BSLLI r11, r12, 16 /* h = v << 16 */
  208. lwi r12, r8, 24 /* v = *(as + 24) */
  209. BSRLI r9, r12, 16 /* t1 = v >> 16 */
  210. or r9, r11, r9 /* t1 = h | t1 */
  211. swi r9, r5, 20 /* *(d + 20) = t1 */
  212. BSLLI r11, r12, 16 /* h = v << 16 */
  213. lwi r12, r8, 28 /* v = *(as + 28) */
  214. BSRLI r9, r12, 16 /* t1 = v >> 16 */
  215. or r9, r11, r9 /* t1 = h | t1 */
  216. swi r9, r5, 24 /* *(d + 24) = t1 */
  217. BSLLI r11, r12, 16 /* h = v << 16 */
  218. lwi r12, r8, 32 /* v = *(as + 32) */
  219. BSRLI r9, r12, 16 /* t1 = v >> 16 */
  220. or r9, r11, r9 /* t1 = h | t1 */
  221. swi r9, r5, 28 /* *(d + 28) = t1 */
  222. BSLLI r11, r12, 16 /* h = v << 16 */
  223. addi r8, r8, 32 /* as = as + 32 */
  224. addi r4, r4, -32 /* n = n - 32 */
  225. bneid r4, a_bu2_loop /* while (n) loop */
  226. addi r5, r5, 32 /* d = d + 32 (IN DELAY SLOT) */
  227. a_block_done:
  228. addi r4, r0, 4 /* n = 4 */
  229. cmpu r4, r4, r7 /* n = c - n (unsigned) */
  230. blti r4, a_xfer_end /* if n < 0, less than one word to transfer */
  231. a_word_xfer:
  232. andi r4, r7, 0xfffffffc /* n = c & ~3 */
  233. addi r10, r0, 0 /* offset = 0 */
  234. andi r9, r6, 3 /* t1 = s & 3 */
  235. /* if temp != 0, unaligned transfers needed */
  236. bnei r9, a_word_unaligned
  237. a_word_aligned:
  238. lw r9, r6, r10 /* t1 = *(s+offset) */
  239. sw r9, r5, r10 /* *(d+offset) = t1 */
  240. addi r4, r4,-4 /* n-- */
  241. bneid r4, a_word_aligned /* loop */
  242. addi r10, r10, 4 /* offset++ (IN DELAY SLOT) */
  243. bri a_word_done
  244. a_word_unaligned:
  245. andi r8, r6, 0xfffffffc /* as = s & ~3 */
  246. lwi r11, r8, 0 /* h = *(as + 0) */
  247. addi r8, r8, 4 /* as = as + 4 */
  248. addi r9, r9, -1
  249. beqi r9, a_word_u1 /* t1 was 1 => 1 byte offset */
  250. addi r9, r9, -1
  251. beqi r9, a_word_u2 /* t1 was 2 => 2 byte offset */
  252. a_word_u3:
  253. BSLLI r11, r11, 24 /* h = h << 24 */
  254. a_wu3_loop:
  255. lw r12, r8, r10 /* v = *(as + offset) */
  256. BSRLI r9, r12, 8 /* t1 = v >> 8 */
  257. or r9, r11, r9 /* t1 = h | t1 */
  258. sw r9, r5, r10 /* *(d + offset) = t1 */
  259. BSLLI r11, r12, 24 /* h = v << 24 */
  260. addi r4, r4,-4 /* n = n - 4 */
  261. bneid r4, a_wu3_loop /* while (n) loop */
  262. addi r10, r10, 4 /* offset = ofset + 4 (IN DELAY SLOT) */
  263. bri a_word_done
  264. a_word_u1:
  265. BSLLI r11, r11, 8 /* h = h << 8 */
  266. a_wu1_loop:
  267. lw r12, r8, r10 /* v = *(as + offset) */
  268. BSRLI r9, r12, 24 /* t1 = v >> 24 */
  269. or r9, r11, r9 /* t1 = h | t1 */
  270. sw r9, r5, r10 /* *(d + offset) = t1 */
  271. BSLLI r11, r12, 8 /* h = v << 8 */
  272. addi r4, r4,-4 /* n = n - 4 */
  273. bneid r4, a_wu1_loop /* while (n) loop */
  274. addi r10, r10, 4 /* offset = ofset + 4 (IN DELAY SLOT) */
  275. bri a_word_done
  276. a_word_u2:
  277. BSLLI r11, r11, 16 /* h = h << 16 */
  278. a_wu2_loop:
  279. lw r12, r8, r10 /* v = *(as + offset) */
  280. BSRLI r9, r12, 16 /* t1 = v >> 16 */
  281. or r9, r11, r9 /* t1 = h | t1 */
  282. sw r9, r5, r10 /* *(d + offset) = t1 */
  283. BSLLI r11, r12, 16 /* h = v << 16 */
  284. addi r4, r4,-4 /* n = n - 4 */
  285. bneid r4, a_wu2_loop /* while (n) loop */
  286. addi r10, r10, 4 /* offset = ofset + 4 (IN DELAY SLOT) */
  287. a_word_done:
  288. add r5, r5, r10 /* d = d + offset */
  289. add r6, r6, r10 /* s = s + offset */
  290. rsub r7, r10, r7 /* c = c - offset */
  291. a_xfer_end:
  292. a_xfer_end_loop:
  293. beqi r7, a_done /* while (c) */
  294. lbui r9, r6, 0 /* t1 = *s */
  295. addi r6, r6, 1 /* s++ */
  296. sbi r9, r5, 0 /* *d = t1 */
  297. addi r7, r7, -1 /* c-- */
  298. brid a_xfer_end_loop /* loop */
  299. addi r5, r5, 1 /* d++ (IN DELAY SLOT) */
  300. a_done:
  301. rtsd r15, 8
  302. nop
  303. .size memcpy, . - memcpy
  304. .end memcpy
  305. libc_hidden_def(memcpy)