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