Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Accessing raw CPUID information is actually very easy, here is a C++ class for that which works in Windows, Linux and OSX:</p> <pre><code>#ifndef CPUID_H #define CPUID_H #ifdef _WIN32 #include &lt;limits.h&gt; #include &lt;intrin.h&gt; typedef unsigned __int32 uint32_t; #else #include &lt;stdint.h&gt; #endif class CPUID { uint32_t regs[4]; public: explicit CPUID(unsigned i) { #ifdef _WIN32 __cpuid((int *)regs, (int)i); #else asm volatile ("cpuid" : "=a" (regs[0]), "=b" (regs[1]), "=c" (regs[2]), "=d" (regs[3]) : "a" (i), "c" (0)); // ECX is set to zero for CPUID function 4 #endif } const uint32_t &amp;EAX() const {return regs[0];} const uint32_t &amp;EBX() const {return regs[1];} const uint32_t &amp;ECX() const {return regs[2];} const uint32_t &amp;EDX() const {return regs[3];} }; #endif // CPUID_H </code></pre> <p>To use it just instantiate an instance of the class, load the CPUID instruction you are interested in and examine the registers. For example:</p> <pre><code>#include "CPUID.h" #include &lt;iostream&gt; #include &lt;string&gt; using namespace std; int main(int argc, char *argv[]) { CPUID cpuID(0); // Get CPU vendor string vendor; vendor += string((const char *)&amp;cpuID.EBX(), 4); vendor += string((const char *)&amp;cpuID.EDX(), 4); vendor += string((const char *)&amp;cpuID.ECX(), 4); cout &lt;&lt; "CPU vendor = " &lt;&lt; vendor &lt;&lt; endl; return 0; } </code></pre> <p>This Wikipedia page tells you how to use CPUID: <a href="http://en.wikipedia.org/wiki/CPUID">http://en.wikipedia.org/wiki/CPUID</a></p> <p><strong>EDIT:</strong> Added <code>#include &lt;intrin.h&gt;</code> for Windows, per comments.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload