Question

I'd like to perform a SIMD arithmetic right shift (i.e. shifting in the sign bit) by a constant amount on a NEON register using compiler intrinsics. Yet I cannot find this particular kind of shift in all those shift intrinsics mentionend in the documentation. Does NEON even support arithmetic shifts (though, it would be strange if it didn't) and I'm just too dumb to find it (or am looking for the wrong terminology)? Or maybe it is just the normal vshr(q)_n intrinsic and the kind of shift is decided by the signedness of the actual type used?

Was it helpful?

Solution

Ah, shifts on ARM-NEON. The sign-ness is easy to miss.

There is of course an arithmetic shift right instruction, and it is the same as the logical shift right instruction. You decide if you want to shift arithmetic or logic by picking the data-type.

E.g.

  int8x8_t   vshr_n_s8(int8x8_t a, int b);

Will shift arithmetic because the data-type is s8 while:

  uint8x8_t   vshr_n_u8(uint8x8_t a, int b);

will shift logically (shifing in zeros instead of replicating the sign bit) because the data-type is unsigned.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top