memset.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <linux/types.h>
  2. void * memset(void * s, int c, size_t count)
  3. {
  4. void *xs = s;
  5. size_t temp, temp1;
  6. if (!count)
  7. return xs;
  8. c &= 0xff;
  9. c |= c << 8;
  10. c |= c << 16;
  11. if ((long) s & 1)
  12. {
  13. char *cs = s;
  14. *cs++ = c;
  15. s = cs;
  16. count--;
  17. }
  18. if (count > 2 && (long) s & 2)
  19. {
  20. short *ss = s;
  21. *ss++ = c;
  22. s = ss;
  23. count -= 2;
  24. }
  25. temp = count >> 2;
  26. if (temp)
  27. {
  28. long *ls = s;
  29. __asm__ __volatile__("movel %1,%2\n\t"
  30. "andw #7,%2\n\t"
  31. "lsrl #3,%1\n\t"
  32. "negw %2\n\t"
  33. "jmp %%pc@(2f,%2:w:2)\n\t"
  34. "1:\t"
  35. "movel %3,%0@+\n\t"
  36. "movel %3,%0@+\n\t"
  37. "movel %3,%0@+\n\t"
  38. "movel %3,%0@+\n\t"
  39. "movel %3,%0@+\n\t"
  40. "movel %3,%0@+\n\t"
  41. "movel %3,%0@+\n\t"
  42. "movel %3,%0@+\n\t"
  43. "2:\t"
  44. "dbra %1,1b\n\t"
  45. "clrw %1\n\t"
  46. "subql #1,%1\n\t"
  47. "jpl 1b\n\t"
  48. : "=a" (ls), "=d" (temp), "=&d" (temp1)
  49. : "d" (c), "0" (ls), "1" (temp)
  50. );
  51. s = ls;
  52. }
  53. if (count & 2)
  54. {
  55. short *ss = s;
  56. *ss++ = c;
  57. s = ss;
  58. }
  59. if (count & 1)
  60. {
  61. char *cs = s;
  62. *cs = c;
  63. }
  64. return xs;
  65. }