How to increment a vector in AVX/AVX2

本秂侑毒 提交于 2019-12-10 14:12:12

问题


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 1s.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!