memcpy.c 1.6 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(__mc68020__) || defined(__mc68030__) || \
  35. defined(__mc68040__) || defined(__mc68060__) || defined(__mcpu32__)
  36. asm volatile (
  37. " movel %2,%3\n"
  38. " andw #7,%3\n"
  39. " lsrl #3,%2\n"
  40. " negw %3\n"
  41. " jmp %%pc@(1f,%3:w:2)\n"
  42. "4: movel %0@+,%1@+\n"
  43. " movel %0@+,%1@+\n"
  44. " 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. "1: dbra %2,4b\n"
  51. " clrw %2\n"
  52. " subql #1,%2\n"
  53. " jpl 4b"
  54. : "=a" (lfrom), "=a" (lto), "=d" (temp), "=&d" (temp1)
  55. : "0" (lfrom), "1" (lto), "2" (temp));
  56. #else
  57. for (; temp; temp--)
  58. *lto++ = *lfrom++;
  59. #endif
  60. to = lto;
  61. from = lfrom;
  62. }
  63. if (n & 2) {
  64. short *sto = to;
  65. const short *sfrom = from;
  66. *sto++ = *sfrom++;
  67. to = sto;
  68. from = sfrom;
  69. }
  70. if (n & 1) {
  71. char *cto = to;
  72. const char *cfrom = from;
  73. *cto = *cfrom;
  74. }
  75. return xto;
  76. }
  77. EXPORT_SYMBOL(memcpy);