This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <config.h>
21
22 #include <stdint.h>
23 #include <stdlib.h>
24
25 #define ALIGNMENT 4
26 #define aligned_malloc aligned4_malloc
27 #define aligned_free aligned4_free
28 #include "aligned-malloc.h"
29 #undef aligned_free
30 #undef aligned_malloc
31 #undef ALIGNMENT
32
33 #define ALIGNMENT 8
34 #define aligned_malloc aligned8_malloc
35 #define aligned_free aligned8_free
36 #include "aligned-malloc.h"
37 #undef aligned_free
38 #undef aligned_malloc
39 #undef ALIGNMENT
40
41 #define ALIGNMENT 16
42 #define aligned_malloc aligned16_malloc
43 #define aligned_free aligned16_free
44 #include "aligned-malloc.h"
45 #undef aligned_free
46 #undef aligned_malloc
47 #undef ALIGNMENT
48
49 #define ALIGNMENT 32
50 #define aligned_malloc aligned32_malloc
51 #define aligned_free aligned32_free
52 #include "aligned-malloc.h"
53 #undef aligned_free
54 #undef aligned_malloc
55 #undef ALIGNMENT
56
57 #include <string.h>
58
59 #include "macros.h"
60
61 int
62 main (int argc, char *argv[])
63 {
64 static size_t sizes[] =
65 { 13, 8, 17, 450, 320, 1, 99, 4, 15, 16, 2, 76, 37, 127, 2406, 641 };
66 void *volatile aligned4_blocks[SIZEOF (sizes)];
67 void *volatile aligned8_blocks[SIZEOF (sizes)];
68 void *volatile aligned16_blocks[SIZEOF (sizes)];
69 void *volatile aligned32_blocks[SIZEOF (sizes)];
70 size_t i;
71
72 for (i = 0; i < SIZEOF (sizes); i++)
73 {
74 size_t size = sizes[i];
75
76 aligned4_blocks[i] = aligned4_malloc (size);
77 ASSERT (((uintptr_t) aligned4_blocks[i] % 4) == 0);
78 memset (aligned4_blocks[i], 'w', size);
79
80 aligned8_blocks[i] = aligned8_malloc (size);
81 ASSERT (((uintptr_t) aligned8_blocks[i] % 8) == 0);
82 memset (aligned8_blocks[i], 'x', size);
83
84 aligned16_blocks[i] = aligned16_malloc (size);
85 ASSERT (((uintptr_t) aligned16_blocks[i] % 16) == 0);
86 memset (aligned16_blocks[i], 'y', size);
87
88 aligned32_blocks[i] = aligned32_malloc (size);
89 ASSERT (((uintptr_t) aligned32_blocks[i] % 32) == 0);
90 memset (aligned32_blocks[i], 'z', size);
91 }
92
93 for (i = 0; i < SIZEOF (sizes); i++)
94 {
95 aligned4_free (aligned4_blocks[i]);
96 aligned8_free (aligned8_blocks[i]);
97 aligned16_free (aligned16_blocks[i]);
98 aligned32_free (aligned32_blocks[i]);
99 }
100
101 return 0;
102 }