3 <<memset>>---set an area of memory
10 void *memset(const 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 <[m]>.
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
),
49 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
62 unsigned long *aligned_addr
;
64 if (!TOO_SMALL (n
) && !UNALIGNED (m
))
66 /* If we get this far, we know that n is large and m is word-aligned. */
68 aligned_addr
= (unsigned long*)m
;
70 /* Store C into each char sized location in BUFFER so that
71 we can set large blocks quickly. */
75 buffer
= (c
<< 8) | c
;
76 buffer
|= (buffer
<< 16);
81 for (i
= 0; i
< LBLOCKSIZE
; i
++)
82 buffer
= (buffer
<< 8) | c
;
85 while (n
>= LBLOCKSIZE
*4)
87 *aligned_addr
++ = buffer
;
88 *aligned_addr
++ = buffer
;
89 *aligned_addr
++ = buffer
;
90 *aligned_addr
++ = buffer
;
94 while (n
>= LBLOCKSIZE
)
96 *aligned_addr
++ = buffer
;
99 /* Pick up the remainder with a bytewise loop. */
100 s
= (char*)aligned_addr
;
109 #endif /* not PREFER_SIZE_OVER_SPEED */