_mm256_load_si256: How to achieve data alignment?

Hi everyone.
This simple question is related with SIMD, intel avx and bit programming.
I got a Address boundary error when I call _mm256_load_si256 to load 256 bit data. They are actually 32 * 8 bit uint8_t int.
I suppose that the error came, because my data is not aligned (?).
So I would like to post part of code and let's discuss how to align data and load successfully.
1
2
3
4
5
6
7
  // basic try with _mm256_load_si256
  uint8_t array[1 << 8];
  for (size_t i = 0; i < 1 << 8; ++i) {
    array[i] = i;
  }
  __m256i attributeVec = _mm256_load_si256(reinterpret_cast<__m256i*>((array))); 

Simple word to the example code: I am sure that the array has uint8_t from 0 to 255, and we have 8 * 256 bit which is also larger than 256 bit form __m256i. The values start from array as a pointer, so this 256 values are also aligned (are they?)



Last edited on
1
2
3
4
5
6
7
8

 alignas(32) uint8_t array[1 << 8];
  std::cout << "data              = " << (void*)array << std::endl;
  for (size_t i = 0; i < 1 << 8; ++i) {
    array[i] = i;
  }
  __m256i attributeVec = _mm256_load_si256(reinterpret_cast<__m256i*>((array + 32)));
Last edited on
Topic archived. No new replies allowed.