memcpy.S 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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: mov r9, r12
  26. 5: sub r10, 4
  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. movlt r9, r12
  47. brlt 4b
  48. add r10, r9
  49. lsl r9, 2
  50. add pc, pc, r9
  51. ld.ub r8, r11++
  52. st.b r12++, r8
  53. ld.ub r8, r11++
  54. st.b r12++, r8
  55. ld.ub r8, r11++
  56. st.b r12++, r8
  57. mov r8, r12
  58. add pc, pc, r9
  59. sub r8, 1
  60. nop
  61. sub r8, 1
  62. nop
  63. sub r8, 1
  64. nop
  65. mov r9, r8
  66. rjmp 5b