Function multiversioning question
Marc Glisse
marc.glisse@inria.fr
Thu Oct 25 12:50:00 GMT 2018
On Thu, 25 Oct 2018, Martin Reinecke wrote:
> 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.
target_clones does nothing magic, you can also look at target and ifunc.
https://gcc.gnu.org/wiki/FunctionMultiVersioning
--
Marc Glisse
More information about the Gcc-help
mailing list