1 /* Test of allocating memory with given alignment.
3 Copyright (C) 2020 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* Written by Bruno Haible <bruno@clisp.org>, 2020. */
26 #define aligned_malloc aligned4_malloc
27 #define aligned_free aligned4_free
28 #include "aligned-malloc.h"
34 #define aligned_malloc aligned8_malloc
35 #define aligned_free aligned8_free
36 #include "aligned-malloc.h"
42 #define aligned_malloc aligned16_malloc
43 #define aligned_free aligned16_free
44 #include "aligned-malloc.h"
50 #define aligned_malloc aligned32_malloc
51 #define aligned_free aligned32_free
52 #include "aligned-malloc.h"
62 main (int argc
, char *argv
[])
64 static size_t sizes
[] =
65 { 13, 8, 17, 450, 320, 1, 99, 4, 15, 16, 2, 76, 37, 127, 2406, 641 };
66 void *aligned4_blocks
[SIZEOF (sizes
)];
67 void *aligned8_blocks
[SIZEOF (sizes
)];
68 void *aligned16_blocks
[SIZEOF (sizes
)];
69 void *aligned32_blocks
[SIZEOF (sizes
)];
72 for (i
= 0; i
< SIZEOF (sizes
); i
++)
74 size_t size
= sizes
[i
];
76 aligned4_blocks
[i
] = aligned4_malloc (size
);
77 ASSERT (((uintptr_t) aligned4_blocks
[i
] % 4) == 0);
78 memset (aligned4_blocks
[i
], 'w', size
);
80 aligned8_blocks
[i
] = aligned8_malloc (size
);
81 ASSERT (((uintptr_t) aligned8_blocks
[i
] % 8) == 0);
82 memset (aligned8_blocks
[i
], 'x', size
);
84 aligned16_blocks
[i
] = aligned16_malloc (size
);
85 ASSERT (((uintptr_t) aligned16_blocks
[i
] % 16) == 0);
86 memset (aligned16_blocks
[i
], 'y', size
);
88 aligned32_blocks
[i
] = aligned32_malloc (size
);
89 ASSERT (((uintptr_t) aligned32_blocks
[i
] % 32) == 0);
90 memset (aligned32_blocks
[i
], 'z', size
);
93 for (i
= 0; i
< SIZEOF (sizes
); i
++)
95 aligned4_free (aligned4_blocks
[i
]);
96 aligned8_free (aligned8_blocks
[i
]);
97 aligned16_free (aligned16_blocks
[i
]);
98 aligned32_free (aligned32_blocks
[i
]);