问题
I want to use intrinsics to increment the elements of a SIMD vector. The simplest way seems to be to add 1 to each element, like this:
(note:vec_inc
has been set to 1 before)
vec = _mm256_add_epi16 (vec, vec_inc);
but is there any special instruction to increment a vector? Like inc
in this page ? Or any other easier way ?
回答1:
The INC
instruction is not a SIMD level instruction, it operates on integer scalars.
As you and Paul already suggested, the simplest way is to add 1
to each vector element, which you can do by adding a vector of 1
s.
If you want to simulate an intrinsic, you can implement your own function:
inline __m256i _mm256_inc_epi16(__m256i a)
{
return _mm256_add_epi16(a, _mm256_set1_epi16(1));
}
For similar questions on x86 intrinsics in the future, you can find the collection of Intel ISA intrinsics at Intel's Intrinsics Guide. Also see the extensive resources documented under the x86 and sse tag info:
- x86 tag info
- sse tag info
来源:https://stackoverflow.com/questions/41086366/how-to-increment-a-vector-in-avx-avx2