title: How do I call "cpuid" in Linux?
body: <p>While writing new code for Windows, I stumbled upon <code>_cpuinfo()</code> from the Windows API. As I am mainly dealing with a Linux environment (GCC) I want to have access to the CPUInfo.</p>
  <p>I have tried the following:</p>
  <pre><code>#include &lt;iostream&gt;
   
  int main()
  {
    int a, b;
   
    for (a = 0; a &lt; 5; a++)
    {
      __asm ( &quot;mov %1, %%eax; &quot;            // a into eax
            &quot;cpuid;&quot;
            &quot;mov %%eax, %0;&quot;             // eax into b
            :&quot;=r&quot;(b)                     // output
            :&quot;r&quot;(a)                      // input
            :&quot;%eax&quot;,&quot;%ebx&quot;,&quot;%ecx&quot;,&quot;%edx&quot; // clobbered register
           );
      std::cout &lt;&lt; &quot;The CPUID level &quot; &lt;&lt; a &lt;&lt; &quot; gives EAX= &quot; &lt;&lt; b &lt;&lt; '\n';
    }
   
    return 0;
  }
  </code></pre>
  <p>This use assembly but I don't want to re-invent the wheel. Is there any other way to implement CPUInfo without assembly?</p>