memmove.S 4.8 KB

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