memmove.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
  3. #include <linux/linkage.h>
  4. #include "sysdep.h"
  5. .weak memmove
  6. ENTRY(__memmove)
  7. ENTRY(memmove)
  8. subu r3, r0, r1
  9. cmphs r3, r2
  10. bt memcpy
  11. mov r12, r0
  12. addu r0, r0, r2
  13. addu r1, r1, r2
  14. /* Test if len less than 4 bytes. */
  15. cmplti r2, 4
  16. bt .L_copy_by_byte
  17. andi r13, r0, 3
  18. /* Test if dest is not 4 bytes aligned. */
  19. bnez r13, .L_dest_not_aligned
  20. /* Hardware can handle unaligned access directly. */
  21. .L_dest_aligned:
  22. /* If dest is aligned, then copy. */
  23. zext r18, r2, 31, 4
  24. /* Test if len less than 16 bytes. */
  25. bez r18, .L_len_less_16bytes
  26. movi r19, 0
  27. /* len > 16 bytes */
  28. LABLE_ALIGN
  29. .L_len_larger_16bytes:
  30. subi r1, 16
  31. subi r0, 16
  32. #if defined(__CK860__)
  33. ldw r3, (r1, 12)
  34. stw r3, (r0, 12)
  35. ldw r3, (r1, 8)
  36. stw r3, (r0, 8)
  37. ldw r3, (r1, 4)
  38. stw r3, (r0, 4)
  39. ldw r3, (r1, 0)
  40. stw r3, (r0, 0)
  41. #else
  42. ldw r20, (r1, 0)
  43. ldw r21, (r1, 4)
  44. ldw r22, (r1, 8)
  45. ldw r23, (r1, 12)
  46. stw r20, (r0, 0)
  47. stw r21, (r0, 4)
  48. stw r22, (r0, 8)
  49. stw r23, (r0, 12)
  50. PRE_BNEZAD (r18)
  51. #endif
  52. BNEZAD (r18, .L_len_larger_16bytes)
  53. .L_len_less_16bytes:
  54. zext r18, r2, 3, 2
  55. bez r18, .L_copy_by_byte
  56. .L_len_less_16bytes_loop:
  57. subi r1, 4
  58. subi r0, 4
  59. ldw r3, (r1, 0)
  60. PRE_BNEZAD (r18)
  61. stw r3, (r0, 0)
  62. BNEZAD (r18, .L_len_less_16bytes_loop)
  63. /* Test if len less than 4 bytes. */
  64. .L_copy_by_byte:
  65. zext r18, r2, 1, 0
  66. bez r18, .L_return
  67. .L_copy_by_byte_loop:
  68. subi r1, 1
  69. subi r0, 1
  70. ldb r3, (r1, 0)
  71. PRE_BNEZAD (r18)
  72. stb r3, (r0, 0)
  73. BNEZAD (r18, .L_copy_by_byte_loop)
  74. .L_return:
  75. mov r0, r12
  76. rts
  77. /* If dest is not aligned, just copy some bytes makes the dest
  78. align. */
  79. .L_dest_not_aligned:
  80. sub r2, r13
  81. .L_dest_not_aligned_loop:
  82. subi r1, 1
  83. subi r0, 1
  84. /* Makes the dest align. */
  85. ldb r3, (r1, 0)
  86. PRE_BNEZAD (r13)
  87. stb r3, (r0, 0)
  88. BNEZAD (r13, .L_dest_not_aligned_loop)
  89. cmplti r2, 4
  90. bt .L_copy_by_byte
  91. /* Check whether the src is aligned. */
  92. jbr .L_dest_aligned
  93. ENDPROC(memmove)
  94. ENDPROC(__memmove)