3 ms·
By default, most compilers will target some old processor with basic features, like perhaps SSE2. If you up the processor to something with AVX2, for example, y
by saagarjha 6y ago
By default, most compilers will target some old processor with basic features, like perhaps SSE2. If you up the processor to something with AVX2, for example, you’ll get those instructions but without anything else you will SIGILL on older computers.
Now, if you want to be smarter there’s a number of things you can do, some of which have compiler or OS support. You could, in your program, manually detect these features (cpuid) and then use them if available. You could have entire functions that are specialized for one architecture and pick the right one at runtime; some compilers can do this for you “transparently” with custom attributes. If the dynamic linker supports it, you could have it pick the right version of the symbol for your processor and your program is otherwise none the wiser which one gets selected; it just has to have the appropriate versions of functions. And at the extreme end you can compile entirely separate versions of your program for different base processors; on Darwin you can have a universal binary recognized by the kernel itself as supposing x86_64 (basic 64-bit features) and x86_64h (assume Haswell and above) and the right one will get loaded based on your hardware.