Alternative library and kernel for add-in development on fx-9860G and fx-CG50 under Linux.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

126 lines
1.8 KiB

  1. .global _memcpy
  2. .text
  3. _memcpy:
  4. tst r6, r6
  5. bt .zero
  6. mov r4, r3
  7. mov #3, r2
  8. /* When copying less than 64 bytes, use the naive method */
  9. mov #64, r0
  10. cmp/ge r6, r0
  11. bt _naive_memcpy
  12. _memcpy_align_dst:
  13. /* 4-align the destination */
  14. mov.b @r5+, r0
  15. mov.b r0, @r4
  16. add #1, r4
  17. tst r2, r4
  18. bf/s _memcpy_align_dst
  19. dt r6
  20. /* If source is 4-aligned, use mov.l */
  21. tst r2, r5
  22. bt/s .aligned4_32
  23. mov #4, r2
  24. /* If unaligned but SH4, use movua.l */
  25. mov.l .gint, r0
  26. mov.l @r0, r0
  27. tst #1, r0
  28. bt .unaligned4
  29. /* If source is 2-aligned, use mov.w */
  30. mov r5, r0
  31. tst #1, r0
  32. bt .aligned2
  33. /* Otherwise use a naive copy */
  34. bra _naive_memcpy
  35. nop
  36. .aligned4_32:
  37. mov #36, r2
  38. /* Copy 32 bytes at a time until at most 32 bytes are left */
  39. mov.l @r5+, r0
  40. mov.l @r5+, r1
  41. mov.l @r5+, r7
  42. mov.l r0, @r4
  43. mov.l r1, @(4,r4)
  44. mov.l r7, @(8,r4)
  45. mov.l @r5+, r0
  46. mov.l @r5+, r1
  47. mov.l @r5+, r7
  48. mov.l r0, @(12,r4)
  49. mov.l r1, @(16,r4)
  50. mov.l r7, @(20,r4)
  51. mov.l @r5+, r0
  52. mov.l @r5+, r1
  53. add #-32, r6
  54. mov.l r0, @(24,r4)
  55. mov.l r1, @(28,r4)
  56. cmp/ge r6, r2
  57. bf/s .aligned4_32
  58. add #32, r4
  59. .aligned4_4:
  60. mov #4, r2
  61. /* Copy 4 bytes at a time until at most 4 bytes are left */
  62. mov.l @r5+, r0
  63. mov.l r0, @r4
  64. add #-4, r6
  65. cmp/ge r6, r2
  66. bf/s .aligned4_4
  67. add #4, r4
  68. bra _naive_memcpy
  69. nop
  70. .unaligned4:
  71. /* Copy 4 bytes but read with movua.l since source is unaligned */
  72. movua.l @r5+, r0
  73. mov.l r0, @r4
  74. add #-4, r6
  75. cmp/ge r6, r2
  76. bf/s .unaligned4
  77. add #4, r4
  78. bra _naive_memcpy
  79. nop
  80. .aligned2:
  81. mov.w @r5+, r0
  82. mov.w r0, @r4
  83. mov.w @r5+, r0
  84. mov.w r0, @(2,r4)
  85. add #-4, r6
  86. cmp/ge r6, r2
  87. bf/s .aligned2
  88. add #4, r4
  89. bra _naive_memcpy
  90. nop
  91. _naive_memcpy:
  92. mov.b @r5+, r0
  93. dt r6
  94. mov.b r0, @r4
  95. bf/s _naive_memcpy
  96. add #1, r4
  97. rts
  98. mov r3, r0
  99. .zero:
  100. rts
  101. mov r4, r0
  102. .align 4
  103. .gint:
  104. .long _gint