How to increase the vector in AVX / AVX2

I want to use intrinsics to increase the elements of a SIMD vector. The easiest way is to add 1 to each element, for example:

(note: vec_inc already set to 1)

 vec = _mm256_add_epi16 (vec, vec_inc); 

but is there any special instruction for incrementing a vector? How inc in this page ? Or any other easier way?

+5
source share
1 answer

The INC instruction is not a SIMD level instruction, it works with whole scalars. As you and Paul have already suggested, the easiest way is to add 1 to each vector element that you can make by adding the vector 1 s.

If you want to simulate the internal, you can implement your own function:

 inline __m256i _mm256_inc_epi16(__m256i a) { return _mm256_add_epi16(a, _mm256_set1_epi16(1)); } 

For similar x86 issues in the future, you can find a collection of Intel ISA built-in features in the Intel Intrinsics Guide . Also see the Extensive resources documented in the and tag:

+7
source

Source: https://habr.com/ru/post/1261105/


All Articles