如何在AVX/AVX2中增加向量 [英] How to increment a vector in AVX/AVX2

查看:154
本文介绍了如何在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 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));
}


对于将来有关x86内在函数的类似问题,您可以在英特尔的内部指南.另请参阅标记信息:


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆