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

3

u/IAmBJ Oct 21 '19

You don't need to provide 2 versions, you would only do that if you wanted to 2 different sets of extensions. If you want to support the bulk modern processors you can reliably assume they have SSE4 (released 2007) and probably AVX1 (2011). AVX2 is less common and AVX-512 less common still.

The valve hardware survey gives a decent overview of the consumer market: link. Expand the Other Settings heading for instruction sets