memcpy.S 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* memcpy.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 *memcpy(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
  16. *
  17. * Note: Favours word alignment
  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 it).
  23. */
  24. .global ___GI_memcpy
  25. .type ___GI_memcpy, STT_FUNC
  26. ___GI_memcpy:
  27. [--SP] = P3;
  28. P0 = R0; /* P0 = To address */
  29. P3 = R1; /* P3 = From Address */
  30. P2 = R2; /* P2 = count */
  31. CC = R2 <= 7(IU);
  32. IF CC JUMP .Ltoo_small;
  33. I0 = R1;
  34. R3 = R1 | R0; /* OR addresses together */
  35. R3 <<= 30; /* check bottom two bits */
  36. CC = AZ; /* AZ set if zero. */
  37. IF !CC JUMP .Lbytes; /* Jump if addrs not aligned. */
  38. P1 = P2 >> 2; /* count = n/4 */
  39. P1 += -1;
  40. R3 = 3;
  41. R2 = R2 & R3; /* remainder */
  42. P2 = R2; /* set remainder */
  43. R1 = [I0++];
  44. #if !defined(__WORKAROUND_AVOID_DAG1)
  45. LSETUP (.Lquad_loop, .Lquad_loop) LC0=P1;
  46. .Lquad_loop: MNOP || [P0++] = R1 || R1 = [I0++];
  47. #else
  48. LSETUP (.Lquad_loop_s, .Lquad_loop_e) LC0=P1;
  49. .Lquad_loop_s: [P0++] = R1;
  50. .Lquad_loop_e: R1 = [I0++];
  51. #endif
  52. [P0++] = R1;
  53. CC = P2 == 0; /* any remaining bytes? */
  54. P3 = I0; /* Ammend P3 for remaining copy */
  55. IF !CC JUMP .Lbytes;
  56. P3 = [SP++];
  57. RTS;
  58. .Ltoo_small:
  59. CC = P2 == 0; /* Check zero count */
  60. IF CC JUMP .Lfinished; /* very unlikely */
  61. .Lbytes:
  62. LSETUP (.Lbyte_loop_s, .Lbyte_loop_e) LC0=P2;
  63. .Lbyte_loop_s: R1 = B[P3++](Z);
  64. .Lbyte_loop_e: B[P0++] = R1;
  65. .Lfinished:
  66. P3 = [SP++];
  67. RTS;
  68. .size ___GI_memcpy,.-___GI_memcpy
  69. .hidden ___GI_memcpy
  70. .weak _memcpy
  71. .set _memcpy,___GI_memcpy