memmove.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* MN10300 Optimised simple memory to memory copy, with support for overlapping
  2. * regions
  3. *
  4. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public Licence
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the Licence, or (at your option) any later version.
  11. */
  12. #include <asm/cache.h>
  13. .section .text
  14. .balign L1_CACHE_BYTES
  15. ###############################################################################
  16. #
  17. # void *memmove(void *dst, const void *src, size_t n)
  18. #
  19. ###############################################################################
  20. .globl memmove
  21. .type memmove,@function
  22. memmove:
  23. # fall back to memcpy if dst < src to work bottom up
  24. cmp d1,d0
  25. bcs memmove_memcpy
  26. # work top down
  27. movm [d2,d3],(sp)
  28. mov d0,(12,sp)
  29. mov d1,(16,sp)
  30. mov (20,sp),d2 # count
  31. add d0,d2,a0 # dst end
  32. add d1,d2,a1 # src end
  33. mov d0,e3 # the return value
  34. cmp +0,d2
  35. beq memmove_done # return if zero-length copy
  36. # see if the three parameters are all four-byte aligned
  37. or d0,d1,d3
  38. or d2,d3
  39. and +3,d3
  40. bne memmove_1 # jump if not
  41. # we want to transfer as much as we can in chunks of 32 bytes
  42. add -4,a1
  43. cmp +31,d2
  44. bls memmove_4_remainder # 4-byte aligned remainder
  45. add -32,d2
  46. mov +32,d3
  47. memmove_4_loop:
  48. mov (a1),d0
  49. sub_sub +4,a1,+4,a0
  50. mov d0,(a0)
  51. mov (a1),d1
  52. sub_sub +4,a1,+4,a0
  53. mov d1,(a0)
  54. mov (a1),d0
  55. sub_sub +4,a1,+4,a0
  56. mov d0,(a0)
  57. mov (a1),d1
  58. sub_sub +4,a1,+4,a0
  59. mov d1,(a0)
  60. mov (a1),d0
  61. sub_sub +4,a1,+4,a0
  62. mov d0,(a0)
  63. mov (a1),d1
  64. sub_sub +4,a1,+4,a0
  65. mov d1,(a0)
  66. mov (a1),d0
  67. sub_sub +4,a1,+4,a0
  68. mov d0,(a0)
  69. mov (a1),d1
  70. sub_sub +4,a1,+4,a0
  71. mov d1,(a0)
  72. sub d3,d2
  73. bcc memmove_4_loop
  74. add d3,d2
  75. beq memmove_4_no_remainder
  76. memmove_4_remainder:
  77. # cut 4-7 words down to 0-3
  78. cmp +16,d2
  79. bcs memmove_4_three_or_fewer_words
  80. mov (a1),d0
  81. sub_sub +4,a1,+4,a0
  82. mov d0,(a0)
  83. mov (a1),d1
  84. sub_sub +4,a1,+4,a0
  85. mov d1,(a0)
  86. mov (a1),e0
  87. sub_sub +4,a1,+4,a0
  88. mov e0,(a0)
  89. mov (a1),e1
  90. sub_sub +4,a1,+4,a0
  91. mov e1,(a0)
  92. add -16,d2
  93. beq memmove_4_no_remainder
  94. # copy the remaining 1, 2 or 3 words
  95. memmove_4_three_or_fewer_words:
  96. cmp +8,d2
  97. bcs memmove_4_one_word
  98. beq memmove_4_two_words
  99. mov (a1),d0
  100. sub_sub +4,a1,+4,a0
  101. mov d0,(a0)
  102. memmove_4_two_words:
  103. mov (a1),d0
  104. sub_sub +4,a1,+4,a0
  105. mov d0,(a0)
  106. memmove_4_one_word:
  107. mov (a1),d0
  108. sub_sub +4,a1,+4,a0
  109. mov d0,(a0)
  110. memmove_4_no_remainder:
  111. # check we copied the correct amount
  112. # TODO: REMOVE CHECK
  113. sub e3,a0,d2
  114. beq memmove_done
  115. break
  116. break
  117. break
  118. memmove_done:
  119. mov e3,a0
  120. ret [d2,d3],8
  121. # handle misaligned copying
  122. memmove_1:
  123. add -1,a1
  124. add -1,d2
  125. mov +1,d3
  126. setlb # setlb requires the next insns
  127. # to occupy exactly 4 bytes
  128. sub d3,d2
  129. movbu (a1),d0
  130. sub_sub d3,a1,d3,a0
  131. movbu d0,(a0)
  132. lcc
  133. mov e3,a0
  134. ret [d2,d3],8
  135. memmove_memcpy:
  136. jmp memcpy
  137. memmove_end:
  138. .size memmove, memmove_end-memmove