memset.c 571 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
  3. #include <linux/types.h>
  4. void *memset(void *dest, int c, size_t l)
  5. {
  6. char *d = dest;
  7. int ch = c & 0xff;
  8. int tmp = (ch | ch << 8 | ch << 16 | ch << 24);
  9. while (((uintptr_t)d & 0x3) && l--)
  10. *d++ = ch;
  11. while (l >= 16) {
  12. *(((u32 *)d)) = tmp;
  13. *(((u32 *)d)+1) = tmp;
  14. *(((u32 *)d)+2) = tmp;
  15. *(((u32 *)d)+3) = tmp;
  16. l -= 16;
  17. d += 16;
  18. }
  19. while (l > 3) {
  20. *(((u32 *)d)) = tmp;
  21. l -= 4;
  22. d += 4;
  23. }
  24. while (l) {
  25. *d = ch;
  26. l--;
  27. d++;
  28. }
  29. return dest;
  30. }