与 GCC 中的 NEON 内在函数对齐 load/store

Aligned load/store with NEON intrinsics in GCC

如何让 GCC 生成 load/store 对齐访问指令?

如果我们有类似的东西:

uint8_t* p;
uint8x8x4_t r = vld4_u8(p);

如何让 GCC 生成需要 32 字节对齐的加载指令?

我想你可以使用 __builtin_assume_aligned(ptr, size);

例如

#include <arm_neon.h>

void blend4(uint8_t *src, uint8_t *dst)
{
    uint8_t *aligned_src = __builtin_assume_aligned(src, 16);
    uint8_t *aligned_dst = __builtin_assume_aligned(dst, 16);
    uint8x8x4_t temp = vld4_u8(aligned_src);
    vst4_u8(aligned_dst, temp);
}

生成:

vld4.8  {d16-d19}, [r0:128]
vst4.8  {d16-d19}, [r1:128]