memmove.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * linux/arch/arm/lib/memmove.S
  4. *
  5. * Author: Nicolas Pitre
  6. * Created: Sep 28, 2005
  7. * Copyright: (C) MontaVista Software Inc.
  8. */
  9. #include <linux/linkage.h>
  10. #include <asm/assembler.h>
  11. #include <asm/unwind.h>
  12. .text
  13. /*
  14. * Prototype: void *memmove(void *dest, const void *src, size_t n);
  15. *
  16. * Note:
  17. *
  18. * If the memory regions don't overlap, we simply branch to memcpy which is
  19. * normally a bit faster. Otherwise the copy is done going downwards. This
  20. * is a transposition of the code from copy_template.S but with the copy
  21. * occurring in the opposite direction.
  22. */
  23. ENTRY(__memmove)
  24. WEAK(memmove)
  25. UNWIND( .fnstart )
  26. subs ip, r0, r1
  27. cmphi r2, ip
  28. bls __memcpy
  29. UNWIND( .fnend )
  30. UNWIND( .fnstart )
  31. UNWIND( .save {r0, r4, fpreg, lr} )
  32. stmfd sp!, {r0, r4, UNWIND(fpreg,) lr}
  33. UNWIND( .setfp fpreg, sp )
  34. UNWIND( mov fpreg, sp )
  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, r6, r8, r9}
  46. blt 5f
  47. CALGN( ands ip, r0, #31 )
  48. CALGN( sbcsne r4, ip, r2 ) @ C is always set here
  49. CALGN( bcs 2f )
  50. CALGN( adr r4, 6f )
  51. CALGN( subs r2, r2, ip ) @ C is set here
  52. CALGN( rsb ip, ip, #32 )
  53. CALGN( add pc, r4, ip )
  54. PLD( pld [r1, #-4] )
  55. 2: PLD( subs r2, r2, #96 )
  56. PLD( pld [r1, #-32] )
  57. PLD( blt 4f )
  58. PLD( pld [r1, #-64] )
  59. PLD( pld [r1, #-96] )
  60. 3: PLD( pld [r1, #-128] )
  61. 4: ldmdb r1!, {r3, r4, r5, r6, r8, r9, ip, lr}
  62. subs r2, r2, #32
  63. stmdb r0!, {r3, r4, r5, r6, r8, r9, ip, lr}
  64. bge 3b
  65. PLD( cmn r2, #96 )
  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) r8, [r1, #-4]!
  77. W(ldr) r9, [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) r8, [r0, #-4]!
  87. W(str) r9, [r0, #-4]!
  88. W(str) lr, [r0, #-4]!
  89. CALGN( bcs 2b )
  90. 7: ldmfd sp!, {r5, r6, r8, r9}
  91. 8: movs r2, r2, lsl #31
  92. ldrbne r3, [r1, #-1]!
  93. ldrbcs r4, [r1, #-1]!
  94. ldrbcs ip, [r1, #-1]
  95. strbne r3, [r0, #-1]!
  96. strbcs r4, [r0, #-1]!
  97. strbcs ip, [r0, #-1]
  98. ldmfd sp!, {r0, r4, UNWIND(fpreg,) pc}
  99. 9: cmp ip, #2
  100. ldrbgt r3, [r1, #-1]!
  101. ldrbge r4, [r1, #-1]!
  102. ldrb lr, [r1, #-1]!
  103. strbgt r3, [r0, #-1]!
  104. strbge 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( sbcsne r4, ip, r2 ) @ C is always set here
  120. CALGN( subcc r2, r2, ip )
  121. CALGN( bcc 15f )
  122. 11: stmfd sp!, {r5, r6, r8 - r10}
  123. PLD( pld [r1, #-4] )
  124. PLD( subs r2, r2, #96 )
  125. PLD( pld [r1, #-32] )
  126. PLD( blt 13f )
  127. PLD( pld [r1, #-64] )
  128. PLD( pld [r1, #-96] )
  129. 12: PLD( pld [r1, #-128] )
  130. 13: ldmdb r1!, {r8, r9, r10, ip}
  131. mov lr, r3, lspush #\push
  132. subs r2, r2, #32
  133. ldmdb r1!, {r3, r4, r5, r6}
  134. orr lr, lr, ip, lspull #\pull
  135. mov ip, ip, lspush #\push
  136. orr ip, ip, r10, lspull #\pull
  137. mov r10, r10, lspush #\push
  138. orr r10, r10, r9, lspull #\pull
  139. mov r9, r9, lspush #\push
  140. orr r9, r9, r8, lspull #\pull
  141. mov r8, r8, lspush #\push
  142. orr r8, r8, r6, lspull #\pull
  143. mov r6, r6, lspush #\push
  144. orr r6, r6, r5, lspull #\pull
  145. mov r5, r5, lspush #\push
  146. orr r5, r5, r4, lspull #\pull
  147. mov r4, r4, lspush #\push
  148. orr r4, r4, r3, lspull #\pull
  149. stmdb r0!, {r4 - r6, r8 - r10, ip, lr}
  150. bge 12b
  151. PLD( cmn r2, #96 )
  152. PLD( bge 13b )
  153. ldmfd sp!, {r5, r6, r8 - r10}
  154. 14: ands ip, r2, #28
  155. beq 16f
  156. 15: mov lr, r3, lspush #\push
  157. ldr r3, [r1, #-4]!
  158. subs ip, ip, #4
  159. orr lr, lr, r3, lspull #\pull
  160. str lr, [r0, #-4]!
  161. bgt 15b
  162. CALGN( cmp r2, #0 )
  163. CALGN( bge 11b )
  164. 16: add r1, r1, #(\pull / 8)
  165. b 8b
  166. .endm
  167. backward_copy_shift push=8 pull=24
  168. 17: backward_copy_shift push=16 pull=16
  169. 18: backward_copy_shift push=24 pull=8
  170. UNWIND( .fnend )
  171. ENDPROC(memmove)
  172. ENDPROC(__memmove)