Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 946
void-pointer Avatar asked Aug 18 '12 06:08

void-pointer


2 Answers

A simpler solution that fixed this problem for me was adding -Wa,-q to the compiler flags. From the man pages for as (version 1.38):

-q Use the clang(1) integrated assembler instead of the GNU based system assembler.

like image 113
capisce Avatar answered Sep 23 '22 10:09

capisce


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.

like image 35
void-pointer Avatar answered Sep 22 '22 10:09

void-pointer