memcpy.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <linux/types.h>
  2. void * memcpy(void * to, const void * from, size_t n)
  3. {
  4. void *xto = to;
  5. size_t temp, temp1;
  6. if (!n)
  7. return xto;
  8. if ((long) to & 1)
  9. {
  10. char *cto = to;
  11. const char *cfrom = from;
  12. *cto++ = *cfrom++;
  13. to = cto;
  14. from = cfrom;
  15. n--;
  16. }
  17. if (n > 2 && (long) to & 2)
  18. {
  19. short *sto = to;
  20. const short *sfrom = from;
  21. *sto++ = *sfrom++;
  22. to = sto;
  23. from = sfrom;
  24. n -= 2;
  25. }
  26. temp = n >> 2;
  27. if (temp)
  28. {
  29. long *lto = to;
  30. const long *lfrom = from;
  31. __asm__ __volatile__("movel %2,%3\n\t"
  32. "andw #7,%3\n\t"
  33. "lsrl #3,%2\n\t"
  34. "negw %3\n\t"
  35. "jmp %%pc@(1f,%3:w:2)\n\t"
  36. "4:\t"
  37. "movel %0@+,%1@+\n\t"
  38. "movel %0@+,%1@+\n\t"
  39. "movel %0@+,%1@+\n\t"
  40. "movel %0@+,%1@+\n\t"
  41. "movel %0@+,%1@+\n\t"
  42. "movel %0@+,%1@+\n\t"
  43. "movel %0@+,%1@+\n\t"
  44. "movel %0@+,%1@+\n\t"
  45. "1:\t"
  46. "dbra %2,4b\n\t"
  47. "clrw %2\n\t"
  48. "subql #1,%2\n\t"
  49. "jpl 4b\n\t"
  50. : "=a" (lfrom), "=a" (lto), "=d" (temp),
  51. "=&d" (temp1)
  52. : "0" (lfrom), "1" (lto), "2" (temp)
  53. );
  54. to = lto;
  55. from = lfrom;
  56. }
  57. if (n & 2)
  58. {
  59. short *sto = to;
  60. const short *sfrom = from;
  61. *sto++ = *sfrom++;
  62. to = sto;
  63. from = sfrom;
  64. }
  65. if (n & 1)
  66. {
  67. char *cto = to;
  68. const char *cfrom = from;
  69. *cto = *cfrom;
  70. }
  71. return xto;
  72. }