memmove.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * linux/arch/arm/lib/memmove.S
  3. *
  4. * Author: Nicolas Pitre
  5. * Created: Sep 28, 2005
  6. * Copyright: (C) MontaVista Software Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/linkage.h>
  13. #include <asm/assembler.h>
  14. #include <asm/unwind.h>
  15. #include <asm/export.h>
  16. .text
  17. /*
  18. * Prototype: void *memmove(void *dest, const void *src, size_t n);
  19. *
  20. * Note:
  21. *
  22. * If the memory regions don't overlap, we simply branch to memcpy which is
  23. * normally a bit faster. Otherwise the copy is done going downwards. This
  24. * is a transposition of the code from copy_template.S but with the copy
  25. * occurring in the opposite direction.
  26. */
  27. ENTRY(memmove)
  28. UNWIND( .fnstart )
  29. subs ip, r0, r1
  30. cmphi r2, ip
  31. bls memcpy
  32. stmfd sp!, {r0, r4, lr}
  33. UNWIND( .fnend )
  34. UNWIND( .fnstart )
  35. UNWIND( .save {r0, r4, lr} ) @ in first stmfd block
  36. add r1, r1, r2
  37. add r0, r0, r2
  38. subs r2, r2, #4
  39. blt 8f
  40. ands ip, r0, #3
  41. PLD( pld [r1, #-4] )
  42. bne 9f
  43. ands ip, r1, #3
  44. bne 10f
  45. 1: subs r2, r2, #(28)
  46. stmfd sp!, {r5 - r8}
  47. UNWIND( .fnend )
  48. UNWIND( .fnstart )
  49. UNWIND( .save {r0, r4, lr} )
  50. UNWIND( .save {r5 - r8} ) @ in second stmfd block
  51. blt 5f
  52. CALGN( ands ip, r0, #31 )
  53. CALGN( sbcnes r4, ip, r2 ) @ C is always set here
  54. CALGN( bcs 2f )
  55. CALGN( adr r4, 6f )
  56. CALGN( subs r2, r2, ip ) @ C is set here
  57. CALGN( rsb ip, ip, #32 )
  58. CALGN( add pc, r4, ip )
  59. PLD( pld [r1, #-4] )
  60. 2: PLD( subs r2, r2, #96 )
  61. PLD( pld [r1, #-32] )
  62. PLD( blt 4f )
  63. PLD( pld [r1, #-64] )
  64. PLD( pld [r1, #-96] )
  65. 3: PLD( pld [r1, #-128] )
  66. 4: ldmdb r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
  67. subs r2, r2, #32
  68. stmdb r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
  69. bge 3b
  70. PLD( cmn r2, #96 )
  71. PLD( bge 4b )
  72. 5: ands ip, r2, #28
  73. rsb ip, ip, #32
  74. addne pc, pc, ip @ C is always clear here
  75. b 7f
  76. 6: W(nop)
  77. W(ldr) r3, [r1, #-4]!
  78. W(ldr) r4, [r1, #-4]!
  79. W(ldr) r5, [r1, #-4]!
  80. W(ldr) r6, [r1, #-4]!
  81. W(ldr) r7, [r1, #-4]!
  82. W(ldr) r8, [r1, #-4]!
  83. W(ldr) lr, [r1, #-4]!
  84. add pc, pc, ip
  85. nop
  86. W(nop)
  87. W(str) r3, [r0, #-4]!
  88. W(str) r4, [r0, #-4]!
  89. W(str) r5, [r0, #-4]!
  90. W(str) r6, [r0, #-4]!
  91. W(str) r7, [r0, #-4]!
  92. W(str) r8, [r0, #-4]!
  93. W(str) lr, [r0, #-4]!
  94. CALGN( bcs 2b )
  95. 7: ldmfd sp!, {r5 - r8}
  96. UNWIND( .fnend ) @ end of second stmfd block
  97. UNWIND( .fnstart )
  98. UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
  99. 8: movs r2, r2, lsl #31
  100. ldrneb r3, [r1, #-1]!
  101. ldrcsb r4, [r1, #-1]!
  102. ldrcsb ip, [r1, #-1]
  103. strneb r3, [r0, #-1]!
  104. strcsb r4, [r0, #-1]!
  105. strcsb ip, [r0, #-1]
  106. ldmfd sp!, {r0, r4, pc}
  107. 9: cmp ip, #2
  108. ldrgtb r3, [r1, #-1]!
  109. ldrgeb r4, [r1, #-1]!
  110. ldrb lr, [r1, #-1]!
  111. strgtb r3, [r0, #-1]!
  112. strgeb r4, [r0, #-1]!
  113. subs r2, r2, ip
  114. strb lr, [r0, #-1]!
  115. blt 8b
  116. ands ip, r1, #3
  117. beq 1b
  118. 10: bic r1, r1, #3
  119. cmp ip, #2
  120. ldr r3, [r1, #0]
  121. beq 17f
  122. blt 18f
  123. UNWIND( .fnend )
  124. .macro backward_copy_shift push pull
  125. UNWIND( .fnstart )
  126. UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
  127. subs r2, r2, #28
  128. blt 14f
  129. CALGN( ands ip, r0, #31 )
  130. CALGN( sbcnes r4, ip, r2 ) @ C is always set here
  131. CALGN( subcc r2, r2, ip )
  132. CALGN( bcc 15f )
  133. 11: stmfd sp!, {r5 - r9}
  134. UNWIND( .fnend )
  135. UNWIND( .fnstart )
  136. UNWIND( .save {r0, r4, lr} )
  137. UNWIND( .save {r5 - r9} ) @ in new second stmfd block
  138. PLD( pld [r1, #-4] )
  139. PLD( subs r2, r2, #96 )
  140. PLD( pld [r1, #-32] )
  141. PLD( blt 13f )
  142. PLD( pld [r1, #-64] )
  143. PLD( pld [r1, #-96] )
  144. 12: PLD( pld [r1, #-128] )
  145. 13: ldmdb r1!, {r7, r8, r9, ip}
  146. mov lr, r3, lspush #\push
  147. subs r2, r2, #32
  148. ldmdb r1!, {r3, r4, r5, r6}
  149. orr lr, lr, ip, lspull #\pull
  150. mov ip, ip, lspush #\push
  151. orr ip, ip, r9, lspull #\pull
  152. mov r9, r9, lspush #\push
  153. orr r9, r9, r8, lspull #\pull
  154. mov r8, r8, lspush #\push
  155. orr r8, r8, r7, lspull #\pull
  156. mov r7, r7, lspush #\push
  157. orr r7, r7, r6, lspull #\pull
  158. mov r6, r6, lspush #\push
  159. orr r6, r6, r5, lspull #\pull
  160. mov r5, r5, lspush #\push
  161. orr r5, r5, r4, lspull #\pull
  162. mov r4, r4, lspush #\push
  163. orr r4, r4, r3, lspull #\pull
  164. stmdb r0!, {r4 - r9, ip, lr}
  165. bge 12b
  166. PLD( cmn r2, #96 )
  167. PLD( bge 13b )
  168. ldmfd sp!, {r5 - r9}
  169. UNWIND( .fnend ) @ end of the second stmfd block
  170. UNWIND( .fnstart )
  171. UNWIND( .save {r0, r4, lr} ) @ still in first stmfd block
  172. 14: ands ip, r2, #28
  173. beq 16f
  174. 15: mov lr, r3, lspush #\push
  175. ldr r3, [r1, #-4]!
  176. subs ip, ip, #4
  177. orr lr, lr, r3, lspull #\pull
  178. str lr, [r0, #-4]!
  179. bgt 15b
  180. CALGN( cmp r2, #0 )
  181. CALGN( bge 11b )
  182. 16: add r1, r1, #(\pull / 8)
  183. b 8b
  184. UNWIND( .fnend )
  185. .endm
  186. backward_copy_shift push=8 pull=24
  187. 17: backward_copy_shift push=16 pull=16
  188. 18: backward_copy_shift push=24 pull=8
  189. ENDPROC(memmove)
  190. EXPORT_SYMBOL(memmove)