3 <<memset>>---set an area of memory
10 void *memset(void *<[dst]>, int <[c]>, size_t <[length]>);
14 void *memset(<[dst]>, <[c]>, <[length]>)
20 This function converts the argument <[c]> into an unsigned
21 char and fills the first <[length]> characters of the array
22 pointed to by <[dst]> to the value.
25 <<memset>> returns the value of <[dst]>.
30 <<memset>> requires no supporting OS subroutines.
39 #define LBLOCKSIZE (sizeof(long))
40 #define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1))
41 #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
44 _DEFUN (memset, (m, c, n),
51 #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
54 unsigned long *aligned_addr;
55 unsigned int d = c & 0xff; /* To avoid sign extension, copy C to an
68 /* If we get this far, we know that n is large and s is word-aligned. */
69 aligned_addr = (unsigned long *) s;
71 /* Store D into each char sized location in BUFFER so that
72 we can set large blocks quickly. */
73 buffer = (d << 8) | d;
74 buffer |= (buffer << 16);
75 for (i = 32; i < LBLOCKSIZE * 8; i <<= 1)
76 buffer = (buffer << i) | buffer;
78 /* Unroll the loop. */
79 while (n >= LBLOCKSIZE*4)
81 *aligned_addr++ = buffer;
82 *aligned_addr++ = buffer;
83 *aligned_addr++ = buffer;
84 *aligned_addr++ = buffer;
88 while (n >= LBLOCKSIZE)
90 *aligned_addr++ = buffer;
93 /* Pick up the remainder with a bytewise loop. */
94 s = (char*)aligned_addr;
97 #endif /* not PREFER_SIZE_OVER_SPEED */