title: gcc: Enable AVX on AMD
body: <p>I have been trying to get AVX to run properly yet I am not able to compile my c++ project.
  I am new to C++ and the compiling so I use CMake together with CLion and GCC.</p>
  <p><a href="https://i.stack.imgur.com/V6ebn.png" rel="noreferrer"><img src="https://i.stack.imgur.com/V6ebn.png" alt="enter image description here" /></a></p>
  <p>I know that my processor supports AVX and AVX2 and I wrote a simple test program:</p>
  <pre><code>
  #include &lt;immintrin.h&gt;
  ...
  
      __m256 A{};
      __m256 B{};
      __m256 AB = _mm256_add_ps(A,B);
      
      for(int i = 0; i &lt; 8; i++){
          std::cout &lt;&lt; AB[i] &lt;&lt; std::endl;
      }
  </code></pre>
  <p>Sadly when trying to run this, I get the following error:</p>
  <pre><code>warning: AVX vector return without AVX enabled changes the ABI [-Wpsabi]
     91 |     __m256 AB = _mm256_add_ps(A,B);
        |                                  ^
  In file included from C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/10.1.0/include/immintrin.h:51,
                   from A:\OneDrive\ProgrammSpeicher\CLionProjects\Koivisto\src_files\main.cpp:85:
  C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/10.1.0/include/avxintrin.h:147:1: error: inlining failed in call to 'always_inline' '__m256 _mm256_add_ps(__m256, __m256)': target specific option mismatch
    147 | _mm256_add_ps (__m256 __A, __m256 __B)
  
  
  </code></pre>
  <p>I assume I need to set some flag in my CmakeLists.txt but I didnt find anything for this on the web.</p>
  <p>I am very happy if someone could help me out!</p>
  <p>Greetings,
  Finn</p>
  <h1>SOLUTION</h1>
  <p>I had to add</p>
  <pre><code>set(CMAKE_CXX_FLAGS &quot;${CMAKE_CXX_FLAGS} -march=native&quot;)
  </code></pre>
  <p>and it will compile nicely.</p>