Mar*_*Zzz 5 simd intrinsics segmentation-fault stdvector c++11
正如标题所示,我试图使用具有SIMD内在数据类型的STL向量.我知道由于加载/存储的潜在开销,这不是一个好习惯,但我遇到了一个非常奇怪的错误.这是代码:
#include "immintrin.h"
#include <vector>
#include <stdio.h>
#define VL 8
int main () {
std::vector<__m256> vec_1(10);
std::vector<__m256> vec_2(10);
float * tmp_1 = new float[VL];
printf("vec_1[0]:\n");
_mm256_storeu_ps(tmp_1, vec_1[0]); // seems to go as expected
for (int i = 0; i < VL; ++i)
printf("%f ", tmp_1[i]);
printf("\n");
delete tmp_1;
float * tmp_2 = new float[VL];
printf("vec_2[0]:\n");
_mm256_storeu_ps(tmp_2, vec_2[0]); // segmentation fault
for (int i = 0; i < VL; ++i)
printf("%f ", tmp_2[i]);
printf("\n");
delete tmp_2;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我用它编译了它g++ -O3 -g -std=c++11 -mavx2 test.cpp -o test. vec_1[0]按预期打印(全零),但在发生时会出现分段错误vec_2[0].我认为这是对齐问题,但_mm256_store_ps我用过_mm256_storeu_ps,而不是需要对齐.
它是具有AVX2扩展的Intel Haswell架构.GCC版本是4.8.5.
任何可能的线索都是受欢迎的.