memmove.s 1.5 KB

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