> * Case II - User Guided Versioning where the function bodies for each > version differ and is provided by the user. > > This case pertains to multi-versioning when the source bodies of the > two or more versions are different and are provided by the user. Here > too, I want to use a new attribute, “version”. Now, the user can > specify versioning intent like this: > > int __attribute__((version(“popcnt”)) > find_popcnt(unsigned int i) > { > // inline assembly of the popcnt instruction, specialized version. > asm(“popcnt ….”); > } > > int > find_popcnt(unsigned int i) > { > //generic code for doing this > ... > } > > This uses function overloading to specify versions. The compiler will > understand that versioning is requested, since the functions have > different attributes with "version", and will generate the code to > execute the right function at run-time. The compiler should check for > the existence of one body without the attribute which will be the > default version.
The use of function overloading is discussed in http://gcc.gnu.org/ml/gcc-patches/2011-05/msg00150.html > > * Case III - Versioning is done automatically by the compiler. > > I want to add a new compiler flag “-mversion” along the lines of “-m”. > If the user specifies “-mversion=popcnt” then the compiler will > automatically create two versions of any function that is impacted by > the new instruction. The difference between “-m” and “-mversion” will > be that while “-m” generates only the specialized version, “-mversion” > will generate both the specialized and the generic versions. There is > no need to explicity mark any function for versioning, no source > changes. -mversion=targ1,targ2,.. or -mversion=feature1,feature2 .. is a way to tell the compiler the set of target hardwares the program is going be running on. It is an extension of -mcpu=.... It is up to the compiler to decision whether MV is done or what function to be MVed. The __clone__ attribute proposed here (http://gcc.gnu.org/wiki/FunctionSpecificOpt) can be used together with -mversion=... to achieve the similar effect of version attribute mentioned above -- the difference is that version attribute is 'mandatory'. David > > The compiler will decide if it is beneficial to multi-version a > function based on heuristics using hotness information, code size > growth, etc. > > > Runtime support > =============== > > In order for the compiler to generate multi-versioned code, it needs > to call functions that would test if a particular feature exists or > not at run-time. For example, IsPopcntSupported() would be one such > function. I have prepared a patch to do this which adds the runtime > support in libgcc and supports new builtins to test the various > features. I will send the patch separately to keep the dicussions > focused. > > > Thoughts? > > Thanks, > -Sri. >