memcpy_64.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Copyright (C) 2002 Paul Mackerras, IBM Corp.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <asm/processor.h>
  10. #include <asm/ppc_asm.h>
  11. #include <asm/export.h>
  12. .align 7
  13. _GLOBAL_TOC(memcpy)
  14. BEGIN_FTR_SECTION
  15. #ifdef __LITTLE_ENDIAN__
  16. cmpdi cr7,r5,0
  17. #else
  18. std r3,-STACKFRAMESIZE+STK_REG(R31)(r1) /* save destination pointer for return value */
  19. #endif
  20. FTR_SECTION_ELSE
  21. #ifndef SELFTEST
  22. b memcpy_power7
  23. #endif
  24. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_VMX_COPY)
  25. #ifdef __LITTLE_ENDIAN__
  26. /* dumb little-endian memcpy that will get replaced at runtime */
  27. addi r9,r3,-1
  28. addi r4,r4,-1
  29. beqlr cr7
  30. mtctr r5
  31. 1: lbzu r10,1(r4)
  32. stbu r10,1(r9)
  33. bdnz 1b
  34. blr
  35. #else
  36. PPC_MTOCRF(0x01,r5)
  37. cmpldi cr1,r5,16
  38. neg r6,r3 # LS 3 bits = # bytes to 8-byte dest bdry
  39. andi. r6,r6,7
  40. dcbt 0,r4
  41. blt cr1,.Lshort_copy
  42. /* Below we want to nop out the bne if we're on a CPU that has the
  43. CPU_FTR_UNALIGNED_LD_STD bit set and the CPU_FTR_CP_USE_DCBTZ bit
  44. cleared.
  45. At the time of writing the only CPU that has this combination of bits
  46. set is Power6. */
  47. BEGIN_FTR_SECTION
  48. nop
  49. FTR_SECTION_ELSE
  50. bne .Ldst_unaligned
  51. ALT_FTR_SECTION_END(CPU_FTR_UNALIGNED_LD_STD | CPU_FTR_CP_USE_DCBTZ, \
  52. CPU_FTR_UNALIGNED_LD_STD)
  53. .Ldst_aligned:
  54. addi r3,r3,-16
  55. BEGIN_FTR_SECTION
  56. andi. r0,r4,7
  57. bne .Lsrc_unaligned
  58. END_FTR_SECTION_IFCLR(CPU_FTR_UNALIGNED_LD_STD)
  59. srdi r7,r5,4
  60. ld r9,0(r4)
  61. addi r4,r4,-8
  62. mtctr r7
  63. andi. r5,r5,7
  64. bf cr7*4+0,2f
  65. addi r3,r3,8
  66. addi r4,r4,8
  67. mr r8,r9
  68. blt cr1,3f
  69. 1: ld r9,8(r4)
  70. std r8,8(r3)
  71. 2: ldu r8,16(r4)
  72. stdu r9,16(r3)
  73. bdnz 1b
  74. 3: std r8,8(r3)
  75. beq 3f
  76. addi r3,r3,16
  77. .Ldo_tail:
  78. bf cr7*4+1,1f
  79. lwz r9,8(r4)
  80. addi r4,r4,4
  81. stw r9,0(r3)
  82. addi r3,r3,4
  83. 1: bf cr7*4+2,2f
  84. lhz r9,8(r4)
  85. addi r4,r4,2
  86. sth r9,0(r3)
  87. addi r3,r3,2
  88. 2: bf cr7*4+3,3f
  89. lbz r9,8(r4)
  90. stb r9,0(r3)
  91. 3: ld r3,-STACKFRAMESIZE+STK_REG(R31)(r1) /* return dest pointer */
  92. blr
  93. .Lsrc_unaligned:
  94. srdi r6,r5,3
  95. addi r5,r5,-16
  96. subf r4,r0,r4
  97. srdi r7,r5,4
  98. sldi r10,r0,3
  99. cmpdi cr6,r6,3
  100. andi. r5,r5,7
  101. mtctr r7
  102. subfic r11,r10,64
  103. add r5,r5,r0
  104. bt cr7*4+0,0f
  105. ld r9,0(r4) # 3+2n loads, 2+2n stores
  106. ld r0,8(r4)
  107. sld r6,r9,r10
  108. ldu r9,16(r4)
  109. srd r7,r0,r11
  110. sld r8,r0,r10
  111. or r7,r7,r6
  112. blt cr6,4f
  113. ld r0,8(r4)
  114. # s1<< in r8, d0=(s0<<|s1>>) in r7, s3 in r0, s2 in r9, nix in r6 & r12
  115. b 2f
  116. 0: ld r0,0(r4) # 4+2n loads, 3+2n stores
  117. ldu r9,8(r4)
  118. sld r8,r0,r10
  119. addi r3,r3,-8
  120. blt cr6,5f
  121. ld r0,8(r4)
  122. srd r12,r9,r11
  123. sld r6,r9,r10
  124. ldu r9,16(r4)
  125. or r12,r8,r12
  126. srd r7,r0,r11
  127. sld r8,r0,r10
  128. addi r3,r3,16
  129. beq cr6,3f
  130. # d0=(s0<<|s1>>) in r12, s1<< in r6, s2>> in r7, s2<< in r8, s3 in r9
  131. 1: or r7,r7,r6
  132. ld r0,8(r4)
  133. std r12,8(r3)
  134. 2: srd r12,r9,r11
  135. sld r6,r9,r10
  136. ldu r9,16(r4)
  137. or r12,r8,r12
  138. stdu r7,16(r3)
  139. srd r7,r0,r11
  140. sld r8,r0,r10
  141. bdnz 1b
  142. 3: std r12,8(r3)
  143. or r7,r7,r6
  144. 4: std r7,16(r3)
  145. 5: srd r12,r9,r11
  146. or r12,r8,r12
  147. std r12,24(r3)
  148. beq 4f
  149. cmpwi cr1,r5,8
  150. addi r3,r3,32
  151. sld r9,r9,r10
  152. ble cr1,6f
  153. ld r0,8(r4)
  154. srd r7,r0,r11
  155. or r9,r7,r9
  156. 6:
  157. bf cr7*4+1,1f
  158. rotldi r9,r9,32
  159. stw r9,0(r3)
  160. addi r3,r3,4
  161. 1: bf cr7*4+2,2f
  162. rotldi r9,r9,16
  163. sth r9,0(r3)
  164. addi r3,r3,2
  165. 2: bf cr7*4+3,3f
  166. rotldi r9,r9,8
  167. stb r9,0(r3)
  168. 3: ld r3,-STACKFRAMESIZE+STK_REG(R31)(r1) /* return dest pointer */
  169. blr
  170. .Ldst_unaligned:
  171. PPC_MTOCRF(0x01,r6) # put #bytes to 8B bdry into cr7
  172. subf r5,r6,r5
  173. li r7,0
  174. cmpldi cr1,r5,16
  175. bf cr7*4+3,1f
  176. lbz r0,0(r4)
  177. stb r0,0(r3)
  178. addi r7,r7,1
  179. 1: bf cr7*4+2,2f
  180. lhzx r0,r7,r4
  181. sthx r0,r7,r3
  182. addi r7,r7,2
  183. 2: bf cr7*4+1,3f
  184. lwzx r0,r7,r4
  185. stwx r0,r7,r3
  186. 3: PPC_MTOCRF(0x01,r5)
  187. add r4,r6,r4
  188. add r3,r6,r3
  189. b .Ldst_aligned
  190. .Lshort_copy:
  191. bf cr7*4+0,1f
  192. lwz r0,0(r4)
  193. lwz r9,4(r4)
  194. addi r4,r4,8
  195. stw r0,0(r3)
  196. stw r9,4(r3)
  197. addi r3,r3,8
  198. 1: bf cr7*4+1,2f
  199. lwz r0,0(r4)
  200. addi r4,r4,4
  201. stw r0,0(r3)
  202. addi r3,r3,4
  203. 2: bf cr7*4+2,3f
  204. lhz r0,0(r4)
  205. addi r4,r4,2
  206. sth r0,0(r3)
  207. addi r3,r3,2
  208. 3: bf cr7*4+3,4f
  209. lbz r0,0(r4)
  210. stb r0,0(r3)
  211. 4: ld r3,-STACKFRAMESIZE+STK_REG(R31)(r1) /* return dest pointer */
  212. blr
  213. #endif
  214. EXPORT_SYMBOL(memcpy)