https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78379
--- Comment #13 from Thomas Koenig <tkoenig at gcc dot gnu.org> --- OK, I think I have a rough idea how to do this. For querying the CPU model, we need to put the interface in libgcc/config/i386/cpuinfo.c into a separate header. Then we generate a list of matmul functions using m4, with a second parameter, which gives us the architecture, such as in $(M4) -Dfile=$@ -Darch=avx512f ... In the generated C files, we enclose the whole content inside HAVE_AVX512F, so nothing happens if the architecture is not supported by the compiler. The target attribute is also set there. On the first call to matmul, we check for the availability of AVX etc, we also check for prefrences such as AVX128 from the CPU model, and then set a static function pointer to the function we want to call. On each subsequent invocation, all we do is that (tail) call. How does this sound?