【发布时间】:2017-04-14 21:23:55
【问题描述】:
这是我在车道中添加所有 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
我尝试将所有 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
有没有简单明了的方法来做到这一点?我希望 LLVM 汇编代码在编译后简洁明了。我也希望sum 的最终类型是 32 位。
我使用了基于 LLVM 编译器基础架构的 ellcc 交叉编译器来编译它。
我在 stackoverflow 上看到了类似的问题 (Add all elements in a lane),但内在的 addv 在我的主机上不起作用。
【问题讨论】:
-
为什么你觉得你的代码看起来效率低下?我看不到复杂的循环或分支。只是顺序。除了效率之外,您还试图解决其他问题吗?即代码是否执行了它应该执行的操作?
-
因为 LLVM 汇编代码在编译后很复杂,所以我想知道有没有更简单的方法来做到这一点,比如使用 neon 内在函数。
-
我的目标是通过 pass 自动生成 LLVM-IR,如果 LLVM-IR 代码很复杂,对我来说很难。