avoid unaligned aliasing load in neon vint4 byte constructor by sahvx655-wq · Pull Request #652 · ARM-software/astc-encoder · GitHub
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
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
Loading