Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
align_16.h
Go to the documentation of this file.
1 //
2 // align_16.h
3 //
4 // Macros to support allocation of variables and structures
5 // that are guaranteed to be aligned on a 16-byte boundary.
6 // Note that ONLY the first variable in the structure is
7 // guaranteed to align on a 16-byte boundary; the alignment
8 // of the remaining elements follows the standard packing
9 // rules for c/c++ structure members.
10 //
11 // Richard Jones, University of Connecticut
12 // March 5, 2011
13 //
14 
15 #ifndef ALIGNED_16_BLOCK
16 
17 #include <stdint.h>
18 
19 #define ALIGNED_16_BLOCK(TYPE,NUM,PTR) \
20 uint32_t padded_space_for_pointer_##PTR \
21  [ ( ( ( NUM ) * sizeof(TYPE)) + 18 ) / 4 ]; \
22 TYPE * const PTR;
23 
24 #define ALIGNED_16_BLOCK_PTR(TYPE,NUM,PTR) \
25 reinterpret_cast< TYPE *> ((reinterpret_cast<uintptr_t>(padded_space_for_pointer_##PTR) + 15) & (~ 15))
26 
27 #define ALIGNED_16_BLOCK_WITH_PTR(TYPE,NUM,PTR) \
28 uint32_t padded_space_for_pointer_##PTR \
29  [ ( ( ( NUM ) * sizeof(TYPE)) + 18 ) / 4 ]; \
30 TYPE * const PTR = ALIGNED_16_BLOCK_PTR(TYPE,NUM,PTR);
31 
32 #endif