memcpy_64.S 4.0 KB

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