Skip to content

Instantly share code, notes, and snippets.

@boxmein
Created May 16, 2014 23:42
Show Gist options
  • Save boxmein/7d8e5fae7febafc5851e to your computer and use it in GitHub Desktop.
Save boxmein/7d8e5fae7febafc5851e to your computer and use it in GitHub Desktop.
// Queries the computer for the cpuid bits and tries detailing the results.
//# vcvars32 & cl __cpuid.c
// See http://msdn.microsoft.com/en-us/library/hskdteyh(v=vs.90).aspx
// Not sure what to do for Linux.
#include <stdio.h>
#include <intrin.h>
int main(int argc, char *argv[]) {
int cpuinfo[4];
printf("CPU identification thing\n"
"prints out various data the cpuid instruction returns\n"
"instructions marked with an asterisk (*) are Intel-only\n"
"approximated from http://msdn.microsoft.com/en-us/library/hskdteyh(v=vs.90).aspx\n\n");
//
// 0 - Ident string
//
__cpuid(cpuinfo, 0);
printf("- __cpuid(0) -\n ident string: %c%c%c%c%c%c%c%c%c%c%c%c\n",
cpuinfo[1] &0xff,
cpuinfo[1] >> 8 &0xff,
cpuinfo[1] >> 16 &0xff,
cpuinfo[1] >> 24 &0xff,
cpuinfo[3] &0xff,
cpuinfo[3] >> 8 &0xff,
cpuinfo[3] >> 16 &0xff,
cpuinfo[3] >> 24 &0xff,
cpuinfo[2] &0xff,
cpuinfo[2] >> 8 &0xff,
cpuinfo[2] >> 16 &0xff,
cpuinfo[2] >> 24 &0xff);
//
// 1 - Tons of crap
//
__cpuid(cpuinfo, 1);
// all the names here are copied off the msdn article anyway
// ...but basically they describe the CPU in ...detail
printf("\n- __cpuid(1) eax -\n");
printf(" stepping id: %d\n", cpuinfo[0] &0xf );
printf(" model: %d\n", cpuinfo[0] >> 4 &0xf );
printf(" family: %d\n", cpuinfo[0] >> 8 &0xf );
printf("* processor type: %d\n", cpuinfo[0] >> 12 &0x3 );
printf(" reserved bits 14-15: %d\n", cpuinfo[0] >> 14 &0x3 );
printf(" extended model: %d\n", cpuinfo[0] >> 16 &0xf );
printf(" extended family: %d\n", cpuinfo[0] >> 20 &0xff);
printf(" reserved bits 28-31: %d\n", cpuinfo[0] >> 28 &0xf );
printf("\n- __cpuid(1) ebx -\n");
printf(" brand index: %d\n", cpuinfo[1] &0xff);
printf(" clflush cache line size: %d (quadwords)\n", cpuinfo[1] >> 8 &0xff);
printf(" logical processors: %d\n", cpuinfo[1] >> 16 &0xff);
printf(" initial apic id: %d\n", cpuinfo[1] >> 24 &0xff);
printf("\n- __cpuid(1) ecx -\n");
printf(" SSE3 instructions: %d\n", cpuinfo[2] &1);
printf(" reserved 1-2: %d\n", cpuinfo[2] >> 1 &3);
printf(" monitor/mwait: %d\n", cpuinfo[2] >> 3 &1);
printf("* cpl qualified debug store: %d\n", cpuinfo[2] >> 4 &1);
printf("* virtual machine extensions: %d\n", cpuinfo[2] >> 5 &1);
printf("* safer-mode extensions: %d\n", cpuinfo[2] >> 6 &1);
printf("* enhanced intel speedstep extensions: %d\n", cpuinfo[2] >> 7 &1);
printf("* thermal monitor: %d\n", cpuinfo[2] >> 8 &1);
printf(" supplemental SSE3: %d\n", cpuinfo[2] >> 9 &1);
printf("* L1 context id: %d\n", cpuinfo[2] >> 10 &1);
printf(" reserved bit 11: %d\n", cpuinfo[2] >> 11 &1);
printf("* 256-bit fma extensions: %d\n", cpuinfo[2] >> 12 &1);
printf(" CMPXCHG16B (compare-exchange-16bytes) support: %d\n", cpuinfo[2] >> 13 &1);
printf(" xTPR update control: %d\n", cpuinfo[2] >> 14 &1);
printf(" performance/debug capability MSR: %d\n", cpuinfo[2] >> 15 &1);
printf(" reserved bits 16-17: %d\n", cpuinfo[2] >> 16 &3);
printf("* direct cache access (DCA): %d\n", cpuinfo[2] >> 18 &1);
printf(" SSE 4.1 extensions: %d\n", cpuinfo[2] >> 19 &1);
printf(" SSE 4.2 extensions: %d\n", cpuinfo[2] >> 20 &1);
printf("* x2APIC support: %d\n", cpuinfo[2] >> 21 &1);
printf("* MOVBE instruction support: %d\n", cpuinfo[2] >> 22 &1);
printf(" POPCNT instruction support: %d\n", cpuinfo[2] >> 23 &1);
printf(" reserved bit 24: %d\n", cpuinfo[2] >> 24 &1);
printf("* AES instruction support: %d\n", cpuinfo[2] >> 25 &1);
printf("* XSAVE instruction support: %d\n", cpuinfo[2] >> 26&1);
printf("* OSXSAVE instruction support: %d\n", cpuinfo[2] >> 27 &1);
printf("* 256bit advanced vector extensions: %d\n", cpuinfo[2] >> 28 &1);
printf(" reserved bits 29-31: %d\n", cpuinfo[2] >> 29 &0xf);
printf("\n- __cpuid(1) edx -\n");
printf(" FPU - x87 FPU on chip: %d\n", cpuinfo[3] >> 0 &1);
printf(" VME - Virtual-8086 mode enhancement: %d\n", cpuinfo[3] >> 1 &1);
printf(" DE - Debugging extensions: %d\n", cpuinfo[3] >> 2 &1);
printf(" PSE - Page size extensions: %d\n", cpuinfo[3] >> 3 &1);
printf(" TSC - Time stamp counter: %d\n", cpuinfo[3] >> 4 &1);
printf(" MSR - RDMSR and WRMSR support: %d\n", cpuinfo[3] >> 5 &1);
printf(" PAE - Physical address extensions: %d\n", cpuinfo[3] >> 6 &1);
printf(" MCE - Machine check exception: %d\n", cpuinfo[3] >> 7 &1);
printf(" CX8 - CMPXCHG8B instruction: %d\n", cpuinfo[3] >> 8 &1);
printf(" APIC - APIC on chip: %d\n", cpuinfo[3] >> 9 &1);
printf(" n/a - Reserved: %d\n", cpuinfo[3] >> 10 &1);
printf(" SEP - SYSENTER and SYSEXIT: %d\n", cpuinfo[3] >> 11 &1);
printf(" MTRR - Memory type range registers: %d\n", cpuinfo[3] >> 12 &1);
printf(" PGE - PTE global bit: %d\n", cpuinfo[3] >> 13 &1);
printf(" MCA - Machine check architecture: %d\n", cpuinfo[3] >> 14 &1);
printf(" CMOV - Conditional move/compare instruction: %d\n", cpuinfo[3] >> 15 &1);
printf(" PAT - Page Attribute Table: %d\n", cpuinfo[3] >> 16 &1);
printf(" PSE-36 - 36-bit page size extension: %d\n", cpuinfo[3] >> 17 &1);
printf(" PSN - Processor serial number: %d\n", cpuinfo[3] >> 18 &1);
printf(" CLFSH - CFLUSH instruction: %d\n", cpuinfo[3] >> 19 &1);
printf(" n -/a Reserved: %d\n", cpuinfo[3] >> 20 &1);
printf(" DS - Debug store: %d\n", cpuinfo[3] >> 21 &1);
printf(" ACPI - Thermal monitor and clock control: %d\n", cpuinfo[3] >> 22 &1);
printf(" MMX - MMX technology: %d\n", cpuinfo[3] >> 23 &1);
printf(" FXSR - FXSAVE/FXRSTOR: %d\n", cpuinfo[3] >> 24 &1);
printf(" SSE - SSE extensions: %d\n", cpuinfo[3] >> 25 &1);
printf(" SSE2 - SSE2 extensions: %d\n", cpuinfo[3] >> 26 &1);
printf(" SS - Self snoop: %d\n", cpuinfo[3] >> 27 &1);
printf(" HTT - Multithreading: %d\n", cpuinfo[3] >> 28 &1);
printf(" TM - Thermal monitor: %d\n", cpuinfo[3] >> 29 &1);
printf(" n/a - Reserved: %d\n", cpuinfo[3] >> 30 &1);
printf(" PBE - Pending break enable: %d\n", cpuinfo[3] >> 31 &1);
//
// 2 -
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment