NEON 内在,使用 vshr_n_u32 时编译错误 "argument must be a constant"
NEON intrinsic, compile error "argument must be a constant" when using vshr_n_u32
我在使用 NEON 内部 vshr_n_u32
时遇到编译错误 "argument must be a constant"。函数原型为:
__extension__ static __inline uint32x2_t __attribute__ ((__always_inline__))
vshr_n_u32 (uint32x2_t __a, const int __b)
{
return (uint32x2_t)__builtin_neon_vshr_nv2si ((int32x2_t) __a, __b, 0);
}
这是我的函数:
uint32x2_t shift_func(int index)
{
int shift_bit[] = {2, 4, 5, 6, 7, 8, 9, 10};
int n_val = shift_bit[index];
uint32x2_t src_reg = {16, 32};
return vshr_n_u32(src_reg, n_val);
}
n_val
的值只能在 运行 时知道。但是根据编译错误,似乎 n_val
的值应该在编译时就知道了。虽然__b
的类型是const int
,但我觉得输入一个int变量应该是对的
如何消除编译错误?或者如何在这个函数中使用vshr_n_u32
?
vshr_n_u32 has to be a compile-time literal constant, as the shift value is encoded as part of the ARM instruction itself. Since you only have a few possible shift values then you might want to use a switch
statement to handle each case. Or you could just use vshl_u32 中的偏移为负偏移(您传递第二个包含偏移值的 int32x2_t
参数)。
我在使用 NEON 内部 vshr_n_u32
时遇到编译错误 "argument must be a constant"。函数原型为:
__extension__ static __inline uint32x2_t __attribute__ ((__always_inline__))
vshr_n_u32 (uint32x2_t __a, const int __b)
{
return (uint32x2_t)__builtin_neon_vshr_nv2si ((int32x2_t) __a, __b, 0);
}
这是我的函数:
uint32x2_t shift_func(int index)
{
int shift_bit[] = {2, 4, 5, 6, 7, 8, 9, 10};
int n_val = shift_bit[index];
uint32x2_t src_reg = {16, 32};
return vshr_n_u32(src_reg, n_val);
}
n_val
的值只能在 运行 时知道。但是根据编译错误,似乎 n_val
的值应该在编译时就知道了。虽然__b
的类型是const int
,但我觉得输入一个int变量应该是对的
如何消除编译错误?或者如何在这个函数中使用vshr_n_u32
?
vshr_n_u32 has to be a compile-time literal constant, as the shift value is encoded as part of the ARM instruction itself. Since you only have a few possible shift values then you might want to use a switch
statement to handle each case. Or you could just use vshl_u32 中的偏移为负偏移(您传递第二个包含偏移值的 int32x2_t
参数)。