memmove.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. 2: PLD( subs r2, r2, #96 )
  51. PLD( pld [r1, #-32] )
  52. PLD( blt 4f )
  53. PLD( pld [r1, #-64] )
  54. PLD( pld [r1, #-96] )
  55. 3: PLD( pld [r1, #-128] )
  56. 4: ldmdb r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
  57. subs r2, r2, #32
  58. stmdb r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
  59. bge 3b
  60. PLD( cmn r2, #96 )
  61. PLD( bge 4b )
  62. 5: ands ip, r2, #28
  63. rsb ip, ip, #32
  64. addne pc, pc, ip @ C is always clear here
  65. b 7f
  66. 6: W(nop)
  67. W(ldr) r3, [r1, #-4]!
  68. W(ldr) r4, [r1, #-4]!
  69. W(ldr) r5, [r1, #-4]!
  70. W(ldr) r6, [r1, #-4]!
  71. W(ldr) r7, [r1, #-4]!
  72. W(ldr) r8, [r1, #-4]!
  73. W(ldr) lr, [r1, #-4]!
  74. add pc, pc, ip
  75. nop
  76. W(nop)
  77. W(str) r3, [r0, #-4]!
  78. W(str) r4, [r0, #-4]!
  79. W(str) r5, [r0, #-4]!
  80. W(str) r6, [r0, #-4]!
  81. W(str) r7, [r0, #-4]!
  82. W(str) r8, [r0, #-4]!
  83. W(str) lr, [r0, #-4]!
  84. CALGN( bcs 2b )
  85. 7: ldmfd sp!, {r5 - r8}
  86. 8: movs r2, r2, lsl #31
  87. ldrneb r3, [r1, #-1]!
  88. ldrcsb r4, [r1, #-1]!
  89. ldrcsb ip, [r1, #-1]
  90. strneb r3, [r0, #-1]!
  91. strcsb r4, [r0, #-1]!
  92. strcsb ip, [r0, #-1]
  93. ldmfd sp!, {r0, r4, pc}
  94. 9: cmp ip, #2
  95. ldrgtb r3, [r1, #-1]!
  96. ldrgeb r4, [r1, #-1]!
  97. ldrb lr, [r1, #-1]!
  98. strgtb r3, [r0, #-1]!
  99. strgeb r4, [r0, #-1]!
  100. subs r2, r2, ip
  101. strb lr, [r0, #-1]!
  102. blt 8b
  103. ands ip, r1, #3
  104. beq 1b
  105. 10: bic r1, r1, #3
  106. cmp ip, #2
  107. ldr r3, [r1, #0]
  108. beq 17f
  109. blt 18f
  110. .macro backward_copy_shift push pull
  111. subs r2, r2, #28
  112. blt 14f
  113. CALGN( ands ip, r0, #31 )
  114. CALGN( sbcnes r4, ip, r2 ) @ C is always set here
  115. CALGN( subcc r2, r2, ip )
  116. CALGN( bcc 15f )
  117. 11: stmfd sp!, {r5 - r9}
  118. PLD( pld [r1, #-4] )
  119. PLD( subs r2, r2, #96 )
  120. PLD( pld [r1, #-32] )
  121. PLD( blt 13f )
  122. PLD( pld [r1, #-64] )
  123. PLD( pld [r1, #-96] )
  124. 12: PLD( pld [r1, #-128] )
  125. 13: ldmdb r1!, {r7, r8, r9, ip}
  126. mov lr, r3, push #\push
  127. subs r2, r2, #32
  128. ldmdb r1!, {r3, r4, r5, r6}
  129. orr lr, lr, ip, pull #\pull
  130. mov ip, ip, push #\push
  131. orr ip, ip, r9, pull #\pull
  132. mov r9, r9, push #\push
  133. orr r9, r9, r8, pull #\pull
  134. mov r8, r8, push #\push
  135. orr r8, r8, r7, pull #\pull
  136. mov r7, r7, push #\push
  137. orr r7, r7, r6, pull #\pull
  138. mov r6, r6, push #\push
  139. orr r6, r6, r5, pull #\pull
  140. mov r5, r5, push #\push
  141. orr r5, r5, r4, pull #\pull
  142. mov r4, r4, push #\push
  143. orr r4, r4, r3, pull #\pull
  144. stmdb r0!, {r4 - r9, ip, lr}
  145. bge 12b
  146. PLD( cmn r2, #96 )
  147. PLD( bge 13b )
  148. ldmfd sp!, {r5 - r9}
  149. 14: ands ip, r2, #28
  150. beq 16f
  151. 15: mov lr, r3, push #\push
  152. ldr r3, [r1, #-4]!
  153. subs ip, ip, #4
  154. orr lr, lr, r3, pull #\pull
  155. str lr, [r0, #-4]!
  156. bgt 15b
  157. CALGN( cmp r2, #0 )
  158. CALGN( bge 11b )
  159. 16: add r1, r1, #(\pull / 8)
  160. b 8b
  161. .endm
  162. backward_copy_shift push=8 pull=24
  163. 17: backward_copy_shift push=16 pull=16
  164. 18: backward_copy_shift push=24 pull=8
  165. ENDPROC(memmove)