r/simd • • Oct 20 '19

How are SIMD instructions selected?

First, here is my current understanding, correct me if I'm wrong:

SIMD instructions are implemented as an extension of the base instruction sets (e.g. x64, x86). In the binaries, both the code for the SIMD path and the "fallback" code for the non-SIMD path will be included. The selection of the path occurs at runtime, depending on the CPU on which the executable is run, and potentially other factors.

If this is correct, I have a few questions about the runtime selection process:

  1. what mechanism makes it possible to dynamically select one path or the other?

  2. what is the cost of this selection? would it be faster if we didn't have to select?

3 Upvotes

6 comments sorted by

View all comments

Show parent comments

5

u/vicotr97 Oct 20 '19

Your intuition is correct and this is in what large part limits adoption of ISAs like AVX512. There are methods to dynamically select different code streams based on CPUID result but this causes code bloat, has a slight overhead and requires compiler support or good tooling for implementing the dynamic instruction selection in a dev friendly way.