在 ARM NEON 中的数组边界上加载向量

Loading of a vector on the border of the array in ARM NEON

我尝试使用 NEON 内在函数为 ARM 优化一些图像处理算法。 对于某些过滤器,它需要加载点附近的元素。 例如,要以 p[x] 像素过滤图像,我需要加载 p[x - 1]p[x]p[x + 1]。 如果 x=0,那么我加载 p[0]p[0]p[1]。如果 x=width-1,那么我加载 p[width-2]p[width-1]p[width-1]

所以如果我有一个向量:

uint8x16_t a = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};

我如何从中得到以下向量:

uint8x16_t b = {0, 0, 1, 2, 3, 4, 5, 6, 7,  8,  9, 10, 11, 12, 13, 14};
uint8x16_t c = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15};

我认为以下功能对您的情况很有用:

template <size_t count> inline uint8x16_t LoadBeforeFirst(uint8x16_t first)
{
    return vextq_u8(vextq_u8(first, first, count), first, 16 - count);
}

template <size_t count> inline uint8x16_t LoadAfterLast(uint8x16_t last)
{
    return vextq_u8(last, vextq_u8(last, last, 16 - count), count);
}