This is the code I usually write:
alignas(16) __m128 myBuffer[8];
But maybe (since the object-array is 128*8 bit = 128 byte) I should write:
alignas(128) __m128 myBuffer[8];
Or, "since the first 16 byte are aligned" in the first example, the rest will be automatically aligned in memory?
128-bit SIMD data types must be aligned on 16 bytes. The compiler already knows that, so it's not needed to align __m128 manually. See for example, MSVC docs on __m128:
Variables of type
__m128are automatically aligned on 16-byte boundaries.
Also, arrays are contiguous. Each array element is naturally aligned the same as the first one. There's no need to multiply the alignment for arrays.
So you need not bother with alignas at all:
__m128 myBuffer[8];
This will just work.
is correct to use alignas(16) for an array[8] of m128?
It's not technically wrong, but according to documentation __m128 is aligned to 16 bytes, so it's unnecessary to use alignas.
But maybe ... I should write:
alignas(128)
If your goal is to align to 128 bytes, then you can achieve it like that.
Or "since the first 16 byte are aligned" in the first example, the rest will be automatically aligned in memory?
This question confuses me. If the integer is aligned, then the first byte is aligned. Rest of the bytes are offset from the first byte. In case the size is larger than alignment, some of the subsequent bytes would be aligned at offsets equal to the alignment.
Note that there is no __m128 in standard C++.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With