memcpy.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * File: memcpy.S
  3. *
  4. * Copyright 2004-2007 Analog Devices Inc.
  5. * Enter bugs at http://blackfin.uclinux.org/
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, see the file COPYING, or write
  19. * to the Free Software Foundation, Inc.,
  20. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. .align 2
  23. .globl _memcpy_ASM;
  24. .type _memcpy_ASM, STT_FUNC;
  25. _memcpy_ASM:
  26. CC = R2 <= 0; /* length not positive?*/
  27. IF CC JUMP .L_P1L2147483647; /* Nothing to do */
  28. P0 = R0 ; /* dst*/
  29. P1 = R1 ; /* src*/
  30. P2 = R2 ; /* length */
  31. /* check for overlapping data */
  32. CC = R1 < R0; /* src < dst */
  33. IF !CC JUMP .Lno_overlap;
  34. R3 = R1 + R2;
  35. CC = R0 < R3; /* and dst < src+len */
  36. IF CC JUMP .Lhas_overlap;
  37. .Lno_overlap:
  38. /* Check for aligned data.*/
  39. R3 = R1 | R0;
  40. R0 = 0x3;
  41. R3 = R3 & R0;
  42. CC = R3; /* low bits set on either address? */
  43. IF CC JUMP .Lnot_aligned;
  44. /* Both addresses are word-aligned, so we can copy
  45. at least part of the data using word copies.*/
  46. P2 = P2 >> 2;
  47. CC = P2 <= 2;
  48. IF !CC JUMP .Lmore_than_seven;
  49. /* less than eight bytes... */
  50. P2 = R2;
  51. LSETUP(.Lthree_start, .Lthree_end) LC0=P2;
  52. R0 = R1; /* setup src address for return */
  53. .Lthree_start:
  54. R3 = B[P1++] (X);
  55. .Lthree_end:
  56. B[P0++] = R3;
  57. RTS;
  58. .Lmore_than_seven:
  59. /* There's at least eight bytes to copy. */
  60. P2 += -1; /* because we unroll one iteration */
  61. LSETUP(.Lword_loop, .Lword_loop) LC0=P2;
  62. R0 = R1;
  63. I1 = P1;
  64. R3 = [I1++];
  65. .Lword_loop:
  66. MNOP || [P0++] = R3 || R3 = [I1++];
  67. [P0++] = R3;
  68. /* Any remaining bytes to copy? */
  69. R3 = 0x3;
  70. R3 = R2 & R3;
  71. CC = R3 == 0;
  72. P1 = I1; /* in case there's something left, */
  73. IF !CC JUMP .Lbytes_left;
  74. RTS;
  75. .Lbytes_left: P2 = R3;
  76. .Lnot_aligned:
  77. /* From here, we're copying byte-by-byte. */
  78. LSETUP (.Lbyte_start , .Lbyte_end) LC0=P2;
  79. R0 = R1; /* Save src address for return */
  80. .Lbyte_start:
  81. R1 = B[P1++] (X);
  82. .Lbyte_end:
  83. B[P0++] = R1;
  84. .L_P1L2147483647:
  85. RTS;
  86. .Lhas_overlap:
  87. /* Need to reverse the copying, because the
  88. * dst would clobber the src.
  89. * Don't bother to work out alignment for
  90. * the reverse case.
  91. */
  92. R0 = R1; /* save src for later. */
  93. P0 = P0 + P2;
  94. P0 += -1;
  95. P1 = P1 + P2;
  96. P1 += -1;
  97. LSETUP(.Lover_start, .Lover_end) LC0=P2;
  98. .Lover_start:
  99. R1 = B[P1--] (X);
  100. .Lover_end:
  101. B[P0--] = R1;
  102. RTS;
  103. .size _memcpy_ASM, .-_memcpy_ASM