memcpy.S 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* memcpy.S
  2. * Copyright (C) 2003, 2005, 2006 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. /* void *memcpy(void *dest, const void *src, size_t n);
  12. * R0 = To Address (dest) (leave unchanged to form result)
  13. * R1 = From Address (src)
  14. * R2 = count
  15. *
  16. * Note: Favours word alignment
  17. */
  18. .text
  19. .align 2
  20. .global _memcpy
  21. .type _memcpy, STT_FUNC
  22. _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 too_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 bytes ; // 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 (quad_loop , quad_loop) LC0=P1;
  42. quad_loop: MNOP || [P0++] = R1 || R1 = [I0++];
  43. #else
  44. LSETUP (quad_loop_s , quad_loop_e) LC0=P1;
  45. quad_loop_s: [P0++] = R1;
  46. quad_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 bytes;
  52. P3 = [SP++];
  53. RTS;
  54. too_small:
  55. CC = P2 == 0; //Check zero count
  56. IF CC JUMP finished; // very unlikely
  57. bytes:
  58. LSETUP (byte_loop_s , byte_loop_e) LC0=P2;
  59. byte_loop_s: R1 = B[P3++](Z);
  60. byte_loop_e: B[P0++] = R1;
  61. finished:
  62. P3 = [SP++];
  63. RTS;
  64. .size _memcpy,.-_memcpy
  65. libc_hidden_def (memcpy)