Target specific functions with intrinsics

Hi,

This is a GCC question more than C,C++ so if its the wrong place please suggest a better place to ask :)

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.

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?

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")))

gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0

Any suggestions?

Thanks, Colin
Topic archived. No new replies allowed.