Skip to content
Snippets Groups Projects
Unverified Commit e535e894 authored by Timothy B. Terriberry's avatar Timothy B. Terriberry Committed by Jean-Marc Valin
Browse files

Work around UBSan unaligned access errors.


The underlying objects are all 8-bit integers.
Verified that the generated assembly still just uses MOVD.

Signed-off-by: default avatarJean-Marc Valin <jmvalin@jmvalin.ca>
parent 7b6cede8
No related branches found
No related tags found
No related merge requests found
......@@ -56,8 +56,16 @@
int opus_select_arch(void);
# endif
/*MOVD should not impose any alignment restrictions, but the C standard does,
and UBSan will report errors if we actually make unaligned accesses.
Use this to work around those restrictions (which should hopefully all get
optimized to a single MOVD instruction).*/
#define OP_LOADU_EPI32(x) \
(int)((*(unsigned char *)(x) | *((unsigned char *)(x) + 1) << 8U |\
*((unsigned char *)(x) + 2) << 16U | (opus_uint32)*((unsigned char *)(x) + 3) << 24U))
#define OP_CVTEPI8_EPI32_M32(x) \
(_mm_cvtepi8_epi32(_mm_cvtsi32_si128(*(int *)(x))))
(_mm_cvtepi8_epi32(_mm_cvtsi32_si128(OP_LOADU_EPI32(x))))
#define OP_CVTEPI16_EPI32_M64(x) \
(_mm_cvtepi16_epi32(_mm_loadl_epi64((__m128i *)(x))))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment