简体   繁体   English

我可以处理__m128i中包含的4 int32_t吗?

[英]Can I work on the 4 int32_t contained in a __m128i?

I would like to have a __m128i variable, and do some operation like this: 我想要一个__m128i变量,并执行以下操作:

unsigned char* myArray;
__m128i fourValues;

//Do some strange reference assignment, e.g.:
//int32_t& a = *((int32_t*) &fourValues);
//int32_t& b = *(((int32_t*) &fourValues) + 1);
//int32_t& c = *(((int32_t*) &fourValues) + 2);
//int32_t& d = *(((int32_t*) &fourValues) + 3);

for (int i =0; i < someSize; i+=4) {
  a = d + myArray[i];
  b = a + myArray[i+1];
  c = b + myArray[i+2];
  d = c + myArray[i+3];
  //Do something with fourValues;
  }

where a,b,c,d are (or behave as) int32_t variables, and are the first, second, third and fourth 32bits of fourValues. 其中a,b,c,d是int32_t变量(或表现为int32_t变量),并且是fourValues的第一,第二,第三和第四32位。 Is that possible? 那可能吗?

You can use 您可以使用

int _mm_extract_epi32( 
   __m128i a,
   const int ndx 
);

see - http://msdn.microsoft.com/en-us/library/bb531460%28v=vs.90%29.aspx 参见-http://msdn.microsoft.com/en-us/library/bb531460%28v=vs.90%29.aspx

EDIT: Note that this only works for int SSE vectors, I see there's quite a lot of debate going around here - Get member of __m128 by index? 编辑:请注意,这仅适用于int SSE向量,我看到这里有很多争论- 通过索引获取__m128成员? , which refers to a __m128, but in your case it should be possible to use that. ,它指的是__m128,但在您的情况下,可以使用它。 Still, always worth to get a heads up that this isn't generic enough for floats. 尽管如此,总值得提醒一下,这对于浮点数来说还不够通用。

For writing you can use the equivalient _mm_insert_epi32, as you point out. 如您所指出的,您可以使用等效的_mm_insert_epi32进行编写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM