memcpy.S 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2016 Andes Technology, Inc.
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. */
  5. #include <sysdep.h>
  6. !==========================================================
  7. ! void *memcpy(void *dst, const void *src, int n);
  8. !
  9. ! dst: $r0
  10. ! src: $r1
  11. ! n : $r2
  12. ! ret: $r0 - pointer to the memory area dst.
  13. !==========================================================
  14. .weak memcpy
  15. ENTRY(memcpy)
  16. move $r5, $r0
  17. beq $r0, $r1, .Lquit_memcpy
  18. beqz $r2, .Lquit_memcpy
  19. srli $r3, $r2, #5 ! check if len < cache-line size 32
  20. beqz $r3, .Lword_copy_entry
  21. andi $r4, $r0, #0x3 ! check byte-align
  22. beqz $r4, .Lunalign_word_copy_entry
  23. addi $r4, $r4, #-4
  24. abs $r4, $r4 ! check how many un-align byte to copy
  25. sub $r2, $r2, $r4 ! update $R2
  26. .Lunalign_byte_copy:
  27. lbi.bi $r3, [$r1], #1
  28. addi $r4, $r4, #-1
  29. sbi.bi $r3, [$r0], #1
  30. bnez $r4, .Lunalign_byte_copy
  31. beqz $r2, .Lquit_memcpy
  32. .Lunalign_word_copy_entry:
  33. andi $r3, $r0, 0x1f ! check cache-line unaligncount
  34. beqz $r3, .Lcache_copy
  35. addi $r3, $r3, #-32
  36. abs $r3, $r3
  37. sub $r2, $r2, $r3 ! update $R2
  38. .Lunalign_word_copy:
  39. lmw.bim $r4, [$r1], $r4
  40. addi $r3, $r3, #-4
  41. smw.bim $r4, [$r0], $r4
  42. bnez $r3, .Lunalign_word_copy
  43. beqz $r2, .Lquit_memcpy
  44. addi $r3, $r2, #-32 ! to check $r2 < cache_line, than go to .Lword_copy
  45. bltz $r3, .Lword_copy_entry
  46. .Lcache_copy:
  47. srli $r3, $r2, #5
  48. beqz $r3, .Lword_copy_entry
  49. pushm $r6, $r13
  50. .L3:
  51. lmw.bim $r6, [$r1], $r13
  52. addi $r3, $r3, #-1
  53. smw.bim $r6, [$r0], $r13
  54. bnez $r3, .L3
  55. popm $r6, $r13
  56. .Lword_copy_entry:
  57. andi $r2, $r2, #31
  58. beqz $r2, .Lquit_memcpy
  59. srli $r3, $r2, #2
  60. beqz $r3, .Lbyte_copy
  61. .Lword_copy:
  62. lmw.bim $r4, [$r1], $r4
  63. addi $r3, $r3, #-1
  64. smw.bim $r4, [$r0], $r4
  65. bnez $r3, .Lword_copy
  66. andi $r2, $r2, #3
  67. beqz $r2, .Lquit_memcpy
  68. .Lbyte_copy:
  69. lbi.bi $r3, [$r1], #1
  70. addi $r2, $r2, #-1
  71. sbi.bi $r3, [$r0], #1
  72. bnez $r2, .Lbyte_copy
  73. .Lquit_memcpy:
  74. move $r0, $r5
  75. ret
  76. END(memcpy)
  77. libc_hidden_def(memcpy)