PatchworkOS
Loading...
Searching...
No Matches
memset32.c
Go to the documentation of this file.
1#include <stdint.h>
2#include <string.h>
3
4void* memset32(void* s, uint32_t c, size_t n)
5{
6 uint32_t* p = s;
7 uint64_t c64 = ((uint64_t)c << 32) | c;
8
9 while (((uintptr_t)p & 3) && n)
10 {
11 *p++ = c;
12 n--;
13 }
14
15 while (n >= 16)
16 {
17 ((uint64_t*)p)[0] = c64;
18 ((uint64_t*)p)[1] = c64;
19 ((uint64_t*)p)[2] = c64;
20 ((uint64_t*)p)[3] = c64;
21 ((uint64_t*)p)[4] = c64;
22 ((uint64_t*)p)[5] = c64;
23 ((uint64_t*)p)[6] = c64;
24 ((uint64_t*)p)[7] = c64;
25 p += 16;
26 n -= 16;
27 }
28
29 while (n >= 4)
30 {
31 ((uint64_t*)p)[0] = c64;
32 ((uint64_t*)p)[1] = c64;
33 p += 4;
34 n -= 4;
35 }
36
37 while (n)
38 {
39 *p++ = c;
40 n--;
41 }
42
43 return s;
44}
void * memset32(void *s, uint32_t c, size_t n)
Definition memset32.c:4
__UINT32_TYPE__ uint32_t
Definition stdint.h:15
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:43