如何在AVX/AVX2中增加向量 [英] How to increment a vector in AVX/AVX2
问题描述
我想使用内在函数来增加SIMD向量的元素.最简单的方法似乎是在每个元素上加1,如下所示:
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:
(注意:vec_inc
之前已设置为1)
(note:vec_inc
has been set to 1 before)
vec = _mm256_add_epi16 (vec, vec_inc);
但是有增加矢量的特殊指令吗?像此页面中的inc
一样?还是其他更简单的方法?
but is there any special instruction to increment a vector? Like inc
in this page ? Or any other easier way ?
推荐答案
INC
指令不是SIMD级别指令,它在整数标量上运行.
正如您和Paul已经建议的那样,最简单的方法是将1
添加到每个vector元素,您可以通过添加1
s的矢量来实现.
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));
}
对于将来有关x86内在函数的类似问题,您可以在英特尔的内部指南.另请参阅 x86 和 sse 标记信息:
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
这篇关于如何在AVX/AVX2中增加向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!