小编Shu*_*hun的帖子

如何使用 neon 内在函数添加通道中的所有 int32 元素

这是我在通道中添加所有 int16x4 元素的代码:

#include <arm_neon.h>
...
int16x4_t acc = vdup_n_s16(1);
int32x2_t acc1;
int64x1_t acc2;
int32_t sum;
acc1 = vpaddl_s16(acc);
acc2 = vpaddl_s32(acc1);
sum = (int)vget_lane_s64(acc2, 0);
printf("%d\n", sum);// 4
Run Code Online (Sandbox Code Playgroud)

我尝试将所有 int32x4 元素添加到通道中。

但我的代码看起来效率很低:

#include <arm_neon.h>
...
int32x4_t accl = vdupq_n_s32(1);
int64x2_t accl_1;
int64_t temp;
int64_t temp2;
int32_t sum1;
accl_1=vpaddlq_s32(accl);
temp = (int)vgetq_lane_s64(accl_1,0);
temp2 = (int)vgetq_lane_s64(accl_1,1);
sum1=temp+temp2;
printf("%d\n", sum);// 4
Run Code Online (Sandbox Code Playgroud)

有没有简单明了的方法来做到这一点?我希望LLVM汇编代码编译后简单、清晰。我也希望最终的类型sum是32位。

我使用基于 LLVM 编译器基础设施的ellcc交叉编译器来编译它。

我在 stackoverflow 上看到了类似的问题(Add all elements in a Lane),但内在功能addv在我的主机上不起作用。

c arm simd llvm neon

3
推荐指数
1
解决办法
3065
查看次数

标签 统计

arm ×1

c ×1

llvm ×1

neon ×1

simd ×1