vector of __mm128 won't push_back()

2019-04-05 18:50发布

问题:

This simple SSE code:

#include <vector>
#include <emmintrin.h>

int main() {
    std::vector<__m128> blah;
    blah.push_back(__m128());
}

Crashes on MSVC 10 with a segfault at 0xffffffff.

What could be going wrong ?

回答1:

A std::vector does not allocate specially aligned memory, which __m128 needs to store it's data. You will have to either swap out the allocator, or replace it with an array of 4 floats and then perform an unaligned load or copy out to an aligned location every time you access the vector.