gcc and xgetbv

Rainer Müller raimue at macports.org
Fri Jan 25 06:07:39 PST 2013


On 2013-01-25 14:15, vincent habchi wrote:
> 
> On 25 janv. 2013, at 04:02, Michael Dickens <michaelld at macports.org> wrote:
> 
>> 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.
> 
> Two things:
> 
> 1. You’ll never get any AVX instruction out of GCC compilers, because they all rely on the Apple provided /usr/bin/as which is hoary and do not know about new opposes like AVX;

To make this more clear, a C compiler does not touch the assembler
instructions in the __asm__() statement. Rather, these are passed down
in raw form to the assembler.

In Michael's case, clang passes this down to the the integrated
assembler in LLVM, but at runtime the CPU fails to execute as this
instruction is unknown.

When compiling the code with gcc-mp-4.7, it calls the assembler
/opt/local/bin/as (which is the same or even a newer version than
/usr/bin/as), however, this version does not understand the xgetbv
mnemonic. Of course you can still pass raw bytes, as the assembler would
not have anything else than translating the human-readable instruction
name to a byte sequence. However, the resulting binary will not work
either, as your CPU does not understand the instruction.

> 2. AVX means Sandy Bridge processors. I am not sure, but I’d bet your MacBook has a Core 2 Duo Penryn which is one generation older.

Use the following sysctl commands to retrieve information about
instruction sets supported by the current CPU:

  sysctl hw.optional
  sysctl machdep.cpu.features

Rainer


More information about the macports-dev mailing list