ccpuid:CPUID信息模块。范例:显示所有的CPUID信息

2019-07-13 21:49发布

作者:zyl910   关于获取各种CPUID信息,我之前积累了不少代码,现在决定将它们封装在一个模块中,方便代码复用。
  其次,前面只是介绍了CPUID的一些常用功能,而Intel、AMD的手册中定义了大量的CPUID功能。所以我希望有一个程序能按照功能号顺序,依次显示所有的CPUID信息。这样就能很方便的与Intel、AMD的手册进行对照,有助于学习与理解。


一、模块设计

  最初方案是 想将所有功能全部放在一个“ccpuid.h”头文件中,这样用起来会比较方便。
  但是考虑到全局变量等问题,以及需要编写CCPUID类。所以最终决定按照常规做法,分解为头文件与实现文件。   对于原先所写的宏定义、类型定义等声明性内容,可以直接放在头文件中。
  对于原先的simd_sse_names等常数数组,考虑到全局变量问题,觉得作为CCPUID类的静态成员会比较好(CCPUID::SseNames、CCPUID::AvxNames)。
  对于原先的函数,__cpuid/__cpuidex作为内联函数,放在头文件中;而其他函数作为普通函数,放在实现文件中。   除了封装原来的代码之外,还决定增加这些功能——
1. 全部的CPUIDFIELD常数。根据Intel、AMD手册及网络上的一些资料,将目前所有的CPUIDFIELD常数均定义一遍,方便各种情况下的使用。
2. CPUID字段的描述信息。定义了CPUIDFIELDDESC结构体,然后还定义了CCPUID::CPUFDesc这个静态成员,它是CPUIDFIELDDESC结构体数组,记录了每条CPUIDFIELD常数的名称与描述文本。这样就可以通过查找表格得知CPUIDFIELD常数的描述信息。
3. 缓存的描述信息。这是为了方便使用CPUID指令的功能2是获取缓存信息。因为每一个字节代表不同的意义,所以可以使用一个256个项目的字符串指针数组来存储描述文本。(CCPUID::CacheDesc)
4. CCPUID类。拥有存储CPUID信息的能力,提供Vendor、mmx等方法,用于随时翻查CPUID信息。还设计一个cur静态方法,返回一个默认的CCPUID对象,简化代码编写。


二、测试程序

2.1 简单使用

  最基本的用法是,定义一个CCPUID变量,然后调用RefreshAll方法刷新信息——
 CCPUID ccid;
 ccid.RefreshAll();   在大多数时候,为了简化代码,可以调用cur静态方法来获得默认的CCPUID对象——
 CCPUID& ccid = CCPUID::cur();   获得了CCPUID对象之后,便可以调用它的成员函数来获取基本信息——
printf("CCPUID.InfoCount: %d ", ccid.InfoCount()); printf("CCPUID.LFuncStd: %.8Xh ", ccid.LFuncStd()); printf("CCPUID.LFuncExt: %.8Xh ", ccid.LFuncExt()); printf("CCPUID.Vendor: %s ", ccid.Vendor()); //printf("CCPUID.Brand: %s ", ccid.Brand()); printf("CCPUID.BrandTrim: %s ", ccid.BrandTrim());

  获取SIMD指令集类的信息也很方便——
printf("CCPUID.MMX: %d // hw: %d ", ccid.mmx(), ccid.hwmmx()); printf("CCPUID.SSE: %d // hw: %d ", ccid.sse(), ccid.hwsse()); for(i=1; i=i) printf(" %s ", CCPUID::SseNames[i]); } printf("SSE4A: %d ", ccid.GetField(CPUF_SSE4A)); printf("AES: %d ", ccid.GetField(CPUF_AES)); printf("PCLMULQDQ: %d ", ccid.GetField(CPUF_PCLMULQDQ)); printf("CCPUID.AVX: %d // hw: %d ", ccid.avx(), ccid.hwavx()); for(i=1; i=i) printf(" %s ", CCPUID::AvxNames[i]); } printf("F16C: %d ", ccid.GetField(CPUF_F16C)); printf("FMA: %d ", ccid.GetField(CPUF_FMA)); printf("FMA4: %d ", ccid.GetField(CPUF_FMA4)); printf("XOP: %d ", ccid.GetField(CPUF_XOP));

  上面与前面博文中的代码差不多,只不过将全局函数变为CCPUID对象的成员函数而已,例如 simd_sse_names变为CCPUID::SseNames、getcpuidfield变为了ccid.GetField。


2.2 显示所有的CPUID信息

  因为CCPUID类缓存了CPUID信息,而且还有CPUFDesc描述信息数组,所以编写显示所有的CPUID信息的程序十分容易。   我把它分为两个函数——
prtCcpuid:是外循环,对每一条CPUID信息调用prtCcpuid_Item函数。
prtCcpuid_Item:是内循环,在CCPUID::CPUFDesc数组中找到功能号相同的CPUIDFIELD子集,然后逐一输出该字段的数值、名称、描述等信息。   代码如下——
// 打印CPUID字段_某项. void prtCcpuid_Item(INT32 fid, INT32 fidsub, const INT32 CPUInfo[4]) { static const char* RegName[4] = { "EAX", "EBX", "ECX", "EDX" }; INT32 mask = CPUIDFIELD_MASK_FID | CPUIDFIELD_MASK_FIDSUB; INT32 cur = CPUIDFIELD_MAKE(fid, fidsub, 0, 0, 1) & mask; int i; for(i=0; i1) { printf(" %s[%2d:%2d]", RegName[reg], pos+bits-1, pos); } else { printf(" %s[ %2d]", RegName[reg], pos); } printf("=%s: 0x%X (%u)", v.szName, n, n); if (bShowDesc) { printf(" // %s", v.szDesc); } printf(" "); } } } // 打印CPUID字段. void prtCcpuid(const CCPUID& ccid) { int i; for(i=0; i0) // 最高位为0,且不是全0 { for(int k=0; k<=3; ++k) { if (j>0 || k>0) // EAX的低8位不是缓存信息 { int by = n & 0x00FF; if (by>0) { printf(" 0x%.2X: %s ", by, CCPUID::CacheDesc[by]); } } n >>= 8; } } } } } }

  prtCcpuid函数中有两个技巧——
1. 处理规范子功能号。检查子功能号,如果是规范的子功能号,便故意设为0,根据子功能号0的字段来解析各个子功能号的信息。
2. 处理特殊功能号。对于功能0和功能80000004h,可以利用Vendor、Brand这两个成员函数。对于功能2(缓存信息),可以利用CCPUID::CacheDesc数组来解析。


三、全部代码

3.1 头文件的全部代码

  ccpuid.h—— #if _MSC_VER > 1000 #pragma once #endif #ifndef __CCPUID_H_INCLUDED #define __CCPUID_H_INCLUDED #include // NULL等标准宏和类型. #include // INT32、UINT32等规范类型名. #if _MSC_VER >=1400 // VC2005才支持intrin.h #include // 所有Intrinsics函数. #else #include // MMX, SSE, SSE2 #endif #if defined __cplusplus extern "C" { #endif // __cpuid,__cpuidex #if defined(_WIN64) // 64位下不支持内联汇编. 应使用__cpuid、__cpuidex等Intrinsics函数. #else #if _MSC_VER < 1600 // VS2010. 据说VC2008 SP1之后才支持__cpuidex inline void __cpuidex(INT32 CPUInfo[4], INT32 InfoType, INT32 ECXValue) { if (0==CPUInfo) return; _asm{ // load. 读取参数到寄存器. mov edi, CPUInfo; // 准备用edi寻址CPUInfo mov eax, InfoType; mov ecx, ECXValue; // CPUID cpuid; // save. 将寄存器保存到CPUInfo mov [edi], eax; mov [edi+4], ebx; mov [edi+8], ecx; mov [edi+12], edx; } } #endif // #if _MSC_VER < 1600 // VS2010. 据说VC2008 SP1之后才支持__cpuidex #if _MSC_VER < 1400 // VC2005才支持__cpuid inline void __cpuid(INT32 CPUInfo[4], INT32 InfoType) { __cpuidex(CPUInfo, InfoType, 0); } #endif // #if _MSC_VER < 1400 // VC2005才支持__cpuid #endif // #if defined(_WIN64) // CPUIDFIELD typedef INT32 CPUIDFIELD; #define CPUIDFIELD_MASK_POS 0x0000001F // 位偏移. 0~31. #define CPUIDFIELD_MASK_LEN 0x000003E0 // 位长. 1~32 #define CPUIDFIELD_MASK_REG 0x00000C00 // 寄存器. 0=EAX, 1=EBX, 2=ECX, 3=EDX. #define CPUIDFIELD_MASK_FIDSUB 0x000FF000 // 子功能号(低8位). #define CPUIDFIELD_MASK_FID 0xFFF00000 // 功能号(最高4位 和 低8位). #define CPUIDFIELD_SHIFT_POS 0 #define CPUIDFIELD_SHIFT_LEN 5 #define CPUIDFIELD_SHIFT_REG 10 #define CPUIDFIELD_SHIFT_FIDSUB 12 #define CPUIDFIELD_SHIFT_FID 20 #define CPUIDFIELD_MAKE(fid,fidsub,reg,pos,len) (((fid)&0xF0000000) | ((fid)<>CPUIDFIELD_SHIFT_FID) ) #define CPUIDFIELD_FIDSUB(cpuidfield) ( ((cpuidfield) & CPUIDFIELD_MASK_FIDSUB)>>CPUIDFIELD_SHIFT_FIDSUB ) #define CPUIDFIELD_REG(cpuidfield) ( ((cpuidfield) & CPUIDFIELD_MASK_REG)>>CPUIDFIELD_SHIFT_REG ) #define CPUIDFIELD_POS(cpuidfield) ( ((cpuidfield) & CPUIDFIELD_MASK_POS)>>CPUIDFIELD_SHIFT_POS ) #define CPUIDFIELD_LEN(cpuidfield) ( (((cpuidfield) & CPUIDFIELD_MASK_LEN)>>CPUIDFIELD_SHIFT_LEN) + 1 ) typedef struct tagCPUIDFIELDDESC{ CPUIDFIELD cpuf; INT32 reserved; const char* szName; const char* szDesc; }CPUIDFIELDDESC; #define CPUF_LFuncStd CPUIDFIELD_MAKE(0,0,0,0,32) #define CPUF_Stepping CPUIDFIELD_MAKE(1,0,0,0,4) #define CPUF_BaseModel CPUIDFIELD_MAKE(1,0,0,4,4) #define CPUF_BaseFamily CPUIDFIELD_MAKE(1,0,0,8,4) #define CPUF_ProcessorType CPUIDFIELD_MAKE(1,0,0,12,2) #define CPUF_ExtModel CPUIDFIELD_MAKE(1,0,0,16,4) #define CPUF_ExtFamily CPUIDFIELD_MAKE(1,0,0,20,8) #define CPUF_BrandId8 CPUIDFIELD_MAKE(1,0,1,0,8) #define CPUF_CLFlush CPUIDFIELD_MAKE(1,0,1,8,8) #define CPUF_MaxApicId CPUIDFIELD_MAKE(1,0,1,16,8) #define CPUF_ApicId CPUIDFIELD_MAKE(1,0,1,24,8) #define CPUF_SSE3 CPUIDFIELD_MAKE(1,0,2,0,1) #define CPUF_PCLMULQDQ CPUIDFIELD_MAKE(1,0,2,1,1) #define CPUF_DTES64 CPUIDFIELD_MAKE(1,0,2,2,1) #define CPUF_MONITOR CPUIDFIELD_MAKE(1,0,2,3,1) #define CPUF_DS_CPL CPUIDFIELD_MAKE(1,0,2,4,1) #define CPUF_VMX CPUIDFIELD_MAKE(1,0,2,5,1) #define CPUF_SMX CPUIDFIELD_MAKE(1,0,2,6,1) #define CPUF_EIST CPUIDFIELD_MAKE(1,0,2,7,1) #define CPUF_TM2 CPUIDFIELD_MAKE(1,0,2,8,1) #define CPUF_SSSE3 CPUIDFIELD_MAKE(1,0,2,9,1) #define CPUF_CNXT_ID CPUIDFIELD_MAKE(1,0,2,10,1) #define CPUF_FMA CPUIDFIELD_MAKE(1,0,2,12,1) #define CPUF_CMPXCHG16B CPUIDFIELD_MAKE(1,0,2,13,1) #define CPUF_xTPR CPUIDFIELD_MAKE(1,0,2,14,1) #define CPUF_PDCM CPUIDFIELD_MAKE(1,0,2,15,1) #define CPUF_PCID CPUIDFIELD_MAKE(1,0,2,17,1) #define CPUF_DCA CPUIDFIELD_MAKE(1,0,2,18,1) #define CPUF_SSE41 CPUIDFIELD_MAKE(1,0,2,19,1) #define CPUF_SSE42 CPUIDFIELD_MAKE(1,0,2,20,1) #define CPUF_x2APIC CPUIDFIELD_MAKE(1,0,2,21,1) #define CPUF_MOVBE CPUIDFIELD_MAKE(1,0,2,22,1) #define CPUF_POPCNT CPUIDFIELD_MAKE(1,0,2,23,1) #define CPUF_TSC_DEADLINE CPUIDFIELD_MAKE(1,0,2,24,1) #define CPUF_AES CPUIDFIELD_MAKE(1,0,2,25,1) #define CPUF_XSAVE CPUIDFIELD_MAKE(1,0,2,26,1) #define CPUF_OSXSAVE CPUIDFIELD_MAKE(1,0,2,27,1) #define CPUF_AVX CPUIDFIELD_MAKE(1,0,2,28,1) #define CPUF_F16C CPUIDFIELD_MAKE(1,0,2,29,1) #define CPUF_RDRAND CPUIDFIELD_MAKE(1,0,2,30,1) #define CPUF_FPU CPUIDFIELD_MAKE(1,0,3,0,1) #define CPUF_VME CPUIDFIELD_MAKE(1,0,3,1,1) #define CPUF_DE CPUIDFIELD_MAKE(1,0,3,2,1) #define CPUF_PSE CPUIDFIELD_MAKE(1,0,3,3,1) #define CPUF_TSC CPUIDFIELD_MAKE(1,0,3,4,1) #define CPUF_MSR CPUIDFIELD_MAKE(1,0,3,5,1) #define CPUF_PAE CPUIDFIELD_MAKE(1,0,3,6,1) #define CPUF_MCE CPUIDFIELD_MAKE(1,0,3,7,1) #define CPUF_CX8 CPUIDFIELD_MAKE(1,0,3,8,1) #define CPUF_APIC CPUIDFIELD_MAKE(1,0,3,9,1) #define CPUF_SEP CPUIDFIELD_MAKE(1,0,3,11,1) #define CPUF_MTRR CPUIDFIELD_MAKE(1,0,3,12,1) #define CPUF_PGE CPUIDFIELD_MAKE(1,0,3,13,1) #define CPUF_MCA CPUIDFIELD_MAKE(1,0,3,14,1) #define CPUF_CMOV CPUIDFIELD_MAKE(1,0,3,15,1) #define CPUF_PAT CPUIDFIELD_MAKE(1,0,3,16,1) #define CPUF_PSE36 CPUIDFIELD_MAKE(1,0,3,17,1) #define CPUF_PSN CPUIDFIELD_MAKE(1,0,3,18,1) #define CPUF_CLFSH CPUIDFIELD_MAKE(1,0,3,19,1) #define CPUF_DS CPUIDFIELD_MAKE(1,0,3,21,1) #define CPUF_ACPI CPUIDFIELD_MAKE(1,0,3,22,1) #define CPUF_MMX CPUIDFIELD_MAKE(1,0,3,23,1) #define CPUF_FXSR CPUIDFIELD_MAKE(1,0,3,24,1) #define CPUF_SSE CPUIDFIELD_MAKE(1,0,3,25,1) #define CPUF_SSE2 CPUIDFIELD_MAKE(1,0,3,26,1) #define CPUF_SS CPUIDFIELD_MAKE(1,0,3,27,1) #define CPUF_HTT CPUIDFIELD_MAKE(1,0,3,28,1) #define CPUF_TM CPUIDFIELD_MAKE(1,0,3,29,1) #define CPUF_PBE CPUIDFIELD_MAKE(1,0,3,31,1) #define CPUF_Cache_Type CPUIDFIELD_MAKE(4,0,0,0,5) #define CPUF_Cache_Level CPUIDFIELD_MAKE(4,0,0,5,3) #define CPUF_CACHE_SI CPUIDFIELD_MAKE(4,0,0,8,1) #define CPUF_CACHE_FA CPUIDFIELD_MAKE(4,0,0,9,1) #define CPUF_MaxApicIdShare CPUIDFIELD_MAKE(4,0,0,14,12) #define CPUF_MaxApicIdCore CPUIDFIELD_MAKE(4,0,0,26,6) #define CPUF_Cache_LineSize CPUIDFIELD_MAKE(4,0,1,0,12) #define CPUF_Cache_Partitions CPUIDFIELD_MAKE(4,0,1,12,10) #define CPUF_Cache_Ways CPUIDFIELD_MAKE(4,0,1,22,10) #define CPUF_Cache_Sets CPUIDFIELD_MAKE(4,0,2,0,32) #define CPUF_CACHE_INVD CPUIDFIELD_MAKE(4,0,3,0,1) #define CPUF_CACHE_INCLUSIVENESS CPUIDFIELD_MAKE(4,0,3,1,1) #define CPUF_CACHE_COMPLEXINDEX CPUIDFIELD_MAKE(4,0,3,2,1) #define CPUF_MonLineSizeMin CPUIDFIELD_MAKE(5,0,0,0,16) #define CPUF_MonLineSizeMax CPUIDFIELD_MAKE(5,0,1,0,16) #define CPUF_EMX CPUIDFIELD_MAKE(5,0,2,0,1) #define CPUF_IBE CPUIDFIELD_MAKE(5,0,2,1,1) #define CPUF_MWAIT_Number_C0 CPUIDFIELD_MAKE(5,0,3,0,4) #define CPUF_MWAIT_Number_C1 CPUIDFIELD_MAKE(5,0,3,4,4) #define CPUF_MWAIT_Number_C2 CPUIDFIELD_MAKE(5,0,3,8,4) #define CPUF_MWAIT_Number_C3 CPUIDFIELD_MAKE(5,0,3,12,4) #define CPUF_MWAIT_Number_C4 CPUIDFIELD_MAKE(5,0,3,16,4) #define CPUF_DTS CPUIDFIELD_MAKE(6,0,0,0,1) #define CPUF_TURBO_BOOST CPUIDFIELD_MAKE(6,0,0,1,1) #define CPUF_ARAT CPUIDFIELD_MAKE(6,0,0,2,1) #define CPUF_PLN CPUIDFIELD_MAKE(6,0,0,4,1) #define CPUF_ECMD CPUIDFIELD_MAKE(6,0,0,5,1) #define CPUF_PTM CPUIDFIELD_MAKE(6,0,0,6,1) #define CPUF_DTS_ITs CPUIDFIELD_MAKE(6,0,1,0,4) #define CPUF_PERF CPUIDFIELD_MAKE(6,0,2,0,1) #define CPUF_ACNT2 CPUIDFIELD_MAKE(6,0,2,1,1) #define CPUF_ENERGY_PERF_BIAS CPUIDFIELD_MAKE(6,0,2,3,1) #define CPUF_Max07Subleaf CPUIDFIELD_MAKE(7,0,0,0,32) #define CPUF_FSGSBASE CPUIDFIELD_MAKE(7,0,1,0,1) #define CPUF_BMI1 CPUIDFIELD_MAKE(7,0,1,3,1) #define CPUF_HLE CPUIDFIELD_MAKE(7,0,1,4,1) #define CPUF_AVX2 CPUIDFIELD_MAKE(7,0,1,5,1) #define CPUF_SMEP CPUIDFIELD_MAKE(7,0,1,7,1) #define CPUF_BMI2 CPUIDFIELD_MAKE(7,0,1,8,1) #define CPUF_ERMS CPUIDFIELD_MAKE(7,0,1,9,1) #define CPUF_INVPCID CPUIDFIELD_MAKE(7,0,1,10,1) #define CPUF_RTM CPUIDFIELD_MAKE(7,0,1,11,1) #define CPUF_PLATFORM_DCA_CAP CPUIDFIELD_MAKE(9,0,0,0,32) #define CPUF_APM_Version CPUIDFIELD_MAKE(0xA,0,0,0,8) #define CPUF_APM_Counters CPUIDFIELD_MAKE(0xA,0,0,8,8) #define CPUF_APM_Bits CPUIDFIELD_MAKE(0xA,0,0,16,8) #define CPUF_APM_Length CPUIDFIELD_MAKE(0xA,0,0,24,8) #define CPUF_APM_CC CPUIDFIELD_MAKE(0xA,0,1,0,1) #define CPUF_APM_IR CPUIDFIELD_MAKE(0xA,0,1,1,1) #define CPUF_APM_RC CPUIDFIELD_MAKE(0xA,0,1,2,1) #define CPUF_APM_LLCR CPUIDFIELD_MAKE(0xA,0,1,3,1) #define CPUF_APM_LLCM CPUIDFIELD_MAKE(0xA,0,1,4,1) #define CPUF_APM_BIR CPUIDFIELD_MAKE(0xA,0,1,5,1) #define CPUF_APM_BMR CPUIDFIELD_MAKE(0xA,0,1,6,1) #define CPUF_APM_FC_Number CPUIDFIELD_MAKE(0xA,0,3,0,5) #define CPUF_APM_FC_Bits CPUIDFIELD_MAKE(0xA,0,3,5,8) #define CPUF_Topology_Bits CPUIDFIELD_MAKE(0xB,0,0,0,5) #define CPUF_Topology_Number CPUIDFIELD_MAKE(0xB,0,1,0,16) #define CPUF_Topology_Level CPUIDFIELD_MAKE(0xB,0,2,0,8) #define CPUF_Topology_Type CPUIDFIELD_MAKE(0xB,0,2,8,8) #define CPUF_X2APICID CPUIDFIELD_MAKE(0xB,0,3,0,32) #define CPUF_XFeatureSupportedMaskLo CPUIDFIELD_MAKE(0xD,0,0,0,32) #define CPUF_XFeatureEnabledSizeMax CPUIDFIELD_MAKE(0xD,0,1,0,32) #define CPUF_XFeatureSupportedSizeMax CPUIDFIELD_MAKE(0xD,0,2,0,32) #define CPUF_XFeatureSupportedMaskHi CPUIDFIELD_MAKE(0xD,0,3,0,32) #define CPUF_XSAVEOPT CPUIDFIELD_MAKE(0xD,1,0,0,1) #define CPUF_YmmSaveStateSize CPUIDFIELD_MAKE(0xD,2,0,0,32) #define CPUF_YmmSaveStateOffset CPUIDFIELD_MAKE(0xD,2,1,0,32) #define CPUF_LwpSaveStateSize CPUIDFIELD_MAKE(0xD,62,0,0,32) #define CPUF_LwpSaveStateOffset CPUIDFIELD_MAKE(0xD,62,1,0,32) #define CPUF_LFuncExt CPUIDFIELD_MAKE(0x80000000,0,0,0,32) #define CPUF_BrandId16 CPUIDFIELD_MAKE(0x80000001,0,1,0,16) #define CPUF_PkgType CPUIDFIELD_MAKE(0x80000001,0,1,28,4) #define CPUF_LahfSahf CPUIDFIELD_MAKE(0x80000001,0,2,0,1) #define CPUF_CmpLegacy CPUIDFIELD_MAKE(0x80000001,0,2,1,1) #define CPUF_SVM CPUIDFIELD_MAKE(0x80000001,0,2,2,1) #define CPUF_ExtApicSpace CPUIDFIELD_MAKE(0x80000001,0,2,3,1) #define CPUF_AltMovCr8 CPUIDFIELD_MAKE(0x80000001,0,2,4,1) #define CPUF_ABM CPUIDFIELD_MAKE(0x80000001,0,2,5,1) #define CPUF_SSE4A CPUIDFIELD_MAKE(0x80000001,0,2,6,1) #define CPUF_MisAlignSse CPUIDFIELD_MAKE(0x80000001,0,2,7,1) #define CPUF_3DNowPrefetch CPUIDFIELD_MAKE(0x80000001,0,2,8,1) #define CPUF_OSVW CPUIDFIELD_MAKE(0x80000001,0,2,9,1) #define CPUF_IBS CPUIDFIELD_MAKE(0x80000001,0,2,10,1) #define CPUF_XOP CPUIDFIELD_MAKE(0x80000001,0,2,11,1) #define CPUF_SKINIT CPUIDFIELD_MAKE(0x80000001,0,2,12,1) #define CPUF_WDT CPUIDFIELD_MAKE(0x80000001,0,2,13,1) #define CPUF_LWP CPUIDFIELD_MAKE(0x80000001,0,2,15,1) #define CPUF_FMA4 CPUIDFIELD_MAKE(0x80000001,0,2,16,1) #define CPUF_BIT_NODEID CPUIDFIELD_MAKE(0x80000001,0,2,19,1) #define CPUF_TBM CPUIDFIELD_MAKE(0x80000001,0,2,21,1) #define CPUF_TopologyExtensions CPUIDFIELD_MAKE(0x80000001,0,2,22,1) #define CPUF_SYSCALL CPUIDFIELD_MAKE(0x80000001,0,3,11,1) #define CPUF_XD CPUIDFIELD_MAKE(0x80000001,0,3,20,1) #define CPUF_MmxExt CPUIDFIELD_MAKE(0x80000001,0,3,22,1) #define CPUF_FFXSR CPUIDFIELD_MAKE(0x80000001,0,3,25,1) #define CPUF_Page1GB CPUIDFIELD_MAKE(0x80000001,0,3,26,1) #define CPUF_RDTSCP CPUIDFIELD_MAKE(0x80000001,0,3,27,1) #define CPUF_LM CPUIDFIELD_MAKE(0x80000001,0,3,29,1) #define CPUF_3DNowExt CPUIDFIELD_MAKE(0x80000001,0,3,30,1) #define CPUF_3DNow CPUIDFIELD_MAKE(0x80000001,0,3,31,1) #define CPUF_L1ITlb2and4MSize CPUIDFIELD_MAKE(0x80000005,0,0,0,8) #define CPUF_L1ITlb2and4MAssoc CPUIDFIELD_MAKE(0x80000005,0,0,8,8) #define CPUF_L1DTlb2and4MSize CPUIDFIELD_MAKE(0x80000005,0,0,16,8) #define CPUF_L1DTlb2and4MAssoc CPUIDFIELD_MAKE(0x80000005,0,0,24,8) #define CPUF_L1ITlb4KSize CPUIDFIELD_MAKE(0x80000005,0,1,0,8) #define CPUF_L1ITlb4KAssoc CPUIDFIELD_MAKE(0x80000005,0,1,8,8) #define CPUF_L1DTlb4KSize CPUIDFIELD_MAKE(0x80000005,0,1,16,8) #define CPUF_L1DTlb4KAssoc CPUIDFIELD_MAKE(0x80000005,0,1,24,8) #define CPUF_L1DcLineSize CPUIDFIELD_MAKE(0x80000005,0,2,0,8) #define CPUF_L1DcLinesPerTag CPUIDFIELD_MAKE(0x80000005,0,2,8,8) #define CPUF_L1DcAssoc CPUIDFIELD_MAKE(0x80000005,0,2,16,8) #define CPUF_L1DcSize CPUIDFIELD_MAKE(0x80000005,0,2,24,8) #define CPUF_L1IcLineSize CPUIDFIELD_MAKE(0x80000005,0,3,0,8) #define CPUF_L1IcLinesPerTag CPUIDFIELD_MAKE(0x80000005,0,3,8,8) #define CPUF_L1IcAssoc CPUIDFIELD_MAKE(0x80000005,0,3,16,8) #define CPUF_L1IcSize CPUIDFIELD_MAKE(0x80000005,0,3,24,8) #define CPUF_L2ITlb2and4MSize CPUIDFIELD_MAKE(0x80000006,0,0,0,12) #define CPUF_L2ITlb2and4MAssoc CPUIDFIELD_MAKE(0x80000006,0,0,12,4) #define CPUF_L2DTlb2and4MSize CPUIDFIELD_MAKE(0x80000006,0,0,16,12) #define CPUF_L2DTlb2and4MAssoc CPUIDFIELD_MAKE(0x80000006,0,0,28,4) #define CPUF_L2ITlb4KSize CPUIDFIELD_MAKE(0x80000006,0,1,0,12) #define CPUF_L2ITlb4KAssoc CPUIDFIELD_MAKE(0x80000006,0,1,12,4) #define CPUF_L2DTlb4KSize CPUIDFIELD_MAKE(0x80000006,0,1,16,12) #define CPUF_L2DTlb4KAssoc CPUIDFIELD_MAKE(0x80000006,0,1,28,4) #define CPUF_L2LineSize CPUIDFIELD_MAKE(0x80000006,0,2,0,8) #define CPUF_L2LinesPerTag CPUIDFIELD_MAKE(0x80000006,0,2,8,4) #define CPUF_L2Assoc CPUIDFIELD_MAKE(0x80000006,0,2,12,4) #define CPUF_L2Size CPUIDFIELD_MAKE(0x80000006,0,2,16,16) #define CPUF_L3LineSize CPUIDFIELD_MAKE(0x80000006,0,3,0,8) #define CPUF_L3LinesPerTag CPUIDFIELD_MAKE(0x80000006,0,3,8,4) #define CPUF_L3Assoc CPUIDFIELD_MAKE(0x80000006,0,3,12,4) #define CPUF_L3Size CPUIDFIELD_MAKE(0x80000006,0,3,18,14) #define CPUF_TS CPUIDFIELD_MAKE(0x80000007,0,3,0,1) #define CPUF_FID CPUIDFIELD_MAKE(0x80000007,0,3,1,1) #define CPUF_VID CPUIDFIELD_MAKE(0x80000007,0,3,2,1) #define CPUF_TTP CPUIDFIELD_MAKE(0x80000007,0,3,3,1) #define CPUF_HTC CPUIDFIELD_MAKE(0x80000007,0,3,4,1) #define CPUF_100MHzSteps CPUIDFIELD_MAKE(0x80000007,0,3,6,1) #define CPUF_HwPstate CPUIDFIELD_MAKE(0x80000007,0,3,7,1) #define CPUF_TscInvariant CPUIDFIELD_MAKE(0x80000007,0,3,8,1) #define CPUF_CPB CPUIDFIELD_MAKE(0x80000007,0,3,9,1) #define CPUF_EffFreqRO CPUIDFIELD_MAKE(0x80000007,0,3,10,1) #define CPUF_PhysAddrSize CPUIDFIELD_MAKE(0x80000008,0,0,0,8) #define CPUF_LinAddrSize CPUIDFIELD_MAKE(0x80000008,0,0,8,8) #define CPUF_GuestPhysAddrSize CPUIDFIELD_MAKE(0x80000008,0,0,16,8) #define CPUF_NC CPUIDFIELD_MAKE(0x80000008,0,2,0,8) #define CPUF_ApicIdCoreIdSize CPUIDFIELD_MAKE(0x80000008,0,2,12,4) #define CPUF_SvmRev CPUIDFIELD_MAKE(0x8000000A,0,0,0,8) #define CPUF_NASID CPUIDFIELD_MAKE(0x8000000A,0,1,0,32) #define CPUF_NP CPUIDFIELD_MAKE(0x8000000A,0,3,0,1) #define CPUF_LbrVirt CPUIDFIELD_MAKE(0x8000000A,0,3,1,1) #define CPUF_SVML CPUIDFIELD_MAKE(0x8000000A,0,3,2,1) #define CPUF_NRIPS CPUIDFIELD_MAKE(0x8000000A,0,3,3,1) #define CPUF_TscRateMsr CPUIDFIELD_MAKE(0x8000000A,0,3,4,1) #define CPUF_VmcbClean CPUIDFIELD_MAKE(0x8000000A,0,3,5,1) #define CPUF_FlushByAsid CPUIDFIELD_MAKE(0x8000000A,0,3,6,1) #define CPUF_DecodeAssists CPUIDFIELD_MAKE(0x8000000A,0,3,7,1) #define CPUF_PauseFilter CPUIDFIELD_MAKE(0x8000000A,0,3,10,1) #define CPUF_PauseFilterThreshold CPUIDFIELD_MAKE(0x8000000A,0,3,12,1) #define CPUF_L1ITlb1GSize CPUIDFIELD_MAKE(0x80000019,0,0,0,12) #define CPUF_L1ITlb1GAssoc CPUIDFIELD_MAKE(0x80000019,0,0,12,4) #define CPUF_L1DTlb1GSize CPUIDFIELD_MAKE(0x80000019,0,0,16,12) #define CPUF_L1DTlb1GAssoc CPUIDFIELD_MAKE(0x80000019,0,0,28,4) #define CPUF_L2ITlb1GSize CPUIDFIELD_MAKE(0x80000019,0,1,0,12) #define CPUF_L2ITlb1GAssoc CPUIDFIELD_MAKE(0x80000019,0,1,12,4) #define CPUF_L2DTlb1GSize CPUIDFIELD_MAKE(0x80000019,0,1,16,12) #define CPUF_L2DTlb1GAssoc CPUIDFIELD_MAKE(0x80000019,0,1,28,4) #define CPUF_FP128 CPUIDFIELD_MAKE(0x8000001A,0,0,0,1) #define CPUF_MOVU CPUIDFIELD_MAKE(0x8000001A,0,0,1,1) #define CPUF_IBSFFV CPUIDFIELD_MAKE(0x8000001B,0,0,0,1) #define CPUF_FetchSam CPUIDFIELD_MAKE(0x8000001B,0,0,1,1) #define CPUF_OpSam CPUIDFIELD_MAKE(0x8000001B,0,0,2,1) #define CPUF_RdWrOpCnt CPUIDFIELD_MAKE(0x8000001B,0,0,3,1) #define CPUF_OpCnt CPUIDFIELD_MAKE(0x8000001B,0,0,4,1) #define CPUF_BrnTrgt CPUIDFIELD_MAKE(0x8000001B,0,0,5,1) #define CPUF_OpCntExt CPUIDFIELD_MAKE(0x8000001B,0,0,6,1) #define CPUF_RipInvalidChk CPUIDFIELD_MAKE(0x8000001B,0,0,7,1) #define CPUF_LwpAvail CPUIDFIELD_MAKE(0x8000001C,0,0,0,1) #define CPUF_LwpVAL CPUIDFIELD_MAKE(0x8000001C,0,0,1,1) #define CPUF_LwpIRE CPUIDFIELD_MAKE(0x8000001C,0,0,2,1) #define CPUF_LwpBRE CPUIDFIELD_MAKE(0x8000001C,0,0,3,1) #define CPUF_LwpDME CPUIDFIELD_MAKE(0x8000001C,0,0,4,1) #define CPUF_LwpCNH CPUIDFIELD_MAKE(0x8000001C,0,0,5,1) #define CPUF_LwpRNH CPUIDFIELD_MAKE(0x8000001C,0,0,6,1) #define CPUF_LwpInt CPUIDFIELD_MAKE(0x8000001C,0,0,31,1) #define CPUF_LwpCbSize CPUIDFIELD_MAKE(0x8000001C,0,1,0,8) #define CPUF_LwpEventSize CPUIDFIELD_MAKE(0x8000001C,0,1,8,8) #define CPUF_LwpMaxEvents CPUIDFIELD_MAKE(0x8000001C,0,1,16,8) #define CPUF_LwpEventOffset CPUIDFIELD_MAKE(0x8000001C,0,1,24,8) #define CPUF_LwpLatencyMax CPUIDFIELD_MAKE(0x8000001C,0,2,0,5) #define CPUF_LwpDataAddress CPUIDFIELD_MAKE(0x8000001C,0,2,5,1) #define CPUF_LwpLatencyRnd CPUIDFIELD_MAKE(0x8000001C,0,2,6,3) #define CPUF_LwpVersion CPUIDFIELD_MAKE(0x8000001C,0,2,9,7) #define CPUF_LwpMinBufferSize CPUIDFIELD_MAKE(0x8000001C,0,2,16,8) #define CPUF_LwpBranchPrediction CPUIDFIELD_MAKE(0x8000001C,0,2,28,1) #define CPUF_LwpIpFiltering CPUIDFIELD_MAKE(0x8000001C,0,2,29,1) #define CPUF_LwpCacheLevels CPUIDFIELD_MAKE(0x8000001C,0,2,30,1) #define CPUF_LwpCacheLatency CPUIDFIELD_MAKE(0x8000001C,0,2,31,1) #define CPUF_D_LwpAvail CPUIDFIELD_MAKE(0x8000001C,0,3,0,1) #define CPUF_D_LwpVAL CPUIDFIELD_MAKE(0x8000001C,0,3,1,1) #define CPUF_D_LwpIRE CPUIDFIELD_MAKE(0x8000001C,0,3,2,1) #define CPUF_D_LwpBRE CPUIDFIELD_MAKE(0x8000001C,0,3,3,1) #define CPUF_D_LwpDME CPUIDFIELD_MAKE(0x8000001C,0,3,4,1) #define CPUF_D_LwpCNH CPUIDFIELD_MAKE(0x8000001C,0,3,5,1) #define CPUF_D_LwpRNH CPUIDFIELD_MAKE(0x8000001C,0,3,6,1) #define CPUF_D_LwpInt CPUIDFIELD_MAKE(0x8000001C,0,3,31,1) #define CPUF_CacheType CPUIDFIELD_MAKE(0x8000001D,0,0,0,5) #define CPUF_CacheLevel CPUIDFIELD_MAKE(0x8000001D,0,0,5,3) #define CPUF_SelfInitialization CPUIDFIELD_MAKE(0x8000001D,0,0,8,1) #define CPUF_FullyAssociative CPUIDFIELD_MAKE(0x8000001D,0,0,9,1) #define CPUF_NumSharingCache CPUIDFIELD_MAKE(0x8000001D,0,0,14,12) #define CPUF_CacheLineSize CPUIDFIELD_MAKE(0x8000001D,0,1,0,12) #define CPUF_CachePhysPartitions CPUIDFIELD_MAKE(0x8000001D,0,1,12,10) #define CPUF_CacheNumWays CPUIDFIELD_MAKE(0x8000001D,0,1,22,10) #define CPUF_CacheNumSets CPUIDFIELD_MAKE(0x8000001D,0,2,0,32) #define CPUF_WBINVD CPUIDFIELD_MAKE(0x8000001D,0,3,0,1) #define CPUF_CacheInclusive CPUIDFIELD_MAKE(0x8000001D,0,3,1,1) #define CPUF_ExtendedApicId CPUIDFIELD_MAKE(0x8000001E,0,0,0,32) #define CPUF_ComputeUnitId CPUIDFIELD_MAKE(0x8000001E,0,1,0,8) #define CPUF_CoresPerComputeUnit CPUIDFIELD_MAKE(0x8000001E,0,1,8,2) #define CPUF_NodeId CPUIDFIELD_MAKE(0x8000001E,0,2,0,8) #define CPUF_NodesPerProcessor CPUIDFIELD_MAKE(0x8000001E,0,2,8,3) // 取得位域 #ifndef __GETBITS32 #define __GETBITS32(src,pos,len) ( ((src)>>(pos)) & (((UINT32)-1)>>(32-len)) ) #endif // 根据CPUIDFIELD从缓冲区中获取字段. inline UINT32 getcpuidfield_buf(const INT32 dwBuf[4], CPUIDFIELD cpuf) { return __GETBITS32(dwBuf[CPUIDFIELD_REG(cpuf)], CPUIDFIELD_POS(cpuf), CPUIDFIELD_LEN(cpuf)); } // 根据CPUIDFIELD获取CPUID字段. inline UINT32 getcpuidfield(CPUIDFIELD cpuf) { INT32 dwBuf[4]; __cpuidex(dwBuf, CPUIDFIELD_FID(cpuf), CPUIDFIELD_FIDSUB(cpuf)); return getcpuidfield_buf(dwBuf, cpuf); } // SSE系列指令集的支持级别. simd_sse_level 函数的返回值. #define SIMD_SSE_NONE 0 // 不支持. #define SIMD_SSE_1 1 // SSE #define SIMD_SSE_2 2 // SSE2 #define SIMD_SSE_3 3 // SSE3 #define SIMD_SSE_3S 4 // SSSE3 #define SIMD_SSE_41 5 // SSE4.1 #define SIMD_SSE_42 6 // SSE4.2 // AVX系列指令集的支持级别. simd_avx_level 函数的返回值。 #define SIMD_AVX_NONE 0 // 不支持 #define SIMD_AVX_1 1 // AVX #define SIMD_AVX_2 2 // AVX2 // functions int cpu_getvendor(char* pvendor); int cpu_getbrand(char* pbrand); int simd_mmx(int* phwmmx); int simd_sse_level(int* phwsse); int simd_avx_level(int* phwavx); typedef struct tagCPUIDINFO{ INT32 fid; INT32 fidsub; union{ INT32 dw[4]; struct{ INT32 _eax; INT32 _ebx; INT32 _ecx; INT32 _edx; }; }; }CPUIDINFO; typedef CPUIDINFO* LPCPUIDINFO; typedef const CPUIDINFO* LPCCPUIDINFO; #define MAX_CPUIDINFO 0x100 // CCPUID类中最多保存多少条CPUIDINFO信息。 #if defined __cplusplus }; #endif class CCPUID{ public: enum { CPUFDescLen = 292 // CPUIDFIELD描述信息数组的长度. }; static const CPUIDFIELDDESC CPUFDesc[CPUFDescLen]; // CPUIDFIELD描述信息数组. static const char* CacheDesc[0x100]; // 缓存描述信息数组. static const char* SseNames[7]; // SSE级别的名称. static const char* AvxNames[3]; // AVX级别的名称. CPUIDINFO Info[MAX_CPUIDINFO+1]; // CPUID信息数组. CCPUID(); static CCPUID& cur() { if(0==_cur._InfoCount){ _cur.RefreshAll(); } return _cur; } // 当前处理器的CCPUID. int InfoCount() const { return _InfoCount; } // Info数组的有效项目数. void RefreshInfo(); // 刷新信息. void RefreshProperty(); // 刷新属性. void RefreshAll(); // 刷新所有. LPCCPUIDINFO GetInfo(INT32 InfoType, INT32 ECXValue=0) const; // 取得信息. void GetData(INT32 CPUInfo[4], INT32 InfoType, INT32 ECXValue=0) const; // 取得数据. UINT32 GetField(CPUIDFIELD cpuf) const; // 取得CPUID字段 // Property int LFuncStd() const { return _LFuncStd; } // 最大的主功能号. int LFuncExt() const { return _LFuncExt; } // 最大的扩展功能号. const char* Vendor() const { return _Vendor; } // 厂商. const char* Brand() const { return _Brand; } // 商标. const char* BrandTrim() const { return _BrandTrim; } // 去掉首都空格后的商标. int mmx() const { return _mmx; } // 系统支持MMX. int hwmmx() const { return _hwmmx; } // 硬件支持MMX. int sse() const { return _sse; } // 系统支持SSE. int hwsse() const { return _hwsse; } // 硬件支持SSE. int avx() const { return _avx; } // 系统支持AVX. int hwavx() const { return _hwavx; } // 硬件支持AVX. private: static CCPUID _cur; // 当前处理器的CCPUID. 为了方便日常使用. int _InfoCount; // Info数组的有效项目数. // Property int _LFuncStd; // 最大的主功能号. int _LFuncExt; // 最大的扩展功能号. char _Vendor[13]; // 厂商. char _Brand[49]; // 商标. const char* _BrandTrim; // 去掉首都空格后的商标. int _mmx; // 系统支持MMX. int _hwmmx; // 硬件支持MMX. int _sse; // 系统支持SSE. int _hwsse; // 硬件支持SSE. int _avx; // 系统支持AVX. int _hwavx; // 硬件支持AVX. void RefreshInfo_Put(INT32 fid, INT32 fidsub, INT32 CPUInfo[4]); int simd_mmx(int* phwmmx) const; int simd_sse_level(int* phwsse) const; int simd_avx_level(int* phwavx) const; }; #endif // #ifndef __CCPUID_H_INCLUDED

3.2 实现文件的全部代码

  ccpuid.cpp—— #include #include "ccpuid.h" CCPUID CCPUID::_cur; const CPUIDFIELDDESC CCPUID::CPUFDesc[] = { {CPUF_LFuncStd, 0, "LFuncStd", "largest standard function."} ,{CPUF_Stepping, 0, "Stepping", "processor stepping."} ,{CPUF_BaseModel, 0, "BaseModel", "base processor model."} ,{CPUF_BaseFamily, 0, "BaseFamily", "base processor family."} ,{CPUF_ProcessorType, 0, "ProcessorType", "processor type."} ,{CPUF_ExtModel, 0, "ExtModel", "processor extended model."} ,{CPUF_ExtFamily, 0, "ExtFamily", "processor extended family."} ,{CPUF_BrandId8, 0, "BrandId8", "8-bit brand ID."} ,{CPUF_CLFlush, 0, "CLFlush", "CLFLUSH line size. (*8)"} ,{CPUF_MaxApicId, 0, "MaxApicId", "Maximum number of addressable IDs for logical processors in this physical package."} ,{CPUF_ApicId, 0, "ApicId", "Initial local APIC physical ID(8-bit)."} ,{CPUF_SSE3, 0, "SSE3", "Streaming SIMD Extensions 3."} ,{CPUF_PCLMULQDQ, 0, "PCLMULQDQ", "PCLMULQDQ instruction."} ,{CPUF_DTES64, 0, "DTES64", "64-bit DS Area."} ,{CPUF_MONITOR, 0, "MONITOR", "MONITOR/MWAIT instructions."} ,{CPUF_DS_CPL, 0, "DS_CPL", "CPL Qualified Debug Store."} ,{CPUF_VMX, 0, "VMX", "Virtual Machine Extensions."} ,{CPUF_SMX, 0, "SMX", "Safer Mode Extensions."} ,{CPUF_EIST, 0, "EIST", "Enhanced Intel SpeedStep technology."} ,{CPUF_TM2, 0, "TM2", "Thermal Monitor 2."} ,{CPUF_SSSE3, 0, "SSSE3", "Supplemental Streaming SIMD Extensions 3 (SSSE3)."} ,{CPUF_CNXT_ID, 0, "CNXT_ID", "L1 Context ID."} ,{CPUF_FMA, 0, "FMA", "supports FMA extensions using YMM state."} ,{CPUF_CMPXCHG16B, 0, "CMPXCHG16B", "CMPXCHG16B instruction."} ,{CPUF_xTPR, 0, "xTPR", "xTPR Update Control. Can disable sending Task Priority messages."} ,{CPUF_PDCM, 0, "PDCM", "Perfmon and Debug Capability."} ,{CPUF_PCID, 0, "PCID", "Process Context Identifiers."} ,{CPUF_DCA, 0, "DCA", "Direct Cache Access."} ,{CPUF_SSE41, 0, "SSE41", "SSE4.1 instructions."} ,{CPUF_SSE42, 0, "SSE42", "SSE4.2 instructions."} ,{CPUF_x2APIC, 0, "x2APIC", "Extended xAPIC Support."} ,{CPUF_MOVBE, 0, "MOVBE", "MOVBE Instruction."} ,{CPUF_POPCNT, 0, "POPCNT", "POPCNT instruction."} ,{CPUF_TSC_DEADLINE, 0, "TSC_DEADLINE", "Local APIC timer supports one-shot operation using a TSC deadline value."} ,{CPUF_AES, 0, "AES", "Advanced Encryption Standard (AES) Instructions."} ,{CPUF_XSAVE, 0, "XSAVE", "XSAVE (and related) instructions are supported by hardware."} ,{CPUF_OSXSAVE, 0, "OSXSAVE", "XSAVE (and related) instructions are enabled."} ,{CPUF_AVX, 0, "AVX", "AVX instructions."} ,{CPUF_F16C, 0, "F16C", "half-precision convert instruction support."} ,{CPUF_RDRAND, 0, "RDRAND", "RDRAND instruction."} ,{CPUF_FPU, 0, "FPU", "Floating Point Unit On-Chip."} ,{CPUF_VME, 0, "VME", "Virtual 8086 Mode Enhancements."} ,{CPUF_DE, 0, "DE", "Debugging Extensions."} ,{CPUF_PSE, 0, "PSE", "Page Size Extension."} ,{CPUF_TSC, 0, "TSC", "Time Stamp Counter."} ,{CPUF_MSR, 0, "MSR", "Model Specific Registers RDMSR and WRMSR Instructions."} ,{CPUF_PAE, 0, "PAE", "Physical Address Extension."} ,{CPUF_MCE, 0, "MCE", "Machine Check Exception."} ,{CPUF_CX8, 0, "CX8", "CMPXCHG8B instruction."} ,{CPUF_APIC, 0, "APIC", "APIC(Advanced Programmable Interrupt Controller) On-Chip."} ,{CPUF_SEP, 0, "SEP", "Fast System Call instructions, SYSENTER and SYSEXIT."} ,{CPUF_MTRR, 0, "MTRR", "Memory Type Range Registers."} ,{CPUF_PGE, 0, "PGE", "Page Global Enable."} ,{CPUF_MCA, 0, "MCA", "Machine-Check Architecture."} ,{CPUF_CMOV, 0, "CMOV", "Conditional Move Instructions."} ,{CPUF_PAT, 0, "PAT", "Page Attribute Table."} ,{CPUF_PSE36, 0, "PSE36", "36-Bit Page Size Extension."} ,{CPUF_PSN, 0, "PSN", "Processor Serial Number."} ,{CPUF_CLFSH, 0, "CLFSH", "CLFLUSH Instruction."} ,{CPUF_DS, 0, "DS", "Debug Store."} ,{CPUF_ACPI, 0, "ACPI", "Thermal Monitor and Software Controlled Clock Facilities."} ,{CPUF_MMX, 0, "MMX", "MMX instructions."} ,{CPUF_FXSR, 0, "FXSR", "FXSAVE and FXRSTOR instructions."} ,{CPUF_SSE, 0, "SSE", "Streaming SIMD Extensions."} ,{CPUF_SSE2, 0, "SSE2", "Streaming SIMD Extensions 2."} ,{CPUF_SS, 0, "SS", "Self Snoop."} ,{CPUF_HTT, 0, "HTT", "Max APIC IDs reserved field is Valid."} ,{CPUF_TM, 0, "TM", "Thermal Monitor."} ,{CPUF_PBE, 0, "PBE", "Pending Break Enable."} ,{CPUF_Cache_Type, 0, "Cache_Type", "Cache Type (0=Null, 1=Data, 2=Instruction, 3=Unified)."} ,{CPUF_Cache_Level, 0, "Cache_Level", "Cache Level (Starts at 1)."} ,{CPUF_CACHE_SI, 0, "CACHE_SI", "Self Initializing cache level."} ,{CPUF_CACHE_FA, 0, "CACHE_FA", "Fully Associative cache."} ,{CPUF_MaxApicIdShare, 0, "MaxApicIdShare", "Maximum number of addressable IDs for logical processors sharing this cache (plus 1 encoding)."} ,{CPUF_MaxApicIdCore, 0, "MaxApicIdCore", "Maximum number of addressable IDs for processor cores in the physical package (plus 1 encoding)."} ,{CPUF_Cache_LineSize, 0, "Cache_LineSize", "System Coherency Line Size (plus 1 encoding)."} ,{CPUF_Cache_Partitions, 0, "Cache_Partitions", "Physical Line partitions (plus 1 encoding)."} ,{CPUF_Cache_Ways, 0, "Cache_Ways", "Ways of Associativity (plus 1 encoding)."} ,{CPUF_Cache_Sets, 0, "Cache_Sets", "Number of Sets (plus 1 encoding)."} ,{CPUF_CACHE_INVD, 0, "CACHE_INVD", "WBINVD/INVD behavior on lower level caches."} ,{CPUF_CACHE_INCLUSIVENESS, 0, "CACHE_INCLUSIVENESS", "Cache is inclusive of lower cache levels."} ,{CPUF_CACHE_COMPLEXINDEX, 0, "CACHE_COMPLEXINDEX", "Complex Cache Indexing."} ,{CPUF_MonLineSizeMin, 0, "MonLineSizeMin", "Smallest monitor line size in bytes."} ,{CPUF_MonLineSizeMax, 0, "MonLineSizeMax", "Largest monitor-line size in bytes."} ,{CPUF_EMX, 0, "EMX", "Enumerate MONITOR/MWAIT extensions."} ,{CPUF_IBE, 0, "IBE", "Interrupt Break-Event."} ,{CPUF_MWAIT_Number_C0, 0, "MWAIT_Number_C0", "Number of C0 sub C-states supported using MWAIT."} ,{CPUF_MWAIT_Number_C1, 0, "MWAIT_Number_C1", "Number of C1 sub C-states supported using MWAIT."} ,{CPUF_MWAIT_Number_C2, 0, "MWAIT_Number_C2", "Number of C2 sub C-states supported using MWAIT."} ,{CPUF_MWAIT_Number_C3, 0, "MWAIT_Number_C3", "Number of C3 sub C-states supported using MWAIT."} ,{CPUF_MWAIT_Number_C4, 0, "MWAIT_Number_C4", "Number of C4 sub C-states supported using MWAIT."} ,{CPUF_DTS, 0, "DTS", "Digital Thermal Sensor."} ,{CPUF_TURBO_BOOST, 0, "TURBO_BOOST", "Intel Turbo Boost Technology."} ,{CPUF_ARAT, 0, "ARAT", "Always Running APIC Timer."} ,{CPUF_PLN, 0, "PLN", "Power Limit Notification."} ,{CPUF_ECMD, 0, "ECMD", "Extended Clock Modulation Duty."} ,{CPUF_PTM, 0, "PTM", "Package Thermal Management."} ,{CPUF_DTS_ITs, 0, "DTS_ITs", "Number of Interrupt Thresholds in Digital Thermal Sensor."} ,{CPUF_PERF, 0, "PERF", "Hardware Coordination Feedback Capability."} ,{CPUF_ACNT2, 0, "ACNT2", "ACNT2 Capability."} ,{CPUF_ENERGY_PERF_BIAS, 0, "ENERGY_PERF_BIAS", "Performance-Energy Bias capability."} ,{CPUF_Max07Subleaf, 0, "Max07Subleaf", "Reports the maximum supported leaf 7 sub-leaf."} ,{CPUF_FSGSBASE, 0, "FSGSBASE", "Supports RDFSBASE/RDGSBASE/WRFSBASE/WRGSBASE."} ,{CPUF_BMI1, 0, "BMI1", "The first group of advanced bit manipulation extensions (ANDN, BEXTR, BLSI, BLSMK, BLSR, TZCNT)."} ,{CPUF_HLE, 0, "HLE", "Hardware Lock Elision."} ,{CPUF_AVX2, 0, "AVX2", "AVX2 instructions."} ,{CPUF_SMEP, 0, "SMEP", "Supervisor Mode Execution Protection."} ,{CPUF_BMI2, 0, "BMI2", "The second group of advanced bit manipulation extensions (BZHI, MULX, PDEP, PEXT, RORX, SARX, SHLX, SHRX)."} ,{CPUF_ERMS, 0, "ERMS", "Supports Enhanced REP MOVSB/STOSB."} ,{CPUF_INVPCID, 0, "INVPCID", "INVPCID instruction."} ,{CPUF_RTM, 0, "RTM", ""} ,{CPUF_PLATFORM_DCA_CAP, 0, "PLATFORM_DCA_CAP", "Value of PLATFORM_DCA_CAP MSR Bits [31:0] (Offset 1F8h)."} ,{CPUF_APM_Version, 0, "APM_Version", "Version ID of architectural performance monitoring."} ,{CPUF_APM_Counters, 0, "APM_Counters", "Number of general-purpose performance monitoring counters per logical processor."} ,{CPUF_APM_Bits, 0, "APM_Bits", "Bit width of general-purpose, performance monitoring counters."} ,{CPUF_APM_Length, 0, "APM_Length", "Length of EBX bit vector to enumerate architectural performance monitoring events."} ,{CPUF_APM_CC, 0, "APM_CC", "Core cycle event not available if 1."} ,{CPUF_APM_IR, 0, "APM_IR", "Instruction retired event not available if 1."} ,{CPUF_APM_RC, 0, "APM_RC", "Reference cycles event not available if 1."} ,{CPUF_APM_LLCR, 0, "APM_LLCR", "Last-level cache reference event not available if 1."} ,{CPUF_APM_LLCM, 0, "APM_LLCM", "Last-level cache misses event not available if 1."} ,{CPUF_APM_BIR, 0, "APM_BIR", "Branch instruction retired event not available if 1."} ,{CPUF_APM_BMR, 0, "APM_BMR", "Branch mispredict retired event not available if 1."} ,{CPUF_APM_FC_Number, 0, "APM_FC_Number", "Number of fixed-function performance counters."} ,{CPUF_APM_FC_Bits, 0, "APM_FC_Bits", "Bit width of fixed-function performance counters."} ,{CPUF_Topology_Bits, 0, "Topology_Bits", "Number of bits to shift right on x2APIC ID to get a unique topology ID of the next level type."} ,{CPUF_Topology_Number, 0, "Topology_Number", "Number of factory-configured logical processors at this level."} ,{CPUF_Topology_Level, 0, "Topology_Level", "Level number. Same value in ECX input."} ,{CPUF_Topology_Type, 0, "Topology_Type", "Level Type (0=Invalid, 1=Thread, 2=Core)."} ,{CPUF_X2APICID, 0, "X2APICID", "x2APIC ID."} ,{CPUF_XFeatureSupportedMaskLo, 0, "XFeatureSupportedMaskLo", "The lower 32 bits of XCR0(XFEATURE_ENABLED_MASK register)."} ,{CPUF_XFeatureEnabledSizeMax, 0, "XFeatureEnabledSizeMax", "Size in bytes of XSAVE/XRSTOR area for the currently enabled features in XCR0."} ,{CPUF_XFeatureSupportedSizeMax, 0, "XFeatureSupportedSizeMax", "Size in bytes of XSAVE/XRSTOR area for all features that the core supports."} ,{CPUF_XFeatureSupportedMaskHi, 0, "XFeatureSupportedMaskHi", "The upper 32 bits of XCR0(XFEATURE_ENABLED_MASK register)."} ,{CPUF_XSAVEOPT, 0, "XSAVEOPT", "XSAVEOPT is available."} ,{CPUF_YmmSaveStateSize, 0, "YmmSaveStateSize", "YMM save state byte size."} ,{CPUF_YmmSaveStateOffset, 0, "YmmSaveStateOffset", "YMM save state byte offset."} ,{CPUF_LwpSaveStateSize, 0, "LwpSaveStateSize", "LWP save state byte size."} ,{CPUF_LwpSaveStateOffset, 0, "LwpSaveStateOffset", "LWP save state byte offset."} ,{CPUF_LFuncExt, 0, "LFuncExt", "Largest extended function."} ,{CPUF_BrandId16, 0, "BrandId16", "16-bit Brand ID."} ,{CPUF_PkgType, 0, "PkgType", "Package type (Family[7:0] >= 10h)."} ,{CPUF_LahfSahf, 0, "LahfSahf", "LAHF and SAHF instruction support in 64-bit mode."} ,{CPUF_CmpLegacy, 0, "CmpLegacy", "core multi-processing legacy mode."} ,{CPUF_SVM, 0, "SVM", "secure virtual machine."} ,{CPUF_ExtApicSpace, 0, "ExtApicSpace", "extended APIC space."} ,{CPUF_AltMovCr8, 0, "AltMovCr8", "LOCK MOV CR0 means MOV CR8."} ,{CPUF_ABM, 0, "ABM", "advanced bit manipulation (LZCNT)."} ,{CPUF_SSE4A, 0, "SSE4A", "SSE4A instructions."} ,{CPUF_MisAlignSse, 0, "MisAlignSse", "misaligned SSE mode."} ,{CPUF_3DNowPrefetch, 0, "3DNowPrefetch", "PREFETCH and PREFETCHW instruction support."} ,{CPUF_OSVW, 0, "OSVW", "OS visible workaround."} ,{CPUF_IBS, 0, "IBS", "instruction based sampling."} ,{CPUF_XOP, 0, "XOP", "extended operation support."} ,{CPUF_SKINIT, 0, "SKINIT", "SKINIT and STGI are supported, independent of the value of MSRC000_0080[SVME]."} ,{CPUF_WDT, 0, "WDT", "watchdog timer support."} ,{CPUF_LWP, 0, "LWP", "lightweight profiling support."} ,{CPUF_FMA4, 0, "FMA4", "4-operand FMA instruction support."} ,{CPUF_BIT_NODEID, 0, "BIT_NODEID", "Indicates support for MSRC001_100C[NodeId, NodesPerProcessor]."} ,{CPUF_TBM, 0, "TBM", "Trailing bit manipulation instruction support."} ,{CPUF_TopologyExtensions, 0, "TopologyExtensions", "Topology extensions support."} ,{CPUF_SYSCALL, 0, "SYSCALL", "SYSCALL and SYSRET instructions."} ,{CPUF_XD, 0, "XD", "Execution Disable Bit."} ,{CPUF_MmxExt, 0, "MmxExt", "AMD extensions to MMX instructions."} ,{CPUF_FFXSR, 0, "FFXSR", "FXSAVE and FXRSTOR instruction optimizations."} ,{CPUF_Page1GB, 0, "Page1GB", "1-GB large page support."} ,{CPUF_RDTSCP, 0, "RDTSCP", "RDTSCP and TSC_AUX."} ,{CPUF_LM, 0, "LM", "64-bit long mode.(x86-64)"} ,{CPUF_3DNowExt, 0, "3DNowExt", "AMD extensions to 3DNow! instructions."} ,{CPUF_3DNow, 0, "3DNow", "3DNow! instructions."} ,{CPUF_L1ITlb2and4MSize, 0, "L1ITlb2and4MSize", "Instruction TLB number of entries for 2-MB and 4-MB pages."} ,{CPUF_L1ITlb2and4MAssoc, 0, "L1ITlb2and4MAssoc", "Instruction TLB associativity for 2-MB and 4-MB pages."} ,{CPUF_L1DTlb2and4MSize, 0, "L1DTlb2and4MSize", "Data TLB number of entries for 2-MB and 4-MB pages."} ,{CPUF_L1DTlb2and4MAssoc, 0, "L1DTlb2and4MAssoc", "Data TLB associativity for 2-MB and 4-MB pages."} ,{CPUF_L1ITlb4KSize, 0, "L1ITlb4KSize", "Instruction TLB number of entries for 4 KB pages."} ,{CPUF_L1ITlb4KAssoc, 0, "L1ITlb4KAssoc", "Instruction TLB associativity for 4KB pages."} ,{CPUF_L1DTlb4KSize, 0, "L1DTlb4KSize", "Data TLB number of entries for 4 KB pages."} ,{CPUF_L1DTlb4KAssoc, 0, "L1DTlb4KAssoc", "Data TLB associativity for 4 KB pages."} ,{CPUF_L1DcLineSize, 0, "L1DcLineSize", "L1 data cache line size in bytes."} ,{CPUF_L1DcLinesPerTag, 0, "L1DcLinesPerTag", "L1 data cache lines per tag."} ,{CPUF_L1DcAssoc, 0, "L1DcAssoc", "L1 data cache associativity."} ,{CPUF_L1DcSize, 0, "L1DcSize", "L1 data cache size in KB."} ,{CPUF_L1IcLineSize, 0, "L1IcLineSize", "L1 instruction cache line size in bytes"} ,{CPUF_L1IcLinesPerTag, 0, "L1IcLinesPerTag", "L1 instruction cache lines per tag."} ,{CPUF_L1IcAssoc, 0, "L1IcAssoc", "L1 instruction cache associativity."} ,{CPUF_L1IcSize, 0, "L1IcSize", "L1 instruction cache size KB."} ,{CPUF_L2ITlb2and4MSize, 0, "L2ITlb2and4MSize", "L2 instruction TLB number of entries for 2 MB and 4 MB pages."} ,{CPUF_L2ITlb2and4MAssoc, 0, "L2ITlb2and4MAssoc", "L2 instruction TLB associativity for 2 MB and 4 MB pages."} ,{CPUF_L2DTlb2and4MSize, 0, "L2DTlb2and4MSize", "L2 data TLB number of entries for 2 MB and 4 MB pages."} ,{CPUF_L2DTlb2and4MAssoc, 0, "L2DTlb2and4MAssoc", "L2 data TLB associativity for 2 MB and 4 MB pages."} ,{CPUF_L2ITlb4KSize, 0, "L2ITlb4KSize", "L2 instruction TLB number of entries for 4 KB pages."} ,{CPUF_L2ITlb4KAssoc, 0, "L2ITlb4KAssoc", "L2 instruction TLB associativity for 4 KB pages."} ,{CPUF_L2DTlb4KSize, 0, "L2DTlb4KSize", "L2 data TLB number of entries for 4 KB pages."} ,{CPUF_L2DTlb4KAssoc, 0, "L2DTlb4KAssoc", "L2 data TLB associativity for 4 KB pages."} ,{CPUF_L2LineSize, 0, "L2LineSize", "L2 cache line size in bytes."} ,{CPUF_L2LinesPerTag, 0, "L2LinesPerTag", "L2 cache lines per tag."} ,{CPUF_L2Assoc, 0, "L2Assoc", "L2 cache associativity."} ,{CPUF_L2Size, 0, "L2Size", "L2 cache size in KB."} ,{CPUF_L3LineSize, 0, "L3LineSize", "L3 cache line size in bytes."} ,{CPUF_L3LinesPerTag, 0, "L3LinesPerTag", "L3 cache lines per tag."} ,{CPUF_L3Assoc, 0, "L3Assoc", "L3 cache associativity."} ,{CPUF_L3Size, 0, "L3Size", "L3 cache size."} ,{CPUF_TS, 0, "TS", "Temperature sensor."} ,{CPUF_FID, 0, "FID", "Frequency ID control."} ,{CPUF_VID, 0, "VID", "Voltage ID control."} ,{CPUF_TTP, 0, "TTP", "THERMTRIP."} ,{CPUF_HTC, 0, "HTC", "TM: Hardware thermal control (HTC)."} ,{CPUF_100MHzSteps, 0, "100MHzSteps", "100 MHz multiplier Control."} ,{CPUF_HwPstate, 0, "HwPstate", "Hardware P-state control."} ,{CPUF_TscInvariant, 0, "TscInvariant", "TSC invariant."} ,{CPUF_CPB, 0, "CPB", "Core performance boost."} ,{CPUF_EffFreqRO, 0, "EffFreqRO", "Read-only effective frequency interface."} ,{CPUF_PhysAddrSize, 0, "PhysAddrSize", "Maximum physical byte address size in bits."} ,{CPUF_LinAddrSize, 0, "LinAddrSize", "Maximum linear byte address size in bits."} ,{CPUF_GuestPhysAddrSize, 0, "GuestPhysAddrSize", "Maximum guest physical byte address size in bits."} ,{CPUF_NC, 0, "NC", "number of physical cores - 1."} ,{CPUF_ApicIdCoreIdSize, 0, "ApicIdCoreIdSize", "APIC ID size. The number of bits in the initial APIC20[ApicId] value that indicate core ID within a processor."} ,{CPUF_SvmRev, 0, "SvmRev", "SVM revision."} ,{CPUF_NASID, 0, "NASID", "number of address space identifiers (ASID)."} ,{CPUF_NP, 0, "NP", "Nested paging."} ,{CPUF_LbrVirt, 0, "LbrVirt", "LBR virtualization."} ,{CPUF_SVML, 0, "SVML", "SVM lock. Indicates support for SVM-Lock."} ,{CPUF_NRIPS, 0, "NRIPS", "NRIP save. Indicates support for NRIP save on #VMEXIT."} ,{CPUF_TscRateMsr, 0, "TscRateMsr", "MSR based TSC rate control."} ,{CPUF_VmcbClean, 0, "VmcbClean", "VMCB clean bits. Indicates support for VMCB clean bits."} ,{CPUF_FlushByAsid, 0, "FlushByAsid", "Flush by ASID."} ,{CPUF_DecodeAssists, 0, "DecodeAssists", "Decode assists."} ,{CPUF_PauseFilter, 0, "PauseFilter", "Pause intercept filter."} ,{CPUF_PauseFilterThreshold, 0, "PauseFilterThreshold", "PAUSE filter threshold."} ,{CPUF_L1ITlb1GSize, 0, "L1ITlb1GSize", "L1 instruction TLB number of entries for 1 GB pages."} ,{CPUF_L1ITlb1GAssoc, 0, "L1ITlb1GAssoc", "L1 instruction TLB associativity for 1 GB pages."} ,{CPUF_L1DTlb1GSize, 0, "L1DTlb1GSize", "L1 data TLB number of entries for 1 GB pages."} ,{CPUF_L1DTlb1GAssoc, 0, "L1DTlb1GAssoc", "L1 data TLB associativity for 1 GB pages."} ,{CPUF_L2ITlb1GSize, 0, "L2ITlb1GSize", "L2 instruction TLB number of entries for 1 GB pages."} ,{CPUF_L2ITlb1GAssoc, 0, "L2ITlb1GAssoc", "L2 instruction TLB associativity for 1 GB pages."} ,{CPUF_L2DTlb1GSize, 0, "L2DTlb1GSize", "L2 data TLB number of entries for 1 GB pages."} ,{CPUF_L2DTlb1GAssoc, 0, "L2DTlb1GAssoc", "L2 data TLB associativity for 1 GB pages."} ,{CPUF_FP128, 0, "FP128", "128-bit SSE (multimedia) instructions are executed with full-width internal operations and pipelines rather than decomposing them into internal 64-bit suboperations."} ,{CPUF_MOVU, 0, "MOVU", "MOVU SSE (multimedia) instructions are more efficient and should be preferred to SSE(multimedia) MOVL/MOVH. MOVUPS is more efficient than MOVLPS/MOVHPS."} ,{CPUF_IBSFFV, 0, "IBSFFV", "IBS feature flags valid."} ,{CPUF_FetchSam, 0, "FetchSam", "IBS fetch sampling supported."} ,{CPUF_OpSam, 0, "OpSam", "IBS execution sampling supported."} ,{CPUF_RdWrOpCnt, 0, "RdWrOpCnt", "Read write of op counter supported."} ,{CPUF_OpCnt, 0, "OpCnt", "Op counting mode supported."} ,{CPUF_BrnTrgt, 0, "BrnTrgt", "Branch target address reporting supported."} ,{CPUF_OpCntExt, 0, "OpCntExt", "IbsOpCurCnt and IbsOpMaxCnt extend by 7 bits."} ,{CPUF_RipInvalidChk, 0, "RipInvalidChk", "Invalid RIP indication supported."} ,{CPUF_LwpAvail, 0, "LwpAvail", "LWP available."} ,{CPUF_LwpVAL, 0, "LwpVAL", "LWPVAL instruction available."} ,{CPUF_LwpIRE, 0, "LwpIRE", "instructions retired event available."} ,{CPUF_LwpBRE, 0, "LwpBRE", "branch retired event available."} ,{CPUF_LwpDME, 0, "LwpDME", "DC miss event available."} ,{CPUF_LwpCNH, 0, "LwpCNH", "core clocks not halted event available."} ,{CPUF_LwpRNH, 0, "LwpRNH", "core reference clocks not halted event available."} ,{CPUF_LwpInt, 0, "LwpInt", "interrupt on threshold overflow available."} ,{CPUF_LwpCbSize, 0, "LwpCbSize", "control block size. Size in bytes of the LWPCB."} ,{CPUF_LwpEventSize, 0, "LwpEventSize", "event record size. Size in bytes of an event record in the LWP event ring buffer."} ,{CPUF_LwpMaxEvents, 0, "LwpMaxEvents", "maximum EventId. Maximum EventId value that is supported."} ,{CPUF_LwpEventOffset, 0, "LwpEventOffset", "offset to the EventInterval1 field. Offset from the start of the LWPCB to the EventInterval1 field."} ,{CPUF_LwpLatencyMax, 0, "LwpLatencyMax", "latency counter bit size. Size in bits of the cache latency counters."} ,{CPUF_LwpDataAddress, 0, "LwpDataAddress", "data cache miss address valid."} ,{CPUF_LwpLatencyRnd, 0, "LwpLatencyRnd", "amount cache latency is rounded."} ,{CPUF_LwpVersion, 0, "LwpVersion", "version. Version of LWP implementation."} ,{CPUF_LwpMinBufferSize, 0, "LwpMinBufferSize", "event ring buffer size. Minimum size of the LWP event ring buffer, in units of 32 event records."} ,{CPUF_LwpBranchPrediction, 0, "LwpBranchPrediction", "branch prediction filtering supported."} ,{CPUF_LwpIpFiltering, 0, "LwpIpFiltering", "IP filtering supported."} ,{CPUF_LwpCacheLevels, 0, "LwpCacheLevels", "cache level filtering supported."} ,{CPUF_LwpCacheLatency, 0, "LwpCacheLatency", "cache latency filtering supported."} ,{CPUF_D_LwpAvail, 0, "D_LwpAvail", "lightweight profiling supported."} ,{CPUF_D_LwpVAL, 0, "D_LwpVAL", "LWPVAL instruction supported."} ,{CPUF_D_LwpIRE, 0, "D_LwpIRE", "instructions retired event supported."} ,{CPUF_D_LwpBRE, 0, "D_LwpBRE", "branch retired event supported."} ,{CPUF_D_LwpDME, 0, "D_LwpDME", "DC miss event supported."} ,{CPUF_D_LwpCNH, 0, "D_LwpCNH", "core clocks not halted event supported."} ,{CPUF_D_LwpRNH, 0, "D_LwpRNH", "core reference clocks not halted event supported."} ,{CPUF_D_LwpInt, 0, "D_LwpInt", "interrupt on threshold overflow supported."} ,{CPUF_CacheType, 0, "CacheType", "Cache Type (0=Null, 1=Data, 2=Instruction, 3=Unified)."} ,{CPUF_CacheLevel, 0, "CacheLevel", "Cache Level (Starts at 1)."} ,{CPUF_SelfInitialization, 0, "SelfInitialization", "Self Initializing cache level."} ,{CPUF_FullyAssociative, 0, "FullyAssociative", "Fully Associative cache."} ,{CPUF_NumSharingCache, 0, "NumSharingCache", "Number of cores sharing cache. The number of cores sharing this cache is NumSharingCache+1."} ,{CPUF_CacheLineSize, 0, "CacheLineSize", "Cache line size in bytes (plus 1 encoding)."} ,{CPUF_CachePhysPartitions, 0, "CachePhysPartitions", "Cache physical line partitions (plus 1 encoding)."} ,{CPUF_CacheNumWays, 0, "CacheNumWays", "Cache number of ways (plus 1 encoding)."} ,{CPUF_CacheNumSets, 0, "CacheNumSets", "Cache number of sets (plus 1 encoding)."} ,{CPUF_WBINVD, 0, "WBINVD", "Write-Back Invalidate/Invalidate (WBINVD/INVD)."} ,{CPUF_CacheInclusive, 0, "CacheInclusive", "Cache inclusive."} ,{CPUF_ExtendedApicId, 0, "ExtendedApicId", "extended APIC ID."} ,{CPUF_ComputeUnitId, 0, "ComputeUnitId", "compute unit ID. Identifies the processor compute unit ID."} ,{CPUF_CoresPerComputeUnit, 0, "CoresPerComputeUnit", "cores per compute unit. The number of cores per compute unit is CoresPerComputeUnit+1."} ,{CPUF_NodeId, 0, "NodeId", "Specifies the node ID."} ,{CPUF_NodesPerProcessor, 0, "NodesPerProcessor", "Specifies the number of nodes per processor."} }; const char* CCPUID::CacheDesc[] = { "Null descriptor, this byte contains no information" ,"Instruction TLB: 4 KByte pages, 4-way set associative, 32 entries" ,"Instruction TLB: 4 MByte pages, fully associative, 2 entries" ,"Data TLB: 4 KByte pages, 4-way set associative, 64 entries" ,"Data TLB: 4 MByte pages, 4-way set associative, 8 entries" ,"Data TLB1: 4 MByte pages, 4-way set associative, 32 entries" ,"1st-level instruction cache: 8 KBytes, 4-way set associative, 32 byte line size" ,"" ,"1st-level instruction cache: 16 KBytes, 4-way set associative, 32 byte line size" ,"1st-level instruction cache: 32KBytes, 4-way set associative, 64 byte line size" ,"1st-level data cache: 8 KBytes, 2-way set associative, 32 byte line size" ,"Instruction TLB: 4 MByte pages, 4-way set associative, 4 entries" ,"1st-level data cache: 16 KBytes, 4-way set associative, 32 byte line size" ,"1st-level data cache: 16 KBytes, 4-way set associative, 64 byte line size" ,"1st-level data cache: 24 KBytes, 6-way set associative, 64 byte line size" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"2nd-level cache: 256 KBytes, 8-way set associative, 64 byte line size" ,"3rd-level cache: 512 KBytes, 4-way set associative, 64 byte line size, 2 lines per sector" ,"3rd-level cache: 1 MBytes, 8-way set associative, 64 byte line size, 2 lines per sector" ,"" ,"3rd-level cache: 2 MBytes, 8-way set associative, 64 byte line size, 2 lines per sector" ,"" ,"" ,"" ,"3rd-level cache: 4 MBytes, 8-way set associative, 64 byte line size, 2 lines per sector" ,"" ,"" ,"1st-level data cache: 32 KBytes, 8-way set associative, 64 byte line size" ,"" ,"" ,"" ,"1st-level instruction cache: 32 KBytes, 8-way set associative, 64 byte line size" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"No 2nd-level cache or, if processor contains a valid 2nd-level cache, no 3rd-level cache" ,"2nd-level cache: 128 KBytes, 4-way set associative, 32 byte line size" ,"2nd-level cache: 256 KBytes, 4-way set associative, 32 byte line size" ,"2nd-level cache: 512 KBytes, 4-way set associative, 32 byte line size" ,"2nd-level cache: 1 MByte, 4-way set associative, 32 byte line size" ,"2nd-level cache: 2 MByte, 4-way set associative, 32 byte line size" ,"3rd-level cache: 4 MByte, 4-way set associative, 64 byte line size" ,"3rd-level cache: 8 MByte, 8-way set associative, 64 byte line size" ,"2nd-level cache: 3MByte, 12-way set associative, 64 byte line size" ,"3rd-level cache: 4MB, 16-way set associative, 64-byte line size (Intel Xeon processor MP, Family 0FH, Model 06H); 2nd-level cache: 4 MByte, 16-way set associative, 64 byte line size" ,"3rd-level cache: 6MByte, 12-way set associative, 64 byte line size" ,"3rd-level cache: 8MByte, 16-way set associative, 64 byte line size" ,"3rd-level cache: 12MByte, 12-way set associative, 64 byte line size" ,"3rd-level cache: 16MByte, 16-way set associative, 64 byte line size" ,"2nd-level cache: 6MByte, 24-way set associative, 64 byte line size" ,"Instruction TLB: 4 KByte pages, 32 entries" ,"Instruction TLB: 4 KByte and 2-MByte or 4-MByte pages, 64 entries" ,"Instruction TLB: 4 KByte and 2-MByte or 4-MByte pages, 128 entries" ,"Instruction TLB: 4 KByte and 2-MByte or 4-MByte pages, 256 entries" ,"" ,"" ,"Instruction TLB: 2-MByte or 4-MByte pages, fully associative, 7 entries" ,"Data TLB0: 4 MByte pages, 4-way set associative, 16 entries" ,"Data TLB0: 4 KByte pages, 4-way associative, 16 entries" ,"Data TLB0: 4 KByte pages, fully associative, 16 entries" ,"Data TLB0: 2-MByte or 4 MByte pages, 4-way set associative, 32 entries" ,"Data TLB: 4 KByte and 4 MByte pages, 64 entries" ,"Data TLB: 4 KByte and 4 MByte pages,128 entries" ,"Data TLB: 4 KByte and 4 MByte pages,256 entries" ,"" ,"" ,"" ,"1st-level data cache: 16 KByte, 8-way set associative, 64 byte line size" ,"" ,"" ,"" ,"" ,"" ,"1st-level data cache: 8 KByte, 4-way set associative, 64 byte line size" ,"1st-level data cache: 16 KByte, 4-way set associative, 64 byte line size" ,"1st-level data cache: 32 KByte, 4-way set associative, 64 byte line size" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"Trace cache: 12 K-μop, 8-way set associative" ,"Trace cache: 16 K-μop, 8-way set associative" ,"Trace cache: 32 K-μop, 8-way set associative" ,"" ,"" ,"" ,"Instruction TLB: 2M/4M pages, fully associative, 8 entries" ,"" ,"2nd-level cache: 1 MByte, 4-way set associative, 64byte line size" ,"2nd-level cache: 128 KByte, 8-way set associative, 64 byte line size, 2 lines per sector" ,"2nd-level cache: 256 KByte, 8-way set associative, 64 byte line size, 2 lines per sector" ,"2nd-level cache: 512 KByte, 8-way set associative, 64 byte line size, 2 lines per sector" ,"2nd-level cache: 1 MByte, 8-way set associative, 64 byte line size, 2 lines per sector" ,"2nd-level cache: 2 MByte, 8-way set associative, 64byte line size" ,"" ,"2nd-level cache: 512 KByte, 2-way set associative, 64-byte line size" ,"2nd-level cache: 512 KByte, 8-way set associative, 64-byte line size" ,"" ,"2nd-level cache: 256 KByte, 8-way set associative, 32 byte line size" ,"2nd-level cache: 512 KByte, 8-way set associative, 32 byte line size" ,"2nd-level cache: 1 MByte, 8-way set associative, 32 byte line size" ,"2nd-level cache: 2 MByte, 8-way set associative, 32 byte line size" ,"2nd-level cache: 512 KByte, 4-way set associative, 64 byte line size" ,"2nd-level cache: 1 MByte, 8-way set associative, 64 byte line size" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"Instruction TLB: 4 KByte pages, 4-way set associative, 128 entries" ,"Instruction TLB: 2M pages, 4-way, 8 entries or 4M pages, 4-way, 4 entries" ,"Instruction TLB: 4KByte pages, 4-way set associative, 64 entries" ,"Data TLB: 4 KByte pages, 4-way set associative, 128 entries" ,"Data TLB1: 4 KByte pages, 4-way associative, 256 entries" ,"" ,"" ,"" ,"" ,"" ,"Data TLB1: 4 KByte pages, 4-way associative, 64 entries" ,"" ,"" ,"" ,"" ,"" ,"Data TLB: 4 KByte and 4 MByte pages, 4-way associative, 8 entries" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"Shared 2nd-Level TLB: 4 KByte pages, 4-way associative, 512 entries" ,"" ,"" ,"" ,"" ,"" ,"3rd-level cache: 512 KByte, 4-way set associative, 64 byte line size" ,"3rd-level cache: 1 MByte, 4-way set associative, 64 byte line size" ,"3rd-level cache: 2 MByte, 4-way set associative, 64 byte line size" ,"" ,"" ,"" ,"3rd-level cache: 1 MByte, 8-way set associative, 64 byte line size" ,"3rd-level cache: 2 MByte, 8-way set associative, 64 byte line size" ,"3rd-level cache: 4 MByte, 8-way set associative, 64 byte line size" ,"" ,"" ,"" ,"3rd-level cache: 1.5 MByte, 12-way set associative, 64 byte line size" ,"3rd-level cache: 3 MByte, 12-way set associative, 64 byte line size" ,"3rd-level cache: 6 MByte, 12-way set associative, 64 byte line size" ,"" ,"" ,"" ,"3rd-level cache: 2 MByte, 16-way set associative, 64 byte line size" ,"3rd-level cache: 4 MByte, 16-way set associative, 64 byte line size" ,"3rd-level cache: 8 MByte, 16-way set associative, 64 byte line size" ,"" ,"" ,"" ,"" ,"" ,"3rd-level cache: 12MByte, 24-way set associative, 64 byte line size" ,"3rd-level cache: 18MByte, 24-way set associative, 64 byte line size" ,"3rd-level cache: 24MByte, 24-way set associative, 64 byte line size" ,"" ,"" ,"" ,"64-Byte prefetching" ,"128-Byte prefetching" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,"CPUID leaf 2 does not report cache descriptor information, use CPUID leaf 4 to query cache parameters" }; const char* CCPUID::SseNames[] = { "None", "SSE", "SSE2", "SSE3", "SSSE3", "SSE4.1", "SSE4.2", }; const char* CCPUID::AvxNames[] = { "None", "AVX", "AVX2" }; //////////////////////////////////////////////////////////// // functions //////////////////////////////////////////////////////////// // 取得CPU厂商(Vendor). // // result: 成功时返回字符串的长度(一般为12)。失败时返回0. // pvendor: 接收厂商信息的字符串缓冲区。至少为13字节. int cpu_getvendor(char* pvendor) { INT32 dwBuf[4]; if (NULL==pvendor) return 0; // Function 0: Vendor-ID and Largest Standard Function __cpuid(dwBuf, 0); // save. 保存到pvendor *(INT32*)&pvendor[0] = dwBuf[1]; // ebx: 前四个字符. *(INT32*)&pvendor[4] = dwBuf[3]; // edx: 中间四个字符. *(INT32*)&pvendor[8] = dwBuf[2]; // ecx: 最后四个字符. pvendor[12] = '