2015-12-07 21:41:20 UTC
This is a new/upcoming gcc feature that we might find useful:
"GCC's function attribute feature has been extended to support another
attribute: target_clones (<options>). This is used to specify that a
function is to be cloned into multiple versions compiled with different
target options than specified on the command line. The supported
options and restrictions are the same as for target attribute.
For instance on an x86, you could compile a function with
target_clones("sse4.1,avx"). It will create 2 function clones, one
compiled with -msse4.1 and another with -mavx. At the function call it
will create resolver ifunc, that will dynamically call a clone suitable
for current architecture."
I found that this was discussed on the gcc-patches list (along with
actual gcc patches implementing the feature) in October. It is unclear
to me whether this made it, or will make it soon, into an official gcc