memset.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * arch/v850/lib/memset.c -- Memory initialization
  3. *
  4. * Copyright (C) 2001,02,04 NEC Corporation
  5. * Copyright (C) 2001,02,04 Miles Bader <miles@gnu.org>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General
  8. * Public License. See the file COPYING in the main directory of this
  9. * archive for more details.
  10. *
  11. * Written by Miles Bader <miles@gnu.org>
  12. */
  13. #include <linux/types.h>
  14. void *memset (void *dst, int val, __kernel_size_t count)
  15. {
  16. if (count) {
  17. register unsigned loop;
  18. register void *ptr asm ("ep") = dst;
  19. /* replicate VAL into a long. */
  20. val &= 0xff;
  21. val |= val << 8;
  22. val |= val << 16;
  23. /* copy initial unaligned bytes. */
  24. if ((long)ptr & 1) {
  25. *(char *)ptr = val;
  26. ptr = (void *)((char *)ptr + 1);
  27. count--;
  28. }
  29. if (count > 2 && ((long)ptr & 2)) {
  30. *(short *)ptr = val;
  31. ptr = (void *)((short *)ptr + 1);
  32. count -= 2;
  33. }
  34. /* 32-byte copying loop. */
  35. for (loop = count / 32; loop; loop--) {
  36. asm ("sst.w %0, 0[ep]; sst.w %0, 4[ep];"
  37. "sst.w %0, 8[ep]; sst.w %0, 12[ep];"
  38. "sst.w %0, 16[ep]; sst.w %0, 20[ep];"
  39. "sst.w %0, 24[ep]; sst.w %0, 28[ep]"
  40. :: "r" (val) : "memory");
  41. ptr += 32;
  42. }
  43. count %= 32;
  44. /* long copying loop. */
  45. for (loop = count / 4; loop; loop--) {
  46. *(long *)ptr = val;
  47. ptr = (void *)((long *)ptr + 1);
  48. }
  49. count %= 4;
  50. /* finish up with any trailing bytes. */
  51. if (count & 2) {
  52. *(short *)ptr = val;
  53. ptr = (void *)((short *)ptr + 1);
  54. }
  55. if (count & 1) {
  56. *(char *)ptr = val;
  57. }
  58. }
  59. return dst;
  60. }