memmove.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* memmove.S
  2. * Copyright (C) 2003-2007 Analog Devices Inc., All Rights Reserved.
  3. *
  4. * This file is subject to the terms and conditions of the GNU Library General
  5. * Public License. See the file "COPYING.LIB" in the main directory of this
  6. * archive for more details.
  7. *
  8. * Non-LGPL License also available as part of VisualDSP++
  9. * http://www.analog.com/processors/resources/crosscore/visualDspDevSoftware.html
  10. */
  11. #include <sysdep.h>
  12. /* void *memmove(void *dest, const void *src, size_t n);
  13. * R0 = To Address (dest) (leave unchanged to form result)
  14. * R1 = From Address (src)
  15. * R2 = count (n)
  16. *
  17. * Note: Data may overlap
  18. */
  19. .text
  20. .align 2
  21. .weak _memmove
  22. ENTRY(_memmove)
  23. I1 = P3;
  24. P0 = R0; /* P0 = To address */
  25. P3 = R1; /* P3 = From Address */
  26. P2 = R2; /* P2 = count */
  27. CC = P2 == 0; /* Check zero count*/
  28. IF CC JUMP .Lfinished; /* very unlikely */
  29. CC = R1 < R0 (IU); /* From < To */
  30. IF !CC JUMP .Lno_overlap;
  31. R3 = R1 + R2;
  32. CC = R0 <= R3 (IU); /* (From+len) >= To */
  33. IF CC JUMP .Loverlap;
  34. .Lno_overlap:
  35. R3 = 11;
  36. CC = R2 <= R3;
  37. IF CC JUMP .Lbytes;
  38. R3 = R1 | R0; /* OR addresses together */
  39. R3 <<= 30; /* check bottom two bits */
  40. CC = AZ; /* AZ set if zero.*/
  41. IF !CC JUMP .Lbytes; /* Jump if addrs not aligned.*/
  42. I0 = P3;
  43. P1 = P2 >> 2; /* count = n/4 */
  44. P1 += -1;
  45. R3 = 3;
  46. R2 = R2 & R3; /* remainder */
  47. P2 = R2; /* set remainder */
  48. R1 = [I0++];
  49. #if !defined(__WORKAROUND_AVOID_DAG1)
  50. LSETUP (.Lquad_loop, .Lquad_loop) LC0=P1;
  51. .Lquad_loop: MNOP || [P0++] = R1 || R1 = [I0++];
  52. #else
  53. LSETUP (.Lquad_loop_s, .Lquad_loop_e) LC0=P1;
  54. .Lquad_loop_s: [P0++] = R1;
  55. .Lquad_loop_e: R1 = [I0++];
  56. #endif
  57. [P0++] = R1;
  58. CC = P2 == 0; /* any remaining bytes? */
  59. P3 = I0; /* Ammend P3 to updated ptr. */
  60. IF !CC JUMP .Lbytes;
  61. P3 = I1;
  62. RTS;
  63. .Lbytes: LSETUP (.Lbyte2_s, .Lbyte2_e) LC0=P2;
  64. .Lbyte2_s: R1 = B[P3++](Z);
  65. .Lbyte2_e: B[P0++] = R1;
  66. .Lfinished: P3 = I1;
  67. RTS;
  68. .Loverlap:
  69. P2 += -1;
  70. P0 = P0 + P2;
  71. P3 = P3 + P2;
  72. R1 = B[P3--] (Z);
  73. CC = P2 == 0;
  74. IF CC JUMP .Lno_loop;
  75. #if defined(__WORKAROUND_SPECULATIVE_LOADS)
  76. NOP;
  77. NOP;
  78. #endif
  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
  86. libc_hidden_def (memmove)