Gid*_*eon 3 c++ sse intrinsics
以下编译在MSVC上没有警告.
#include <iostream>
#include <emmintrin.h>
int main()
{
__declspec(align(16)) int x = 42;
std::cout << &x << "\n"; // Print out the address that holds x
__m128i v = _mm_load_si128((__m128i const*)(x));
}
Run Code Online (Sandbox Code Playgroud)
本质上,代码对齐一个32位整数,并尝试将其加载到__m128i类型中.在需要输入地址为16字节对齐.在不需要它,但都可以导致运行时,上面的代码发出访问冲突.为什么,我该如何解决?_mm_load_si128 _mm_loadu_si128
你忘记了以下地址x:
__m128i v = _mm_load_si128((__m128i const*)(&x));
// ^
// |
// Here ----------------+
Run Code Online (Sandbox Code Playgroud)
此外,您没有为数据提供足够的空间,因此_mm_load_si128最终会读取已分配的内存块的末尾.