memcpy.S 1.9 KB

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