memcpy.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file COPYING in the main directory of this archive
  4. * for more details.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/string.h>
  8. void *memcpy(void *to, const void *from, size_t n)
  9. {
  10. void *xto = to;
  11. size_t temp, temp1;
  12. if (!n)
  13. return xto;
  14. if ((long)to & 1) {
  15. char *cto = to;
  16. const char *cfrom = from;
  17. *cto++ = *cfrom++;
  18. to = cto;
  19. from = cfrom;
  20. n--;
  21. }
  22. if (n > 2 && (long)to & 2) {
  23. short *sto = to;
  24. const short *sfrom = from;
  25. *sto++ = *sfrom++;
  26. to = sto;
  27. from = sfrom;
  28. n -= 2;
  29. }
  30. temp = n >> 2;
  31. if (temp) {
  32. long *lto = to;
  33. const long *lfrom = from;
  34. #if defined(CONFIG_M68000) || defined(CONFIG_COLDFIRE)
  35. for (; temp; temp--)
  36. *lto++ = *lfrom++;
  37. #else
  38. asm volatile (
  39. " movel %2,%3\n"
  40. " andw #7,%3\n"
  41. " lsrl #3,%2\n"
  42. " negw %3\n"
  43. " jmp %%pc@(1f,%3:w:2)\n"
  44. "4: movel %0@+,%1@+\n"
  45. " movel %0@+,%1@+\n"
  46. " movel %0@+,%1@+\n"
  47. " movel %0@+,%1@+\n"
  48. " movel %0@+,%1@+\n"
  49. " movel %0@+,%1@+\n"
  50. " movel %0@+,%1@+\n"
  51. " movel %0@+,%1@+\n"
  52. "1: dbra %2,4b\n"
  53. " clrw %2\n"
  54. " subql #1,%2\n"
  55. " jpl 4b"
  56. : "=a" (lfrom), "=a" (lto), "=d" (temp), "=&d" (temp1)
  57. : "0" (lfrom), "1" (lto), "2" (temp));
  58. #endif
  59. to = lto;
  60. from = lfrom;
  61. }
  62. if (n & 2) {
  63. short *sto = to;
  64. const short *sfrom = from;
  65. *sto++ = *sfrom++;
  66. to = sto;
  67. from = sfrom;
  68. }
  69. if (n & 1) {
  70. char *cto = to;
  71. const char *cfrom = from;
  72. *cto = *cfrom;
  73. }
  74. return xto;
  75. }
  76. EXPORT_SYMBOL(memcpy);