Reputation: 171
I got a compile error "argument must be a constant" when using NEON intrinsic vshr_n_u32
. The function prototype is:
__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);
}
And here is my function:
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);
}
The value of n_val
only can be known at run-time. But according to compile error, it seems that the value of n_val
should be known at compile-time. Although the type of __b
is const int
, I think it should be right to input an int variable.
How to remove the compile error? Or how to use vshr_n_u32
in this function?
Upvotes: 1
Views: 3428
Reputation: 212979
The shift in 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 with a negative shift (you pass a second int32x2_t
parameter containing the shift values).
Upvotes: 3