memmove.s 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. TEXT memmove(SB), $0
  2. MOVL n+8(FP), R0 /* count */
  3. BEQ return
  4. BGT ok
  5. MOVL 0, R0
  6. ok:
  7. MOVL s1+0(FP), A2 /* dest pointer */
  8. MOVL s2+4(FP), A1 /* source pointer */
  9. CMPL A2,A1
  10. BHI back
  11. /*
  12. * byte-at-a-time foreward copy to
  13. * get source (A1) alligned.
  14. */
  15. f1:
  16. MOVL A1, R1
  17. ANDL $3, R1
  18. BEQ f2
  19. SUBL $1, R0
  20. BLT return
  21. MOVB (A1)+, (A2)+
  22. BRA f1
  23. /*
  24. * check that dest is alligned
  25. * if not, just go byte-at-a-time
  26. */
  27. f2:
  28. MOVL A2, R1
  29. ANDL $3, R1
  30. BEQ f3
  31. SUBL $1, R0
  32. BLT return
  33. BRA f5
  34. /*
  35. * quad-long-at-a-time forward copy
  36. */
  37. f3:
  38. SUBL $16, R0
  39. BLT f4
  40. MOVL (A1)+, (A2)+
  41. MOVL (A1)+, (A2)+
  42. MOVL (A1)+, (A2)+
  43. MOVL (A1)+, (A2)+
  44. BRA f3
  45. /*
  46. * cleanup byte-at-a-time
  47. */
  48. f4:
  49. ADDL $15, R0
  50. BLT return
  51. f5:
  52. MOVB (A1)+, (A2)+
  53. SUBL $1, R0
  54. BGE f5
  55. BRA return
  56. return:
  57. MOVL s1+0(FP),R0
  58. RTS
  59. /*
  60. * everything the same, but
  61. * copy backwards
  62. */
  63. back:
  64. ADDL R0, A1
  65. ADDL R0, A2
  66. /*
  67. * byte-at-a-time backward copy to
  68. * get source (A1) alligned.
  69. */
  70. b1:
  71. MOVL A1, R1
  72. ANDL $3, R1
  73. BEQ b2
  74. SUBL $1, R0
  75. BLT return
  76. MOVB -(A1), -(A2)
  77. BRA b1
  78. /*
  79. * check that dest is alligned
  80. * if not, just go byte-at-a-time
  81. */
  82. b2:
  83. MOVL A2, R1
  84. ANDL $3, R1
  85. BEQ b3
  86. SUBL $1, R0
  87. BLT return
  88. BRA b5
  89. /*
  90. * quad-long-at-a-time backward copy
  91. */
  92. b3:
  93. SUBL $16, R0
  94. BLT b4
  95. MOVL -(A1), -(A2)
  96. MOVL -(A1), -(A2)
  97. MOVL -(A1), -(A2)
  98. MOVL -(A1), -(A2)
  99. BRA b3
  100. /*
  101. * cleanup byte-at-a-time backward
  102. */
  103. b4:
  104. ADDL $15, R0
  105. BLT return
  106. b5:
  107. MOVB -(A1), -(A2)
  108. SUBL $1, R0
  109. BGE b5
  110. BRA return