c++ - 在 ARM NEON 中的数组边界上加载 vector

标签 c++ image-processing arm simd 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[宽度-1]

所以如果我有一个 vector :

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

如何从中获得以下 vector :

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);
}

关于c++ - 在 ARM NEON 中的数组边界上加载 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34041221/

相关文章:

image - 如何对 RGB 值执行双线性插值?

c++ - 交叉编译 C++ 程序时权限被拒绝

c++11 - 在ARM计算库中初始化张量的正确方法?

c++ - 使用 o2 标志编译会使程序出现访问冲突

c++ - 我什么时候应该 `#include <ios>` , `#include <iomanip>` 等?

c++ - 有没有办法在 GCC 中禁用内联汇编程序?

c++ - 为什么这段代码以相反的方式工作?

c++ - 使用高度图扭曲图像?

java - 在图像上附加文本

c - 用 C/gcc 内在函数 : no intrinsic for VSWP? 交换 NEON vector 的一半