gcc and xgetbv

Michael Dickens michaelld at macports.org
Thu Jan 24 19:02:19 PST 2013


I'm trying to compile gnuradio using configure.compiler=macports-gcc-4.7
to see if their SIMD detection is working (a component they call VOLK). 
VOLK was originally designed for GCC-based compilers, and they are
working on augmenting for CLANG.  I've been told, and a quick internet
search ("xgetbv") agrees, that the following code snippet should be
appropriate to use for GCC >= 4.4:

{{{
#if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 4
static inline unsigned long long _xgetbv(unsigned int index){
  unsigned int eax, edx;
  __asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index));
  return ((unsigned long long)edx << 32) | eax;
}
#else
#define _xgetbv() 0
#endif
}}}

but, this code does not compile using MacPorts' gcc 4.7; it errors out
with "no such instruction: `xgetbv'". Apple's clang compiles this code
without the #if, but it errors out when running with "Illegal
instruction: 4".  Ditto for MacPorts' clang 3.1. If I change the __asm__
line to us the raw opcode instead:

{{{
  __asm__ (".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c"
  (index));
}}}

then gcc 4.7 compiles it, but returns the same runtime error as with
clang. Hence I'm guessing that my CPU does not support this instruction.
I'm using a 2009 MacBook Pro with Core 2 Duo, 10.8 with most recent OS
and Xcode tools; latest MacPorts from SVN trunk. Can anyone tell me
what's going on, and/or provide any advice on why GCC 4.7 isn't allowing
this instruction?  Thanks! - MLD


More information about the macports-dev mailing list