【发布时间】:2018-04-18 22:43:36
【问题描述】:
#include<cstdint>
#include<iostream>
#include<immintrin.h>
using namespace std;
int main()
{
alignas(32) int32_t a[32];
__m256i t256(_mm256_setzero_si256());
_mm256_store_si256(reinterpret_cast<__m256i*>(a),t256);
cout<<"pass"<<endl;
_mm256_store_si256(reinterpret_cast<__m256i*>(a+8),t256);
cout<<"pass"<<endl;
_mm256_store_si256(reinterpret_cast<__m256i*>(a+4),t256);
cout<<"pass"<<endl;
}
在 windows 中运行此程序时,我得到了三个“通过”(由 vs2017 15.6.6 编译,CPU 为 i7-6700HQ)。
但是,我在 arch linux 中运行第三条语句时得到Segmentation fault(由 g++ 7.3.1 和 clang 6.0.0 编译,CPU 为 i7-7820x)。
我使用的选项是-std=c++17 -march=native。
在我看来,我可以在 a 内的任何地方存储,因为 a 在 32 字节边界上对齐,并且每个元素都是 32 位整数。
但是我得到了什么Segmentation fault?
Intel _mm256_store_si256
【问题讨论】:
-
__m256i是否需要与 32 字节(256 位)边界对齐?a+4不在 32 字节边界上。 -
@kevin 每个元素都是 32 位整数,所以
a+1a+2a+3... 也应该在 32 字节边界上对齐,不是吗? -
不,
a+1位于 32 位(4 字节)边界上。 -
@Kevin 我明白了,它是 32-
byte边界而不是 32-bit边界。谢谢。