Assembly 检测AMD CPU是否有模块
有些英特尔CPU有超线程,我可以通过读取来检测。AMD CPU没有超线程,但其中一些有超线程。是否有一种方法(例如通过CPUID)来检测CPU是否有模块 编辑:根据Jester的回答,我提出了以下未经测试的函数(我没有访问AMD处理器)来确定每个“计算单元”(又名模块)的内核数Assembly 检测AMD CPU是否有模块,assembly,x86,intrinsics,amd-processor,cpuid,Assembly,X86,Intrinsics,Amd Processor,Cpuid,有些英特尔CPU有超线程,我可以通过读取来检测。AMD CPU没有超线程,但其中一些有超线程。是否有一种方法(例如通过CPUID)来检测CPU是否有模块 编辑:根据Jester的回答,我提出了以下未经测试的函数(我没有访问AMD处理器)来确定每个“计算单元”(又名模块)的内核数 //输入:eax=functionnumber,ecx=0 //输出:eax=输出[0],ebx=输出[1],ecx=输出[2],edx=输出[3] //静态内联void cpuid(int-output[4],int-
//输入:eax=functionnumber,ecx=0
//输出:eax=输出[0],ebx=输出[1],ecx=输出[2],edx=输出[3]
//静态内联void cpuid(int-output[4],int-functionnumber)
void coresPerComputeUnit(){
int abcd[4];
int核=1;
cpuid(abcd,0x8000000);
if(abcd[0]>8;//ebx位15:8 CoresPerComputeUnit
}
您可以使用cpuid Fn8000\u 001E计算单元标识符。
EBX
(即BH
)的位15:8包含CoresPerComputeUnit:每个计算单元的内核数。值:特定于产品。每个计算单元的内核数为CoresPerComputeUnit+1
请参阅《AMD Bios和内核开发人员指南》。这还不足以回答您的问题,但第E5节(多核计算)提到了如何确定一个处理器有多少个内核。与架构本身不同,这可能是确定AMD处理器是否使用推土机的最佳方法。(我链接的手册至少没有“推土机”的实例。)我添加了一些未经测试的代码来执行此操作。我不确定是否要检查FN8000001e的可用性。我没有和AMD系统来测试此功能。在我的FX-8350上运行良好。您测试了我的功能,它的核心数为2?感谢您的检查!
// input: eax = functionnumber, ecx = 0
// output: eax = output[0], ebx = output[1], ecx = output[2], edx = output[3]
//static inline void cpuid (int output[4], int functionnumber)
void coresPerComputeUnit() {
int abcd[4];
int cores = 1;
cpuid(abcd,0x80000000);
if(abcd[0]<0x8000001E) return; // Fn8000_001E not available
cpuid(abcd,0x8000001E);
cores += (abcd[1] & 0xff00) >> 8; //ebx bit 15:8 CoresPerComputeUnit
}