This was a solved problem going back at least 10 years. At $oldjob, we would simply compile an entire section of project as a standalone DLL once wth AVX (it was SSEx something back then) and once without, then dynamically load the entire module - not call a single function.