On Thursday 19 August 2010 09:17:18 Rémi Denis-Courmont wrote:
> > I wish there was a way to use the intrinsics specifically for a portion
> > of the code.
> 
> In most recent GCC versions, you can change architecture parameters with a
> function granularity using a new function attribute. Those are the examples
> from the documentation:
> __attribute__((__target__("arch=core2")))
> __attribute__((__target__("sse3")))
> 
> But I am not sure if/when it will be supported on ARM.

That doesn't help because the __SSSE3___ define doesn't get suddenly defined in 
that section, so I can't #include <tmmintrin.h>.

This requires an inverted solution: pass -mavx to the compiler and do this 
right at the beginning:

#include <immintrin.h>
#pragma GCC target("i686")

Yes, I know that there is no processor yet that supports AVX. But passing the 
flag sets all the #defines required for including the intrinsics files.

Or a more complex solution:

#ifndef __AVX__
# define __AVX__
# ifndef __SSE4_1__
#  define __SSE4_1__
#  ifndef __SSSE3__
#   define __SSSE3__
#   ifndef __SSE3__
#    define __SSE3__
#    ifndef __SSE2__
#     define __SSE2__
#     include <emmintrin.h>
#     undef __SSE2__
#    endif
#    include <pmmintrin.h>
#    undef __SSE3__
#   endif
#   include <tmmintrin.h>
#   undef __SSSE3__
#   endif
#  include <nmmintrin.h>
#  undef __SSE4_1__
# endif
# include <immintrin.h>
# undef __AVX__
#endif

This is not checking whether the header actually exists. The solution with 
separate compilation units solves the problem because the compiler flag doesn't 
exist without the header.

And this is, of course, GCC-specific. It's not required for the Intel compiler, 
for example.

A third solution is to forego the intrinsics and write assembly code.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
MeeGo-dev mailing list
[email protected]
http://lists.meego.com/listinfo/meego-dev

Reply via email to