0

There is an instruction called _mm256_set1_epi8 in AVX which can set 32 8-bit integers inside a _m256i container to a specific value.

If I have an array of said 8-bit integers, how can I make it so that the __m256i container resulting from the _mm256_set1_epi8 operation overrides the char[32] container ?

I have not found any load or move instruction related to epi8 (8-bit signed integers) in either SSEx, or AVX. I guess there must be a way to achieve this as it seems not that complicated of a computation but I cannot find which instruction should be used to achieve that.

If it is not achievable using __m256i, would it be possible to achieve something similar with a __m128i ?

Code sample to illustrate the situation described above :

int _tmain(int argc, _TCHAR* argv[])
{
  // This is an array of 8-bit signed integers
  char charArray[32] = { 0, 1, 2, 3, 4, /*[...],*/ 30, 31 };

  // This is the value I want to set in the array at some point
  char valueToSet = 4;

  // This instruction makes it possible to set 32 8-bit signed integers at once
  __m256i eightBitIntegersRegistry = _mm256_set1_epi8(valueToSet);

  // How can I make it affect the charArray array?
  // In the end I would want the content of charArray to be { 4, 4, 4, [...] 4, 4, 4 }

  return 0;
}
Paul R
  • 208,748
  • 37
  • 389
  • 560
Norgannon
  • 487
  • 4
  • 16
  • 4
    This is fairly similar to [Store __m256i to integer](https://stackoverflow.com/questions/29517622/store-m256i-to-integer), it doesn't matter whether it's char or int or whatever, just cast the pointer. The alignment or lack of it does matter. – harold Sep 13 '19 at 09:08
  • 2
    I'll try that out, thanks a lot ! I'm not sure how to know if my array is memory-aligned or not so I'll try `_mm256_storeu_si256` by default. – Norgannon Sep 13 '19 at 09:16
  • 1
    I can confirm the other question's answer solves this. I think I should probably let this one up nonetheless as the other one is poorly named and didn't come up in my search ? – Norgannon Sep 13 '19 at 11:00

0 Answers0