memcpy.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * File: arch/blackfin/lib/memcpy.S
  3. * Based on:
  4. * Author:
  5. *
  6. * Created:
  7. * Description: internal version of memcpy(), issued by the compiler
  8. * to copy blocks of data around.
  9. * This is really memmove() - it has to be able to deal with
  10. * possible overlaps, because that ambiguity is when the compiler
  11. * gives up and calls a function. We have our own, internal version
  12. * so that we get something we trust, even if the user has redefined
  13. * the normal symbol.
  14. *
  15. * Modified:
  16. * Copyright 2004-2006 Analog Devices Inc.
  17. *
  18. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  19. *
  20. * This program is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation; either version 2 of the License, or
  23. * (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, see the file COPYING, or write
  32. * to the Free Software Foundation, Inc.,
  33. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  34. */
  35. #include <linux/linkage.h>
  36. /* void *memcpy(void *dest, const void *src, size_t n);
  37. * R0 = To Address (dest) (leave unchanged to form result)
  38. * R1 = From Address (src)
  39. * R2 = count
  40. *
  41. * Note: Favours word alignment
  42. */
  43. #ifdef CONFIG_MEMCPY_L1
  44. .section .l1.text
  45. #else
  46. .text
  47. #endif
  48. .align 2
  49. ENTRY(_memcpy)
  50. CC = R2 <= 0; /* length not positive? */
  51. IF CC JUMP .L_P1L2147483647; /* Nothing to do */
  52. P0 = R0 ; /* dst*/
  53. P1 = R1 ; /* src*/
  54. P2 = R2 ; /* length */
  55. /* check for overlapping data */
  56. CC = R1 < R0; /* src < dst */
  57. IF !CC JUMP .Lno_overlap;
  58. R3 = R1 + R2;
  59. CC = R0 < R3; /* and dst < src+len */
  60. IF CC JUMP .Lhas_overlap;
  61. .Lno_overlap:
  62. /* Check for aligned data.*/
  63. R3 = R1 | R0;
  64. R1 = 0x3;
  65. R3 = R3 & R1;
  66. CC = R3; /* low bits set on either address? */
  67. IF CC JUMP .Lnot_aligned;
  68. /* Both addresses are word-aligned, so we can copy
  69. at least part of the data using word copies.*/
  70. P2 = P2 >> 2;
  71. CC = P2 <= 2;
  72. IF !CC JUMP .Lmore_than_seven;
  73. /* less than eight bytes... */
  74. P2 = R2;
  75. LSETUP(.Lthree_start, .Lthree_end) LC0=P2;
  76. .Lthree_start:
  77. R3 = B[P1++] (X);
  78. .Lthree_end:
  79. B[P0++] = R3;
  80. RTS;
  81. .Lmore_than_seven:
  82. /* There's at least eight bytes to copy. */
  83. P2 += -1; /* because we unroll one iteration */
  84. LSETUP(.Lword_loops, .Lword_loope) LC0=P2;
  85. I1 = P1;
  86. R3 = [I1++];
  87. #if ANOMALY_05000202
  88. .Lword_loops:
  89. [P0++] = R3;
  90. .Lword_loope:
  91. R3 = [I1++];
  92. #else
  93. .Lword_loops:
  94. .Lword_loope:
  95. MNOP || [P0++] = R3 || R3 = [I1++];
  96. #endif
  97. [P0++] = R3;
  98. /* Any remaining bytes to copy? */
  99. R3 = 0x3;
  100. R3 = R2 & R3;
  101. CC = R3 == 0;
  102. P1 = I1; /* in case there's something left, */
  103. IF !CC JUMP .Lbytes_left;
  104. RTS;
  105. .Lbytes_left: P2 = R3;
  106. .Lnot_aligned:
  107. /* From here, we're copying byte-by-byte. */
  108. LSETUP (.Lbyte_start, .Lbyte_end) LC0=P2;
  109. .Lbyte_start:
  110. R1 = B[P1++] (X);
  111. .Lbyte_end:
  112. B[P0++] = R1;
  113. .L_P1L2147483647:
  114. RTS;
  115. .Lhas_overlap:
  116. /* Need to reverse the copying, because the
  117. * dst would clobber the src.
  118. * Don't bother to work out alignment for
  119. * the reverse case.
  120. */
  121. P0 = P0 + P2;
  122. P0 += -1;
  123. P1 = P1 + P2;
  124. P1 += -1;
  125. LSETUP(.Lover_start, .Lover_end) LC0=P2;
  126. .Lover_start:
  127. R1 = B[P1--] (X);
  128. .Lover_end:
  129. B[P0--] = R1;
  130. RTS;
  131. ENDPROC(_memcpy)