This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: target_clones constexpr
- From: Victor Rodriguez <vm dot rod25 at gmail dot com>
- To: Mason <slash dot tmp at free dot fr>
- Cc: Roland Schulz <roland dot schulz at intel dot com>, Billy O Mahony <billy dot o dot mahony at intel dot com>, GCC help <gcc-help at gcc dot gnu dot org>, Evgeny Stupachenko <evstupac at gmail dot com>, Jakub Jelinek <jakub at redhat dot com>
- Date: Thu, 11 Jan 2018 10:57:03 -0600
- Subject: Re: target_clones constexpr
- Authentication-results: sourceware.org; auth=none
- References: <BF759D1B2ACA754496CB1E61835C71EA568C66@ORSMSX109.amr.corp.intel.com> <c8609fcb-c4af-3af2-4e84-069f7d372cea@free.fr>
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