1

Say for example in the case of x86-64 you have a program that makes use of avx-512 instructions or any other special purpose instruction, and the cpu in question does not support the instruction at the low level such as a haswell based cpu, how does this situation get resolved?

Is the program simply just not able to run (my first thought) or is there a way for the cpu to still run the program using the instructions it does support, however it will simply not receive the performance advantage offered by the instruction in question?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Deank
  • 13
  • 2

1 Answers1

3

If the program checks CPU features and avoids actually run unsupported instructions, you just miss out on performance. Libraries like x264 and x265 do this, setting function pointers when they start to versions of functions that are the best supported version for this CPU.

If you do run an unsupported instruction (e.g. because you compiled with gcc -O3 -march=skylake-avx512 to tell the compiler it could assume AVX-512 support) there are 2 possibilities:

  • It happens to decode as something else (which won't be the case for AVX-512, but does happen for example with lzcnt decoding as bsr).
  • The CPU raises a #UD exception (UnDefined instruction). The OS handles it and delivers a SIGILL (Illegal Instruction) to the process, or equivalent on non-POSIX OSes like Windows.
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Thanks for the speedy reply Peter. From what i can gather then, its all dependent on the programmer as to A) whether the compiler they used was made aware of specific uarchs and instructions supported by said uarch, and B) whether they include code that allows for the glossing over of unsupported instructions in order to prevent potential compatibility issues. i.e- the program being on the end of a hard termination by the OS if it attempts to carry out the unsupported instruction? – Deank Oct 27 '21 at 20:48
  • @Deank: If that answers your question, please use the accept checkmark under the vote arrows. – Peter Cordes Oct 27 '21 at 20:50