本文共 1512 字,大约阅读时间需要 5 分钟。
转自:http://blog.csdn.net/xiaoyi247/article/details/7917537
CPUID指令是用来搜集当前程序正在运行的处理器信息的,包括厂商和信号信息。在IA-32中,CPUID指令使用EAX寄存器作为输入,EAX寄存器用来指定需要查看的信息的类型,根据EAX的数值的不同,CPUID指令会产生不同的信息,存入EBX,ECX,EDX寄存器中。
下面的表格显示了在指定不同的EAX的值的时候,得到的CPU的信息
EAX Value | CPUID Output |
0 | Vendor ID string, and the maximum CPUID option value supported |
1 | Processor type, family, model, and stepping information |
2 | Processor cache configuration |
3 | Processor serial number |
4 | Cache configuration (number of threads, number of cores, and physical properties) |
5 | Monitor information |
80000000h | Extended vendor ID string and supported levels |
80000001h | Extended processor type, family, model, and stepping information |
80000002h | Extended processor name string |
或者更详细的信息,可以参看INTEL的文档
Intel® Processor Identification and the CPUID Instruction
当EAX为0时,CPUID指令产生一个字符串,将存入EBX,EDX和ECX中。其中,EBX包含字符串的后面四个字符,EDX包含中间四个字符,ECX包含前面四个字符。
x264中的汇编代码解析
cglobal x264_cpu_cpuid, 5,7
push rbx mov r11, r1 mov r10, r2 movifnidn r9, r3 movifnidn r8, r4 mov eax, r0d ;将要指定的参数存入到eax中 cpuid mov [r11], eax ;将操作结果存入eax,ebx,ecx,edx mov [r10], ebx mov [r9], ecx mov [r8], edx pop rbx RETcpu.c中根据的到的数据来判断是否支持某种多媒体指令
x264_cpu_cpuid( 1, &eax, &ebx, &ecx, &edx );
if( edx&0x00800000 ) cpu |= X264_CPU_MMX; else return 0; if( edx&0x02000000 ) cpu |= X264_CPU_MMXEXT|X264_CPU_SSE; if( edx&0x04000000 ) cpu |= X264_CPU_SSE2; if( ecx&0x00000001 ) cpu |= X264_CPU_SSE3; if( ecx&0x00000200 ) cpu |= X264_CPU_SSSE3; if( ecx&0x00080000 ) cpu |= X264_CPU_SSE4; if( ecx&0x00100000 ) cpu |= X264_CPU_SSE42;