memset.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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(__mc68020__) || defined(__mc68030__) || \
  33. defined(__mc68040__) || defined(__mc68060__) || defined(__mcpu32__)
  34. size_t temp1;
  35. asm volatile (
  36. " movel %1,%2\n"
  37. " andw #7,%2\n"
  38. " lsrl #3,%1\n"
  39. " negw %2\n"
  40. " jmp %%pc@(2f,%2:w:2)\n"
  41. "1: movel %3,%0@+\n"
  42. " movel %3,%0@+\n"
  43. " 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. "2: dbra %1,1b\n"
  50. " clrw %1\n"
  51. " subql #1,%1\n"
  52. " jpl 1b"
  53. : "=a" (ls), "=d" (temp), "=&d" (temp1)
  54. : "d" (c), "0" (ls), "1" (temp));
  55. #else
  56. for (; temp; temp--)
  57. *ls++ = c;
  58. #endif
  59. s = ls;
  60. }
  61. if (count & 2) {
  62. short *ss = s;
  63. *ss++ = c;
  64. s = ss;
  65. }
  66. if (count & 1) {
  67. char *cs = s;
  68. *cs = c;
  69. }
  70. return xs;
  71. }
  72. EXPORT_SYMBOL(memset);