0

Basically the title. For example, I am trying to run instructions like:

_mm256_load_pd, _mm256_add_pd, _mm256_stream_pd and the 128 bits version on the processor: Intel Xeon, E5630, 2.53 GHz, IBM HS22. But I am getting Illegal instruction any idea for a site where I could see which functions are available for this processor?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
C. Cristi
  • 569
  • 1
  • 7
  • 21

1 Answers1

1

Check your /proc/cpuinfo if you're on an OS that has one.

Or use clang or gcc -march=native - they will refuse to compile any intrinsics your CPU doesn't support. (Unlike MSVC or ICC, which will let you use intrinsics without telling it that the target machine supports them.)


To look it up by CPU model, google the model, e.g. Xeon, E5630 -> https://ark.intel.com/content/www/us/en/ark/products/47924/intel-xeon-processor-e5630-12m-cache-2-53-ghz-5-86-gt-s-intel-qpi.html

  • Instruction Set Extensions: Intel® SSE4.2

So no AVX at all, because it's a Westmere-EP microarchitecture from 2010 (before Sandybridge.)

For more detail CPUs, you can also check http://instlatx64.atw.hu/ and check the CPUID dump for that model (or one of the same microarchitecture), if you can find one. e.g. a screenshot of Aida64 CPUID running on a Westmere-EX, and instruction latency/throughput benchmark output, with info at the top of the text file including decoded CPUID info showing which ISA extensions it has. Also raw CPUID dumps which you can cross-reference with the CPUID feature-bit required (https://sandpile.org/x86/cpuid.htm) by any extension you're interested in (like cmpxchg16b or FSGSBASE that Intel's ark pages won't mention.).


related: https://software.intel.com/sites/landingpage/IntrinsicsGuide/ tells you what ISA extension is required by the corresponding asm instruction for each intrinsic.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    On macOS: `sysctl machdep.cpu.features machdep.cpu.leaf7_features` – Paul R May 02 '21 at 12:14
  • Hello, thank you for your answer! Can you show me a way to check for that in the C code? To run that code only if it has AVX512 or AVX2? Maybe some Macro IFs – C. Cristi May 02 '21 at 14:03
  • 1
    @C.Cristi: That's a separate question. You can of course detect at build-time with `#if __AVX__`, if you want people to compile your code with `-march=native` on their own machines. If you want to do runtime dispatching (e.g. setting function pointers), you need to pick large-enough functions to be worth branching for (e.g. making them not inlineable), but you can use GCC's `ifunc` stuff, or roll your own with `__builtin_cpu_supports("avx")` or whatever in GNU C. Search google / Stack Overflow for more. – Peter Cordes May 02 '21 at 14:07
  • @PeterCordes So, for AVX2 we have `#if __AVX__`, and for AVX512 we have `#if __AVX512__`? and compiling ofcourse with `-march=native`, and should be good to go, right? – C. Cristi May 02 '21 at 14:13
  • 1
    @C.Cristi: yes, if you're not using MSVC, this all works very nicely using `-march=native`. MSVC is designed around a model of building one binary that you distribute, and has no equivalent option to build a binary that targets the host specifically. So it sounds like for your purposes, you want `gcc` or `clang` `-O3 -march=native`, possibly with -ffast-math, etc. etc. (definitely `-fno-math-errno`). – Peter Cordes May 02 '21 at 14:17
  • 2
    For the specific macros, google is your friend: [How to detect SSE/SSE2/AVX/AVX2/AVX-512/AVX-128-FMA/KCVI availability at compile-time?](https://stackoverflow.com/q/28939652) was the first hit for `gcc macro avx avx512` – Peter Cordes May 02 '21 at 14:17