memmove.S 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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(__CSKY_VDSPV2__)
  33. vldx.8 vr0, (r1), r19
  34. PRE_BNEZAD (r18)
  35. vstx.8 vr0, (r0), r19
  36. #elif defined(__CK860__)
  37. ldw r3, (r1, 12)
  38. stw r3, (r0, 12)
  39. ldw r3, (r1, 8)
  40. stw r3, (r0, 8)
  41. ldw r3, (r1, 4)
  42. stw r3, (r0, 4)
  43. ldw r3, (r1, 0)
  44. stw r3, (r0, 0)
  45. #else
  46. ldw r20, (r1, 0)
  47. ldw r21, (r1, 4)
  48. ldw r22, (r1, 8)
  49. ldw r23, (r1, 12)
  50. stw r20, (r0, 0)
  51. stw r21, (r0, 4)
  52. stw r22, (r0, 8)
  53. stw r23, (r0, 12)
  54. PRE_BNEZAD (r18)
  55. #endif
  56. BNEZAD (r18, .L_len_larger_16bytes)
  57. .L_len_less_16bytes:
  58. zext r18, r2, 3, 2
  59. bez r18, .L_copy_by_byte
  60. .L_len_less_16bytes_loop:
  61. subi r1, 4
  62. subi r0, 4
  63. ldw r3, (r1, 0)
  64. PRE_BNEZAD (r18)
  65. stw r3, (r0, 0)
  66. BNEZAD (r18, .L_len_less_16bytes_loop)
  67. /* Test if len less than 4 bytes. */
  68. .L_copy_by_byte:
  69. zext r18, r2, 1, 0
  70. bez r18, .L_return
  71. .L_copy_by_byte_loop:
  72. subi r1, 1
  73. subi r0, 1
  74. ldb r3, (r1, 0)
  75. PRE_BNEZAD (r18)
  76. stb r3, (r0, 0)
  77. BNEZAD (r18, .L_copy_by_byte_loop)
  78. .L_return:
  79. mov r0, r12
  80. rts
  81. /* If dest is not aligned, just copy some bytes makes the dest
  82. align. */
  83. .L_dest_not_aligned:
  84. sub r2, r13
  85. .L_dest_not_aligned_loop:
  86. subi r1, 1
  87. subi r0, 1
  88. /* Makes the dest align. */
  89. ldb r3, (r1, 0)
  90. PRE_BNEZAD (r13)
  91. stb r3, (r0, 0)
  92. BNEZAD (r13, .L_dest_not_aligned_loop)
  93. cmplti r2, 4
  94. bt .L_copy_by_byte
  95. /* Check whether the src is aligned. */
  96. jbr .L_dest_aligned
  97. ENDPROC(memmove)
  98. ENDPROC(__memmove)