Function multiversioning question

Martin Reinecke martin@MPA-Garching.MPG.DE
Thu Oct 25 12:35:00 GMT 2018


Hi Jonathan,

thanks for the quick reply!

> Macros are defined during preprocessing, and the preprocessor doesn't
> know anything about the target_clones attribute. When the compiler
> sees the attribute it can't go back in time and alter the result of
> earlier preprocessing.

I feared as much.
This creates a nasty asymmetry in the sense that gcc's own optimizations
will be able to use all target features (because the compiler knows that
it is OK to use specific features like AVX instructions) whereas the
user has no way to hand-optimize where this becomes necessary. At least
not using this nice mechanism.

>> Is there a way to achieve what I have in mind?
> 
> If you want three different implementations of the function I think
> you need three different clones. Or do runtime checks for the CPU
> features inside the function, but that seems suboptimal.

I guess I'll just put all functions in question in a separate file and
compile this with different flags and name prefixes.

Cheers,
  Martin



More information about the Gcc-help mailing list