How do programs utilize new CPU instructions (e.g. AVX-512, Intel Quick Sync Video) while still being able to run on older CPUs?

316 views

New instruction sets can improve performance but it is difficult to distribute your program if most people’s computers cannot run the program. When compiling an executable to distribute, it either has code that uses or doesn’t certain CPU instructions. The only way around it I can think of is compiling multiple libraries for every function that may use a new instruction set, one with the new instruction set and other without. Then you detect which CPU you have and dynamically load the proper library at runtime.

In: 2

3 Answers

Anonymous 0 Comments

You are basically describing exactly what they do. There is an instruction called CPUID which can be used to get the features supported by the CPU. This is then used to switch between different versions of the code. It is not necessarily the entire library, maybe just a function or two. So it is generally not much work to keep two version.

You are viewing 1 out of 3 answers, click here to view all answers.