Is it possible to enable an enhanced instruction set (SSE/AVX) for a single function or file within a visual studio project? I'd like to have multiple versions of a function which target different instruction sets, all within the same output binary
1 Answers
It is not possible to enable custom instruction set for a single function or a single file. However, you can enable custom instruction set for a single translation unit, which is usually a c/cpp file. Note that the instruction set used in headers depends on how the translation unit is compiled (which includes it) and may be different in different cpp files.
I suppose that if you compile different cpp files with different instruction sets, you can then link them together, and the resulting binary would work. Actually, it is important to ensure that calling conventions are compatible everywhere, and I think they would be, unless you use something like __vectorcall
(it requires at least SSE2 BTW).
If you want to compile some functions with multiple instruction sets, you might want to look at the this question. In overall it is called "CPU dispatch"