1 .. title:: clang-tidy - altera-struct-pack-align
3 altera-struct-pack-align
4 ========================
6 Finds structs that are inefficiently packed or aligned, and recommends
7 packing and/or aligning of said structs as needed.
9 Structs that are not packed take up more space than they should, and accessing
10 structs that are not well aligned is inefficient.
12 Fix-its are provided to fix both of these issues by inserting and/or amending
13 relevant struct attributes.
15 Based on the `Altera SDK for OpenCL: Best Practices Guide
16 <https://www.altera.com/en_US/pdfs/literature/hb/opencl-sdk/aocl_optimization_guide.pdf>`_.
20 // The following struct is originally aligned to 4 bytes, and thus takes up
21 // 12 bytes of memory instead of 10. Packing the struct will make it use
22 // only 10 bytes of memory, and aligning it to 16 bytes will make it
23 // efficient to access.
30 // The following struct is arranged in such a way that packing is not needed.
31 // However, it is aligned to 4 bytes instead of 8, and thus needs to be
32 // explicitly aligned.
33 struct implicitly_packed_example {
41 // The following struct is explicitly aligned and packed.
46 } __attribute__((packed)) __attribute__((aligned(16));
48 // Explicitly aligning a struct to the wrong value will result in a warning.
49 // The following example should be aligned to 16 bytes, not 32.
50 struct badly_aligned_example {
54 } __attribute__((packed)) __attribute__((aligned(32)));