Skip to content

Instantly share code, notes, and snippets.

@CodeAngry
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeAngry/fb9cec3b4d39f6b12886 to your computer and use it in GitHub Desktop.
Save CodeAngry/fb9cec3b4d39f6b12886 to your computer and use it in GitHub Desktop.
Get CPU Maker and Model.
//
// Written and Tested in VC++ (C++11 code)
// by @CodeAngry
//
// get the maker name
int vCpuBuffer[4]{};
__cpuid(vCpuBuffer, 0);
unsigned int vHighestFeature((unsigned int)vCpuBuffer[0]);
char vCpuMaker[32]{}; // zero-fill
*(int*)&vCpuMaker[0] = vCpuBuffer[1];
*(int*)&vCpuMaker[4] = vCpuBuffer[3];
*(int*)&vCpuMaker[8] = vCpuBuffer[2];
// get the model name
char vCpuModel[64]{};
__cpuid(vCpuBuffer, 0x80000000);
unsigned int nHighestFeatureEx((unsigned int)vCpuBuffer[0]);
if(nHighestFeatureEx >= 0x80000004) {
__cpuid((int*)&vCpuModel[0], 0x80000002);
__cpuid((int*)&vCpuModel[16], 0x80000003);
__cpuid((int*)&vCpuModel[32], 0x80000004);
// trim the beggining of the model name
auto vCpuModelBegin(vCpuModel);
while(*vCpuModelBegin && ((*vCpuModelBegin == ' ') || (*vCpuModelBegin == '\t'))) {
++vCpuModelBegin;
}
// seek the end of the model name
auto vCpuModelEnd(vCpuModelBegin);
while(*vCpuModelEnd) {
++vCpuModelEnd;
}
--vCpuModelEnd;
// trim the end of the model name
while(vCpuModelEnd > vCpuModelBegin) {
if((*vCpuModelEnd != ' ') && (*vCpuModelEnd != '\t')) {
break;
}
--vCpuModelEnd;
}
*(vCpuModelEnd + 1) = 0;
// get rid of leading and trailing spaces
unsigned int vCpuModelLength((unsigned int)strlen(vCpuModelBegin));
memmove(vCpuModel, vCpuModelBegin, vCpuModelLength);
memset(vCpuModel + vCpuModelLength, 0, sizeof(vCpuModel) - vCpuModelLength);
}
// we've got the data
printf("Maker: '%s'\r\n", vCpuMaker);
printf("Model: '%s'\r\n", vCpuModel);
bool vIsIntel(!strcmp(vCpuMaker, "GenuineIntel"));
bool vIsAMD(!vIsIntel && !strcmp(vCpuMaker, "AuthenticAMD"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment