This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: target_clones constexpr


On Thu, Jan 11, 2018 at 3:10 AM, Mason <slash.tmp@free.fr> wrote:
> On 11/01/2018 03:44, Roland Schulz wrote:
>
>> Is it possible to have a "if constexpr" inside a __target_clones__
>> multiversioned function to have certain parts of the function depend
>> on the target? Outside of multiversioned function one normally would
>> use preprocessor defines to query the SIMD support (e.g. __AVX__).
>> But this doesn't work inside target_clones given that preprocessor
>> variables don't depend on the target. __builtin_cpu_supports doesn't
>> work because it isn't constexpr (and is meant for runtime detection).
>> One could extract the target specific part into its own function
>> (using target rather than target_clones attribute) but that doesn't
>> work with different types. Is there some other way to query the
>> target which does work inside a multiversioned function?
>
> I've CCed a few people involved in function multi-versioning.
>
> Also, Billy O'Mahony used to work on FMV.
>
> The following article might be interesting to you:
> https://lwn.net/Articles/691932/
>
> Regards.


Hi

Are you looking for simething like this ?


#include <stdio.h>
#include <immintrin.h>

#define MAX 1000000
    int a[256], b[256], c[256];

    __attribute__((target_clones("avx2","arch=atom","default")))
    void foo(){
        int i,x;

for (x=0; x<MAX; x++){
    for (i=0; i<256; i++){
a[i] = b[i] + c[i];
    }
}
    }

int main() {

     if (__builtin_cpu_supports ("ssse3")){
         printf("System supprot SSE\n");
     }
     if (__builtin_cpu_supports ("avx2")){
         printf("System support AVX2\n");
     }
     if (__builtin_cpu_supports ("avx512f")){
         printf("System supports AVX 512\n");
     }

     foo();
        return 0;
    }


# gcc fmv.c -O3 -o fmv

# ./fmv
System supprot  SSE
System support AVX2

more info here :

https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/X86-Built-in-Functions.html

once in the specific function you can also use

#pragma GCC target

https://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Function-Specific-Option-Pragmas.html

Hope it helps

Regards

Victor Rodriguez


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]