c++ - 无法在 x86 上以 SSE 类型访问内存,但在 x64 上工作正常

标签 c++ x86 sse

我有一些使用 MSVC SSE 内在函数编写的代码。

            __m128 zero = _mm_setzero_ps();
            __m128 center = _mm_load_ps(&sphere.origin.x);
            __m128 boxmin = _mm_load_ps(&rhs.BottomLeftClosest.x);
            __m128 boxmax = _mm_load_ps(&rhs.TopRightFurthest.x);

            __m128 e = _mm_add_ps(_mm_max_ps(_mm_sub_ps(boxmin, center), zero), _mm_max_ps(_mm_sub_ps(center, boxmax), zero));
            e = _mm_mul_ps(e, e);

            __declspec(align(16)) float arr[4];
            _mm_store_ps(arr, e);
            float r = sphere.radius;
            return (arr[0] + arr[1] + arr[2] <= r * r);

Math::Vector 类型(即 sphere.originrhs.BottomLeftClosestrhs 的类型。 TopRightFurthest) 实际上是一个包含 3 个 float 的数组。我将它们对齐为 16 个字节,这段代码在 x64 上执行良好。但是在 x86 上,我在读取空指针时遇到访问冲突。关于它的来源有什么建议吗?

最佳答案

        __m128 center = _mm_load_ps(&sphere.origin.x);

_mm_load_ps() 要求传递的指针是 16 字节对齐的。没有证据表明您确保 sphere.origin.x 正确对齐。如果您无法提供该保证,则需要改用 _mm_loadu_ps()。

关于c++ - 无法在 x86 上以 SSE 类型访问内存,但在 x64 上工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10484985/

相关文章:

assembly - x86 上顺序一致的原子负载

assembly - 访问封装在 128 位寄存器中的任意 16 位元素

c++ - 计算 128 位整数中前导零的数量

c++ - 为什么 boost 正则表达式 '.{2}' 不匹配 '??'

c++ - 为 Visual Studio 2003 使用正则表达式的替代方法

c++ - 从 `map` 中删除不在 `set` 中的元素

c++ - 快速将数组 float 到双数组并返回

c++ - C++中的最佳 double 值限制

assembly - 为什么这么小的汇编程序这么慢?

程序集弹出空堆栈