memmove.S 4.2 KB

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