I've got some code written using the MSVC SSE intrinsics.
__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);
The Math::Vector
type (which is the type of sphere.origin
, rhs.BottomLeftClosest
, and rhs.TopRightFurthest
) is effectively an array of 3 floats. I aligned them to 16 bytes and this code executes fine on x64. But on x86 I get access violation reading a null pointer. Any advice on where this comes from?
__m128 center = _mm_load_ps(&sphere.origin.x);
_mm_load_ps() requires that the passed pointer is 16-byte aligned. There's no evidence that you ensured that sphere.origin.x is aligned properly. You'll need to use _mm_loadu_ps() instead if you can't provide that guarantee.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With