Commit be0aa4ad authored by Rupert Swarbrick's avatar Rupert Swarbrick Committed by Debargha Mukherjee
Browse files

Avoid UB in xx_loadl/storel_32 helper functions

The previous code dereferenced a uint32_t * that might be misaligned,
which is technically undefined behaviour in C. This version uses the
right (cryptically named) Intel intrinsics to generate a MOVD without
making any claims about the alignment of the pointer.


Change-Id: Ic51679b9f9ed4d2476e69da70f40b2d599cbc6b0
parent 380e37cd
......@@ -27,7 +27,7 @@
// Loads and stores to do away with the tedium of casting the address
// to the right type.
static INLINE __m128i xx_loadl_32(const void *a) {
return _mm_cvtsi32_si128(*(const uint32_t *)a);
return _mm_castps_si128(_mm_load_ss((const float *)a));
static INLINE __m128i xx_loadl_64(const void *a) {
......@@ -43,7 +43,7 @@ static INLINE __m128i xx_loadu_128(const void *a) {
static INLINE void xx_storel_32(void *const a, const __m128i v) {
*(uint32_t *)a = _mm_cvtsi128_si32(v);
_mm_store_ss((float *)a, _mm_castsi128_ps(v));
static INLINE void xx_storel_64(void *const a, const __m128i v) {
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment