title: How does mtune actually work?
body: <p>There's this related question: <a href="https://stackoverflow.com/q/10559275/3258851">GCC: how is march different from mtune?</a></p>
  
  <p>However, the existing answers don't go much further than the GCC manual itself. At most, we get:</p>
  
  <blockquote>
    <p>If you use <code>-mtune</code>, then the compiler will generate code that works on
    any of them, but will favour instruction sequences that run fastest on
    the specific CPU you indicated.</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>The <code>-mtune=Y</code> option tunes the generated code to run faster on Y than
    on other CPUs it might run on.</p>
  </blockquote>
  
  <p>But exactly <em>how</em> does GCC favor one specific architecture, when bulding, while still being capable of running the build on other (usually older) architectures, albeit slower?</p>
  
  <p>I only know of one thing (but I'm no computer scientist) which would be capable of such, and that's a CPU dispatcher. However, it doesn't seem (for me) that <code>mtune</code> is generating a dispatcher behind the scenes, and instead some other mechanism is probably in effect.</p>
  
  <p>I feel that way for two reasons:</p>
  
  <ol>
  <li>Searching "gcc mtune cpu dispatcher" doesn't find anything relevant; and</li>
  <li>If it was based on dispatcher, I think it could be smarter (even if by some option other than <code>mtune</code>) and test for <code>cpuid</code> to detect supported instructions at runtime, instead of relying on a named architecture which is provided at build time.</li>
  </ol>
  
  <p>So how does it work really?</p>