memmove.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * File: memmove.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. /*
  24. * C Library function MEMMOVE
  25. * R0 = To Address (leave unchanged to form result)
  26. * R1 = From Address
  27. * R2 = count
  28. * Data may overlap
  29. */
  30. .globl _memmove;
  31. .type _memmove, STT_FUNC;
  32. _memmove:
  33. I1 = P3;
  34. P0 = R0; /* P0 = To address */
  35. P3 = R1; /* P3 = From Address */
  36. P2 = R2 ; /* P2 = count */
  37. CC = P2 == 0; /* Check zero count*/
  38. IF CC JUMP .Lfinished; /* very unlikely */
  39. CC = R1 < R0 (IU); /* From < To */
  40. IF !CC JUMP .Lno_overlap;
  41. R3 = R1 + R2;
  42. CC = R0 <= R3 (IU); /* (From+len) >= To */
  43. IF CC JUMP .Loverlap;
  44. .Lno_overlap:
  45. R3 = 11;
  46. CC = R2 <= R3;
  47. IF CC JUMP .Lbytes;
  48. R3 = R1 | R0; /* OR addresses together */
  49. R3 <<= 30; /* check bottom two bits */
  50. CC = AZ; /* AZ set if zero.*/
  51. IF !CC JUMP .Lbytes ; /* Jump if addrs not aligned.*/
  52. I0 = P3;
  53. P1 = P2 >> 2; /* count = n/4 */
  54. P1 += -1;
  55. R3 = 3;
  56. R2 = R2 & R3; /* remainder */
  57. P2 = R2; /* set remainder */
  58. R1 = [I0++];
  59. LSETUP (.Lquad_loop , .Lquad_loop) LC0=P1;
  60. .Lquad_loop: MNOP || [P0++] = R1 || R1 = [I0++];
  61. [P0++] = R1;
  62. CC = P2 == 0; /* any remaining bytes? */
  63. P3 = I0; /* Ammend P3 to updated ptr. */
  64. IF !CC JUMP .Lbytes;
  65. P3 = I1;
  66. RTS;
  67. .Lbytes: LSETUP (.Lbyte2_s , .Lbyte2_e) LC0=P2;
  68. .Lbyte2_s: R1 = B[P3++](Z);
  69. .Lbyte2_e: B[P0++] = R1;
  70. .Lfinished: P3 = I1;
  71. RTS;
  72. .Loverlap:
  73. P2 += -1;
  74. P0 = P0 + P2;
  75. P3 = P3 + P2;
  76. R1 = B[P3--] (Z);
  77. CC = P2 == 0;
  78. IF CC JUMP .Lno_loop;
  79. LSETUP (.Lol_s, .Lol_e) LC0 = P2;
  80. .Lol_s: B[P0--] = R1;
  81. .Lol_e: R1 = B[P3--] (Z);
  82. .Lno_loop: B[P0] = R1;
  83. P3 = I1;
  84. RTS;
  85. .size _memmove, .-_memmove