memmove.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. /* We have to bypass the libc-symbols.h machinery to make sure we get
  22. a weak symbol for memcpy (some crummy gcc tests want to redefine
  23. it). */
  24. .global ___GI_memmove
  25. .type ___GI_memmove, STT_FUNC
  26. ___GI_memmove:
  27. I1 = P3;
  28. P0 = R0; /* P0 = To address */
  29. P3 = R1; /* P3 = From Address */
  30. P2 = R2; /* P2 = count */
  31. CC = P2 == 0; /* Check zero count*/
  32. IF CC JUMP .Lfinished; /* very unlikely */
  33. CC = R1 < R0 (IU); /* From < To */
  34. IF !CC JUMP .Lno_overlap;
  35. R3 = R1 + R2;
  36. CC = R0 <= R3 (IU); /* (From+len) >= To */
  37. IF CC JUMP .Loverlap;
  38. .Lno_overlap:
  39. R3 = 11;
  40. CC = R2 <= R3;
  41. IF CC JUMP .Lbytes;
  42. R3 = R1 | R0; /* OR addresses together */
  43. R3 <<= 30; /* check bottom two bits */
  44. CC = AZ; /* AZ set if zero.*/
  45. IF !CC JUMP .Lbytes; /* Jump if addrs not aligned.*/
  46. I0 = P3;
  47. P1 = P2 >> 2; /* count = n/4 */
  48. P1 += -1;
  49. R3 = 3;
  50. R2 = R2 & R3; /* remainder */
  51. P2 = R2; /* set remainder */
  52. R1 = [I0++];
  53. #if !defined(__WORKAROUND_AVOID_DAG1)
  54. LSETUP (.Lquad_loop, .Lquad_loop) LC0=P1;
  55. .Lquad_loop: MNOP || [P0++] = R1 || R1 = [I0++];
  56. #else
  57. LSETUP (.Lquad_loop_s, .Lquad_loop_e) LC0=P1;
  58. .Lquad_loop_s: [P0++] = R1;
  59. .Lquad_loop_e: R1 = [I0++];
  60. #endif
  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. #if defined(__WORKAROUND_SPECULATIVE_LOADS)
  80. NOP;
  81. NOP;
  82. #endif
  83. LSETUP (.Lol_s, .Lol_e) LC0 = P2;
  84. .Lol_s: B[P0--] = R1;
  85. .Lol_e: R1 = B[P3--] (Z);
  86. .Lno_loop: B[P0] = R1;
  87. P3 = I1;
  88. RTS;
  89. .size ___GI_memmove,.-___GI_memmove
  90. .hidden ___GI_memmove
  91. .weak _memmove
  92. .set _memmove,___GI_memmove