Search code examples
macosg++macportsavx

g++: No Such Instruction with AVX


When I compiled a program I was writing in C++ (for the latest Macbook pro, which of course supports the AVX instruction set), I got the following errors. I am using the latest release of g++ obtained from Macports. Do you have any ideas as to what I can do to fix the error without restricting the instruction sets available to the compiler? Is there any package in particular that I should try to update?

g++-mp-4.7 -std=c++11 -Wall -Ofast -march=native -fno-rtti src/raw_to_json.cpp -o bin/raw_to_json.bin
/var/folders/83/tjczqmxn1y9166m642_rxdlw0000gn/T//cc0hIx0w.s:1831:no such instruction: `vpxor %xmm0, %xmm0,%xmm0'
/var/folders/83/tjczqmxn1y9166m642_rxdlw0000gn/T//cc0hIx0w.s:1847:no such instruction: `vmovdqa %xmm0, 96(%rsp)'
/var/folders/83/tjczqmxn1y9166m642_rxdlw0000gn/T//cc0hIx0w.s:1848:no such instruction: `vmovdqa %xmm0, 112(%rsp)'
/var/folders/83/tjczqmxn1y9166m642_rxdlw0000gn/T//cc0hIx0w.s:1849:no such instruction: `vmovdqa %xmm0, 128(%rsp)'
/var/folders/83/tjczqmxn1y9166m642_rxdlw0000gn/T//cc0hIx0w.s:1850:no such instruction: `vmovdqa %xmm0, 144(%rsp)'
/var/folders/83/tjczqmxn1y9166m642_rxdlw0000gn/T//cc0hIx0w.s:1851:no such instruction: `vmovdqa %xmm0, 160(%rsp)'

Thanks for the help!


Solution

  • Fixed thanks to Conrado PLG's answer to his own question here. In short, I had to do the following:

    1. Move or otherwise get rid of the old as, found at /opt/local/bin/../local/libexec/as/x86_64/as.
    2. Copy the script by Vincent Habchi, found here, to /opt/local/bin/../local/libexec/as/x86_64/as.
    3. sudo chmod +x the script.

    Note that there may some performance degradation, due to the fact that calling the assembler requires going through a shell script first.