Quick Question guys… Are these code spinets have the same alignment ?
struct sse_t {
float sse_data[4];
};
// the array "cacheline" will be aligned to 64-byte boundary
struct sse_t alignas(64) cacheline[1000000];
Or
// every object of type sse_t will be aligned to 64-byte boundary
struct sse_t {
float sse_data[4];
} __attribute((aligned(64)));
struct sse_t cacheline[1000000];
Not quite. Your two examples are actually very different.
In your first example, you will get an array of
sse_tobjects. Asse_tobject is only guaranteed 4-byte alignment. But since the entire array is aligned to 64-bytes, eachsse_tobject will be properly aligned for SSE access.In your second example, you are forcing each
sse_tobject to be aligned to 64-bytes. But eachsse_tobject is only 16 bytes. So the array will be 4x larger. (You will have 48 bytes of padding at the end of eachsse_tobject).Output:
I’m pretty sure that the second case is not what you want.