memset.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 *memset(void *s, int c, size_t count)
  9. {
  10. void *xs = s;
  11. size_t temp;
  12. if (!count)
  13. return xs;
  14. c &= 0xff;
  15. c |= c << 8;
  16. c |= c << 16;
  17. if ((long)s & 1) {
  18. char *cs = s;
  19. *cs++ = c;
  20. s = cs;
  21. count--;
  22. }
  23. if (count > 2 && (long)s & 2) {
  24. short *ss = s;
  25. *ss++ = c;
  26. s = ss;
  27. count -= 2;
  28. }
  29. temp = count >> 2;
  30. if (temp) {
  31. long *ls = s;
  32. #if defined(CONFIG_M68000) || defined(CONFIG_COLDFIRE)
  33. for (; temp; temp--)
  34. *ls++ = c;
  35. #else
  36. size_t temp1;
  37. asm volatile (
  38. " movel %1,%2\n"
  39. " andw #7,%2\n"
  40. " lsrl #3,%1\n"
  41. " negw %2\n"
  42. " jmp %%pc@(2f,%2:w:2)\n"
  43. "1: movel %3,%0@+\n"
  44. " movel %3,%0@+\n"
  45. " movel %3,%0@+\n"
  46. " movel %3,%0@+\n"
  47. " movel %3,%0@+\n"
  48. " movel %3,%0@+\n"
  49. " movel %3,%0@+\n"
  50. " movel %3,%0@+\n"
  51. "2: dbra %1,1b\n"
  52. " clrw %1\n"
  53. " subql #1,%1\n"
  54. " jpl 1b"
  55. : "=a" (ls), "=d" (temp), "=&d" (temp1)
  56. : "d" (c), "0" (ls), "1" (temp));
  57. #endif
  58. s = ls;
  59. }
  60. if (count & 2) {
  61. short *ss = s;
  62. *ss++ = c;
  63. s = ss;
  64. }
  65. if (count & 1) {
  66. char *cs = s;
  67. *cs = c;
  68. }
  69. return xs;
  70. }
  71. EXPORT_SYMBOL(memset);