CPUID から CPU 名を取得する関数 get_cpu_name() はこちら。
double get_cpuname_mfreq(void) {
double freq = -1.0;
int i, unit_size = 0;
char name[48], buffer[8];
strcpy(name, get_cpu_name());
for (i = 0; i < 48-2; ++i) {
if( name[i+1] == 'H' && name[i+2] == 'z' ) {
if (name[i] == 'M') {
unit_size = 1;
} else if (name[i] == 'G') {
unit_size = 1000;
} else if (name[i] == 'T') {
unit_size = 1000000;
}
}
/* parse "x.xxyHz" or "xxxxyHz" */
if (unit_size > 0) {
strncpy(buffer, &name[i-4], 7);
buffer[7] = 0;
if (name[i-3] == '.') {
freq = (int)(name[i-4] - '0') * unit_size;
freq += (int)(name[i-2] - '0') * (unit_size/10);
freq += (int)(name[i-1] - '0') * (unit_size/100);
} else {
freq = (int)(name[i-4] - '0') * 1000;
freq += (int)(name[i-3] - '0') * 100;
freq += (int)(name[i-2] - '0') * 10;
freq += (int)(name[i-1] - '0');
freq *= unit_size;
}
break;
}
}
return freq;
}
[参考] Intel(R) Processor Identification and the CPUID Instruction. 2009.