Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Source/astcenc_vecmathlib_avx2_8.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,13 @@ struct vint8
*/
ASTCENC_SIMD_INLINE explicit vint8(const uint8_t *p)
{
// _mm_loadu_si64 would be nicer syntax, but missing on older GCC and
// generates broken code on GCC 11.x before 11.3, so use this to
// generate alignment-safe and aliasing-safe alternative
// Copy through a uint32_t to avoid load through a reinterpreted
// pointer, which is both unaligned and an aliasing violation.
uint64_t tmp;
std::memcpy(&tmp, p, sizeof(tmp));

// _mm_loadu_si64 would be nicer syntax, but missing on older GCC and
// generates broken code on GCC 11.x before 11.3.
m = _mm256_cvtepu8_epi32(_mm_cvtsi64_si128(tmp));
}

Expand Down
16 changes: 10 additions & 6 deletions Source/astcenc_vecmathlib_neon_4.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,17 @@ struct vint4
ASTCENC_SIMD_INLINE explicit vint4(const uint8_t *p)
{
#if ASTCENC_SVE == 0
// Cast is safe - NEON loads are allowed to be unaligned
uint32x2_t t8 = vld1_dup_u32(reinterpret_cast<const uint32_t*>(p));
uint16x4_t t16 = vget_low_u16(vmovl_u8(vreinterpret_u8_u32(t8)));
m = vreinterpretq_s32_u32(vmovl_u16(t16));
// Copy through a uint32_t to avoid load through a reinterpreted
// pointer, which is both unaligned and an aliasing violation.
uint32_t tmp;
std::memcpy(&tmp, p, sizeof(tmp));

uint32x2_t t8 = vdup_n_u32(tmp);
uint16x4_t t16 = vget_low_u16(vmovl_u8(vreinterpret_u8_u32(t8)));
m = vreinterpretq_s32_u32(vmovl_u16(t16));
#else
svint32_t data = svld1ub_s32(svptrue_pat_b32(SV_VL4), p);
m = svget_neonq(data);
svint32_t data = svld1ub_s32(svptrue_pat_b32(SV_VL4), p);
m = svget_neonq(data);
#endif
}

Expand Down
7 changes: 4 additions & 3 deletions Source/astcenc_vecmathlib_sse_4.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,13 @@ struct vint4
*/
ASTCENC_SIMD_INLINE explicit vint4(const uint8_t *p)
{
// _mm_loadu_si32 would be nicer syntax, but missing on older GCC and
// generates broken code on GCC 11.x before 11.3, so use this to
// generate alignment-safe and aliasing-safe alternative
// Copy through a uint32_t to avoid load through a reinterpreted
// pointer, which is both unaligned and an aliasing violation.
int32_t tmp;
std::memcpy(&tmp, p, sizeof(tmp));

// _mm_loadu_si32 would be nicer syntax, but missing on older GCC and
// generates broken code on GCC 11.x before 11.3.
__m128i t = _mm_cvtsi32_si128(tmp);

#if ASTCENC_SSE >= 41
Expand Down
Loading