memcpy.S 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. /*
  9. * void *memcpy(void *to, const void *from, unsigned long n)
  10. *
  11. * This implementation does word-aligned loads in the main loop,
  12. * possibly sacrificing alignment of stores.
  13. *
  14. * Hopefully, in most cases, both "to" and "from" will be
  15. * word-aligned to begin with.
  16. */
  17. .text
  18. .global memcpy
  19. .type memcpy, @function
  20. memcpy:
  21. mov r9, r11
  22. andl r9, 3, COH
  23. brne 1f
  24. /* At this point, "from" is word-aligned */
  25. 2: sub r10, 4
  26. mov r9, r12
  27. brlt 4f
  28. 3: ld.w r8, r11++
  29. sub r10, 4
  30. st.w r12++, r8
  31. brge 3b
  32. 4: neg r10
  33. reteq r9
  34. /* Handle unaligned count */
  35. lsl r10, 2
  36. add pc, pc, r10
  37. ld.ub r8, r11++
  38. st.b r12++, r8
  39. ld.ub r8, r11++
  40. st.b r12++, r8
  41. ld.ub r8, r11++
  42. st.b r12++, r8
  43. retal r9
  44. /* Handle unaligned "from" pointer */
  45. 1: sub r10, 4
  46. brlt 4b
  47. add r10, r9
  48. lsl r9, 2
  49. add pc, pc, r9
  50. ld.ub r8, r11++
  51. st.b r12++, r8
  52. ld.ub r8, r11++
  53. st.b r12++, r8
  54. ld.ub r8, r11++
  55. st.b r12++, r8
  56. rjmp 2b