Is there an obvious reason why the following code segfaults ?
#include
#include
struct point {
__m128i v;
point()
There is a possibility that the memory that is allocated by the default allocator in your compiler's STL implementation is not aligned. This will be dependent on the specific platform and compiler vendor.
Usually the default allocator uses operator new, which usually does not guarantee alignment beyond the word size (32-bit or 64-bit). To solve the problem, it may be necessary to implement a custom allocator which uses _aligned_malloc.
Also, a simple fix (although not a satisfactory one) would be to assign the value to a local __m128i variable, then copy that variable to the struct using unaligned instruction. Example:
struct point {
__m128i v;
point() {
__m128i temp = _mm_setr_epi32(0, 0, 0, 0);
_mm_storeu_si128(&v, temp);
}
};