Hi Ruoyao, Okay, that makes sense. That's one method I was considering but wasn't entirely happy with as for testing I use #defines to control which versions I build and using different compiles would mean a makefile change. I'm thinking now that I could do my own #define just before each target code. I still can't use target_clones and have to triplicate the code but the code would be identical except with a few conditional bits. Another method I've considered trying was whether I could have target specific inlined functions that get inlined in the target_clones making each different. I'll keep plugging away at it. Thanks, Colin On Thu, Feb 14, 2019 at 11:43 PM Xi Ruoyao <xry111@xxxxxxxxxxxxxxxx> wrote: > On 2019-02-14 22:54 +0800, Colin Hercus wrote: > > Hi, > > > > I have several functions using SIMD intrinsics with target specific > > versions for SSE2, SSSE3, SSE4.1, AVX. They all use packed 8bit ints and > > only 128bit data. > > > > As I'm using intrinsics, each version target is slightly different, SSSE3 > > has _mm_shuffle_epi8, SSE4.1 has _mm_blendv_epi8. Because I need to use > > only a few different intrinsics for each target the code is 95% > > triplicated. Luckily the AVX code can be a target_clone of the SSE4.1 > > version but the others are slightly different. > > > > Is it possible to have code conditional on the target like #ifdef > > __TARGET_AVX2_ > > that might let me have one source code with a few small conditional > > segments? > > No. Because the preprocessor doesn't know what is "target attribute". > > > I tried using #ifdef __AVX__ which works if I select an AVX target on the > > GCC command but doesn't work in a function with __attribute__ ((target > > ("avx"))) > > I suggest to compile one source file with -msse3, -mavx, -mavx2, etc. to > get > multiple object files. > -- > Xi Ruoyao <xry111@xxxxxxxxxxxxxxxx> > School of Aerospace Science and Technology, Xidian University > >