无法使用 AVX512 编译 C++ 程序?

Cannot compile a C++ program using AVX512?

编译程序 (test.cpp) 时出现以下错误:

> g++ -o test test.cpp -O2 -mavx -msse4.1
test.cpp: In function ‘int main(int, char**)’:
test.cpp:18:42: error: ‘_mm_rorv_epi32’ was not declared in this scope
   indice = _mm_rorv_epi32(indice, offset4);
                                          ^

程序(main.cpp):

#include <stdio.h>
#include <stdlib.h>
#include <immintrin.h>

int main(int argc, char* argv[]) {
  float values[4] = {1., 2., 3., 4.};
  __m128i offset4 = _mm_set_epi32(0, 2, 4, 6);
  __m128i mask4 = _mm_set_epi32(3, 3, 3, 3);
  __m128 value4 = _mm_load_ps(&values[0]);
  __m128 res;

  float result[4];

  // load a constant integer 4 times
  __m128i indice = _mm_set1_epi32(123);  // 123 is a fake example

  // shift
  indice = _mm_rorv_epi32(indice, offset4);
  // and
  indice = _mm_and_si128(indice, mask4);

  // lookup
  res = _mm_permutevar_ps(value4, indice);
  // store
  _mm_store_ps(result, res);

  for (int i = 0; i < 4; i++) {
    printf("result[%d] = %g\n", i, result[i]);
  }
  return 0;
}

我确实根据 Intel 手册包含了头文件 immintrin.hg++ 版本是 4.9.3.

如何解决编译问题并使用_mm_rorv_epi32?

_mm_rorv_epi32

根据Intel page on _mm_rorv_epi32, this intrinsic requires avx512f and avx512vl. You need to compile with -mavx512vl to enable it (and your gcc is too old -- -mavx512vl was added in gcc-5.1).