title: Why is -march=native used so rarely?
body: <p>With most C/C++ compilers, there's a flag passable to the compiler, <code>-march=native</code>, which tells the compiler to tune generated code for the micro-architecture and ISA extensions of the host CPU. Even if it doesn't go by the same name, there's typically an equivalent option for LLVM-based compilers, like <code>rustc</code> or <code>swiftc</code>.</p>
  
  <p>In my own experience, this flag can provide massive speedups for numerically-intensive code, and it <em>sounds</em> like it would be free of compromises for code you're just compiling for your own machine. That said, I don't think I've seen any build system or static compiler that enables it by default:</p>
  
  <ul>
  <li><p>Obviously, any command-line compiler executable that requires you to pass it doesn't use it by default.</p></li>
  <li><p>I can't think of any IDE that enables this by default.</p></li>
  <li><p>I can't think of any common build system I've worked with (<code>cmake</code>, <code>automake</code>, <code>cargo</code>, <code>spm</code>, etc.) that enables it by default, even for optimized builds.</p></li>
  </ul>
  
  <p>I can think of a few reasons for this, but none of them are really satisfactory:</p>
  
  <ul>
  <li><p>Using <code>-march=native</code> is inappropriate for binaries that will be distributed to other machines. That said, I find myself compiling sources for my own machine much more often than for others, and this doesn't explain its lack of use in debug builds, where there's no intention for distribution.</p></li>
  <li><p>At least on Intel x86 CPUs, it's my understanding that using AVX instructions infrequently could degrade performance or power efficiency, since the AVX unit is powered down when not in use, requiring it to be powered up to be used, and a lot of Intel CPUs downclock to run AVX instructions. Still, it only explains why AVX wouldn't be enabled, not why the code wouldn't be tuned for the particular micro-architecture's handling of regular instructions.</p></li>
  <li><p>Since most x86 CPUs use fancy out-of-order superscalar pipelines with register renaming, tuning code for a particular micro-architecture probably isn't particularly important. Still, if it <em>could</em> help, why not use it?</p></li>
  </ul>