CPUIDは、x86の機械語命令の一つ(およびそのアセンブリ・ニーモニック)である。CPUの識別 (IDentification) の意。486の後期のステッピングで導入され、Pentiumで完全に公開された。
CPUIDを使用することで、ソフトウェアはプロセッサの形式と機能(例えば、MMXやSSEなどの拡張のサポートの有無)を識別することができる。機械語オペコードは0F A2であり、オペランドとしてEAXレジスタの値でどのような情報を取得するかを指定する。
CPUID命令は一部の80486およびそれ以降のプロセッサで利用できるため、場合によってはCPUID命令が存在するプロセッサであるか否かを事前に判別する必要が生じる。80486以前のプロセッサを識別する必要がある場合には、それぞれの振舞の微妙な違いを利用する難解なテクニックを駆使する必要があった(たとえばPUSH SPの結果として、PUSHによる変化前と変化後の、どちらの値がプッシュされるか、等)。
80486以上のプロセッサであることが確認できた場合、CPUID命令の存在を確認するためのフラグとして32ビットフラグレジスタ (EFLAGS) の第21ビットが新たに設けられているため、このビットが「変更可能」であればCPUID命令が使用可能であると判断できる。なおEFLAGSは80386以上のプロセッサであればアクセスできるため、80286以下のプロセッサを判別・除外しておく必要はあるものの、CPUID命令の有無だけを調べたいのであれば実質的に80386以上であることが確認できればこのフラグを調べることができる。
CPUID命令は、EAXレジスタが暗黙のオペランドであり、それ以外の(明示的な)オペランドは無い。どのような情報を返すべきかを指定する値をEAXレジスタに設定し、CPUID命令を実行する。まずEAX = 0でCPUIDを呼び出し、CPUでサポートされている最大のパラメータを取得するべきである。CPUIDの拡張機能情報を取得する場合は、EAXのビット31をセットしてCPUIDを呼び出す。拡張機能情報でサポートされている最大の機能番号を得るためには、EAX = 80000000hでCPUIDを呼び出す。
これは、CPUベンダのID文字列を返す。12文字のASCII文字列がEBX, EDX, ECXの順序で格納される。基本機能の最大機能番号がEAXに格納される。
既知のCPUベンダのID文字列は以下のとおり:
例えば、ベンダIDが"GenuineIntel"の場合、EBXが0x756e6547、EDXが0x49656e69、ECXが0x6c65746eとなる。
.section .data
s0: .string "Largest Standard Function Number Supported: %i\n"
s1: .string "Vendor ID: %s\n"
.text
.global main
.type main, @function
main:
pushq %rbp
movq %rsp, %rbp
subl %eax, %eax
cpuid
subq $8, %rsp
movl %ebx, (%rsp)
movl %edx, 4(%rsp)
movl %ecx, 8(%rsp)
movl $s0, %edi
movl %eax, %esi
subl %eax, %eax
call printf
movq $s1, %rdi
movq %rsp, %rsi
subl %eax, %eax
call printf
subl %eax, %eax
movq %rbp, %rsp
popq %rbp
ret
これはCPUのステッピング、モデル、ファミリーをEAXに返す(これはCPUの「シグネチャ」とも呼ばれる)。また、機能フラグをEDXとECXに、追加の機能情報をEBXに返す。
EAXに格納される情報のフォーマットは以下のとおり:
インテルとAMDは、CPUのファミリーを上記の「ファミリー」と「拡張ファミリー」の合計で表示し、モデルを上記の「モデル」と4ビット左シフトした「拡張モデル」の合計で表示するように提案した。
プロセッサ情報と機能フラグはメーカ個別のものであるが、通常は互換性のためにインテルの値を他のメーカも使用している。
また、80386以上のプロセッサではリセット直後のDXレジスタにはこれらの情報(拡張ファミリ・拡張ステッピングは除く)に相当する値が格納されているため、ハード構成によっては80286がプロテクトモードからリアルモードに戻るためのリセット機構(通例、80386以降のシステムでも互換性のために残されている)を利用することで、386/486系プロセッサでもファミリ・モデル・ステッピングなどに相当する情報を得られる場合がある。詳細はIntel 80286およびIntel 80386を参照。
| Bit | EDX | ECX | Bit | |||
|---|---|---|---|---|---|---|
| Short | Feature | Short | Feature | |||
| 0 | fpu | オンチップ x87 FPU(浮動小数点ユニット) | sse3 | SSE3命令(Prescott New Instructions) | 0 | |
| 1 | vme | 仮想8086モード拡張 (VIF, VIP, PVIなど) | pclmulqdq | PCLMULQDQ命令 (carry-less multiply) |
1 | |
| 2 | de | デバッグ拡張 (Control register CR4 bit 3) | dtes64 | 64-bit debug store | 2 | |
| 3 | pse | ページサイズ拡張 (4 MByteページ) | monitor | MONITOR、MWAIT命令(Prescott New Instructions) |
3 | |
| 4 | tsc | タイムスタンプカウンタ(Time Stamp Counter)とRDTSC命令。 |
ds-cpl | CPL qualified debug store | 4 | |
| 5 | msr | モデル固有レジスタ(Model-specific registers)とRDMSR/WRMSR命令 |
vmx | Virtual Machine eXtensions | 5 | |
| 6 | pae | 物理アドレス拡張 | smx | Safer Mode Extensions (LaGrande) (GETSEC instruction) |
6 | |
| 7 | mce | マシンチェック例外(Machine Check Exception) | est | Enhanced SpeedStep | 7 | |
| 8 | cx8 | CMPXCHG8B命令 |
tm2 | Thermal Monitor 2 | 8 | |
| 9 | apic | オンチップAPIC(Advanced Programmable Interrupt Controller) | ssse3 | Supplemental SSE3命令 | 9 | |
| 10 | (reserved) | (reserved) | cnxt-id | L1 Context ID | 10 | |
| 11 | sep | SYSENTERおよびSYSEXIT命令 |
sdbg | Silicon Debug interface | 11 | |
| 12 | mtrr | メモリタイプ範囲レジスタ(Memory Type Range Registers) | fma | Fused multiply-add (FMA3) | 12 | |
| 13 | pge | ページ・グローバル・イネーブル(Page Global Enable)ビット Control register CR4 | cx16 | CMPXCHG16B命令 |
13 | |
| 14 | mca | マシン・チェック・アーキテクチャ(Machine check architecture) | xtpr | Can disable sending task priority messages | 14 | |
| 15 | cmov | 条件付き転送命令。CMOV, FCMOV, FCOMIなど |
pdcm | Perfmon & debug capability | 15 | |
| 16 | pat | ページ属性テーブル(Page Attribute Table) | (reserved) | 16 | ||
| 17 | pse-36 | 36ビットページサイズ拡張 | pcid | Process context identifiers (Control register CR4 bit 17) | 17 | |
| 18 | psn | プロセッサ・シリアル番号 | dca | Direct cache access for DMA writes | 18 | |
| 19 | clfsh | CLFLUSH命令 (SSE2) |
sse4.1 | SSE4.1命令 | 19 | |
| 20 | (nx) | No-execute (NX) bit (Itanium only) | sse4.2 | SSE4.2命令 | 20 | |
| 21 | ds | デバッグストア。 save trace of executed jumps | x2apic | x2APIC (enhanced APIC) | 21 | |
| 22 | acpi | Onboard thermal control MSRs for ACPI | movbe | MOVBE命令 |
22 | |
| 23 | mmx | MMX命令 | popcnt | POPCNT命令 |
23 | |
| 24 | fxsr | FXSAVE, FXRSTOR命令。 Control register CR4 bit 9 |
tsc-deadline | APIC implements one-shot operation using a TSC deadline value | 24 | |
| 25 | sse | SSE 命令 (Katmai New Instructions) |
aes-ni | AES命令 | 25 | |
| 26 | sse2 | SSE2命令 | xsave | Extensible processor state save/restore:XSAVE, XRSTOR, XSETBV, XGETBV instructions |
26 | |
| 27 | ss | セルフスヌープ(self-snoop) | osxsave | XSAVE enabled by OS |
27 | |
| 28 | htt | ハイパー・スレッディング・テクノロジ | avx | Advanced Vector Extensions (256-bit SIMD) | 28 | |
| 29 | tm | 温度モニタ(Thermal monitor) | f16c | Floating-point conversion instructions to/from FP16 format | 29 | |
| 30 | ia64 | IA64 processor emulating x86 | rdrnd | RDRAND (on-chip random number generator) feature |
30 | |
| 31 | pbe | Pending Break Enable (PBE# pin) wakeup capability | hypervisor | Hypervisor present (always zero on physical CPUs) | 31 | |
CPUID with a leaf index (EAX) greater than 0 may leave EBX and ECX unmodified, keeping their old values. For this reason, it is recommended to zero out EBX and ECX before executing CPUID with a leaf index of 1.AuthenticAMD Family 5 Model 0) processors only, EDX bit 9 used to indicate support for PGE instead. This was moved to bit 13 from K5 Model 1 onwards.GenuineIntel Family 6 Model 1) processors only, EDX bit 11 is invalid - the bit it set, but the SYSENTER and SYSEXIT instructions are not supported on the Pentium Pro.FCMOV and FCOMI instructions only available if onboard x87 FPU also present (indicated by EDX bit 0).これは、キャッシュとTLBの機能を示すディスクリプタのリストをEAX, EBX, ECX, EDXレジスタに格納する。
これは、プロセッサのシリアル番号を返す。プロセッサ・シリアル・ナンバは、インテルがPentium IIIで導入したが、プライバシーの懸念のためにこの後のモデルでは実装されていない(PSN機能ビットは常にクリアされている)。トランスメタのEfficeonとCrusoeプロセッサはこの機能を提供している。AMDは、この機能をどのCPUにも実装しなかった。
インテルPentium IIIでは、シリアル番号はEDX:ECXレジスタに格納される。トランスメタのEfficeonではEBX:EAXレジスタに、CrusoeではEBXレジスタだけに格納される。
プロセッサ・シリアル・ナンバ機能を使用するためには、BIOSの設定を有効にする必要があることに注意すべきである。
EBX, ECX, EDXレジスタに拡張機能フラグを返す。また、EAX=7での呼び出しに使用できるECXの最大値をEAXに返す。
| Bit | EBX | ECX | EDX | Bit | |||||
|---|---|---|---|---|---|---|---|---|---|
| Short | Feature | Short | Feature | Short | Feature | ||||
| 0 | fsgsbase | Access to base of FS and GS | prefetchwt1 | PREFETCHWT1 instruction |
(sgx-tem) | ? | 0 | ||
| 1 | tsc_adjust | IA32_TSC_ADJUST MSR | avx512-vbmi | AVX-512 Vector Bit Manipulation Instructions | sgx-keys | Attestation Services for Intel SGX | 1 | ||
| 2 | sgx | Software Guard Extensions | umip | User-mode Instruction Prevention | avx512-4vnniw | AVX-512 4-register Neural Network Instructions | 2 | ||
| 3 | bmi1 | Bit Manipulation Instruction Set 1 | pku | Memory Protection Keys for User-mode pages | avx512-4fmaps | AVX-512 4-register Multiply Accumulation Single precision | 3 | ||
| 4 | hle | TSX Hardware Lock Elision | ospke | PKU enabled by OS | fsrm | Fast Short REP MOVSB |
4 | ||
| 5 | avx2 | Advanced Vector Extensions 2 | waitpkg | Timed pause and user-level monitor/wait instructions (TPAUSE, UMONITOR, UMWAIT) |
uintr | User Inter-processor Interrupts | 5 | ||
| 6 | fdp-excptn-only | x87 FPU data pointer register updated on exceptions only | avx512-vbmi2 | AVX-512 Vector Bit Manipulation Instructions 2 | (reserved) | 6 | |||
| 7 | smep | Supervisor Mode Execution Prevention | cet_ss/shstk | Control flow enforcement (CET): shadow stack (SHSTK alternative name) | (reserved) | 7 | |||
| 8 | bmi2 | Bit Manipulation Instruction Set 2 | gfni | Galois Field instructions | avx512-vp2intersect | AVX-512 vector intersection instructions on 32/64-bit integers | 8 | ||
| 9 | erms | Enhanced REP MOVSB/STOSB |
vaes | Vector AES instruction set (VEX-256/EVEX) | srbds-ctrl | Special Register Buffer Data Sampling Mitigations | 9 | ||
| 10 | invpcid | INVPCID instruction |
vpclmulqdq | CLMUL instruction set (VEX-256/EVEX) | md-clear | VERW instruction clears CPU buffers |
10 | ||
| 11 | rtm | TSX Restricted Transactional Memory | avx512-vnni | AVX-512 Vector Neural Network Instructions | rtm-always-abort | All TSX transactions are aborted | 11 | ||
| 12 | rdt-m/pqm | Intel Resource Director (RDT) Monitoring or AMD Platform QOS Monitoring | avx512-bitalg | AVX-512 BITALG instructions | (reserved) | 12 | |||
| 13 | fcs_fds_deprecation | x87 FPU CS and DS deprecated | tme_en | Total Memory Encryption MSRs available | rtm-force-abort | TSX_FORCE_ABORT (MSR 0x10f) is available |
13 | ||
| 14 | mpx | Intel MPX (Memory Protection Extensions) | avx512-vpopcntdq | AVX-512 Vector Population Count Double and Quad-word | serialize | SERIALIZE instruction |
14 | ||
| 15 | rdt-a/pqe | Intel Resource Director (RDT) Allocation or AMD Platform QOS Enforcement | (fzm) | ? | hybrid | Mixture of CPU types in processor topology (e.g. Alder Lake) | 15 | ||
| 16 | avx512-f | AVX-512 Foundation | la57 | 5-level paging (57 address bits) | tsxldtrk | TSX load address tracking suspend/resume instructions (TSUSLDTRK and TRESLDTRK) |
16 | ||
| 17 | avx512-dq | AVX-512 Doubleword and Quadword Instructions | mawau | The value of userspace MPX Address-Width Adjust used by the BNDLDX and BNDSTX Intel MPX instructions in 64-bit mode |
(reserved) | 17 | |||
| 18 | rdseed | RDSEED instruction |
pconfig | Platform configuration (Memory Encryption Technologies Instructions) | 18 | ||||
| 19 | adx | Intel ADX (Multi-Precision Add-Carry Instruction Extensions) | lbr | Architectural Last Branch Records | 19 | ||||
| 20 | smap | Supervisor Mode Access Prevention | cet-ibt | Control flow enforcement (CET): indirect branch tracking | 20 | ||||
| 21 | avx512-ifma | AVX-512 Integer Fused Multiply-Add Instructions | (reserved) | 21 | |||||
| 22 | (pcommit) | (PCOMMIT instruction, deprecated) |
rdpid | RDPID (Read Processor ID) instruction and IA32_TSC_AUX MSR |
amx-bf16 | AMX(Advanced Matrix Extensions) tile computation on bfloat16 numbers | 22 | ||
| 23 | clflushopt | CLFLUSHOPT instruction |
kl | AES Key Locker | avx512-fp16 | AVX-512 half-precision floating-point arithmetic instructions | 23 | ||
| 24 | clwb | CLWB (Cache line writeback) instruction |
bus-lock-detect | Bus lock debug exceptions | amx-tile | AMX tile load/store instructions | 24 | ||
| 25 | pt | Intel Processor Trace | cldemote | CLDEMOTE (Cache line demote) instruction |
amx-int8 | AMX tile computation on 8-bit integers | 25 | ||
| 26 | avx512-pf | AVX-512 Prefetch Instructions | (mprr) | ? | ibrs / spec_ctrl | Speculation Control, part of Indirect Branch Control (IBC): Indirect Branch Restricted Speculation (IBRS) and Indirect Branch Prediction Barrier (IBPB) |
26 | ||
| 27 | avx512-er | AVX-512 Exponential and Reciprocal Instructions | movdiri | MOVDIRI instruction |
stibp | Single Thread Indirect Branch Predictor, part of IBC | 27 | ||
| 28 | avx512-cd | AVX-512 Conflict Detection Instructions | movdir64b | MOVDIR64B (64-byte direct store) instruction |
L1D_FLUSH | IA32_FLUSH_CMD MSR | 28 | ||
| 29 | sha | SHA-1 and SHA-256 extensions | enqcmd | Enqueue Stores and EMQCMD/EMQCMDS instructions |
IA32_ARCH_CAPABILITIES MSR (lists speculative side channel mitigations) | 29 | |||
| 30 | avx512-bw | AVX-512 Byte and Word Instructions | sgx-lc | SGX Launch Configuration | IA32_CORE_CAPABILITIES MSR (lists model-specific core capabilities) | 30 | |||
| 31 | avx512-vl | AVX-512 Vector Length Extensions | pks | Protection keys for supervisor-mode pages | ssbd | Speculative Store Bypass Disable, as mitigation for Speculative Store Bypass (IA32_SPEC_CTRL) | 31 | ||
最大の拡張機能番号をEAXに格納する。
AMD社のCPUの拡張機能フラグをEDXとECXに格納する。 EDXのビット 0 から 9, 12 から 17, 23と 24は、AMDのCPUではEAX=1の場合のCPUIDの結果と重複し、IntelのCPUでは未使用である。IntelのCPUでもsyscall, nx, pdpe1gb, rdtscp, lm, lahf_lm, abm/lzcnt, 3dnowprefetchに対応しているものもある。
| Bit | EDX | ECX | Bit | |||
|---|---|---|---|---|---|---|
| Short | Feature | Short | Feature | |||
| 0 | fpu | lahf_lm | LAHF/SAHF in long mode |
0 | ||
| 1 | vme | cmp_legacy | Hyperthreading not valid | 1 | ||
| 2 | de | svm | Secure Virtual Machine | 2 | ||
| 3 | pse | extapic | Extended APIC space | 3 | ||
| 4 | tsc | cr8_legacy | Control register CR8 in 32-bit mode | 4 | ||
| 5 | msr | abm/lzcnt | Advanced bit manipulation (LZCNT and POPCNT) |
5 | ||
| 6 | pae | sse4a | SSE4a | 6 | ||
| 7 | mce | misalignsse | Misaligned SSE mode | 7 | ||
| 8 | cx8 | 3dnowprefetch | PREFETCH and PREFETCHW instructions |
8 | ||
| 9 | apic | osvw | OS Visible Workaround | 9 | ||
| 10 | (syscall) | (SYSCALL/SYSRET, K6 only) |
ibs | Instruction Based Sampling | 10 | |
| 11 | syscall | SYSCALL and SYSRET instructions |
xop | XOP instruction set | 11 | |
| 12 | mtrr | skinit | SKINIT/STGI instructions |
12 | ||
| 13 | pge | wdt | Watchdog timer | 13 | ||
| 14 | mca | (reserved) | 14 | |||
| 15 | cmov | lwp | Light Weight Profiling | 15 | ||
| 16 | pat | fma4 | 4-operand fused multiply-add instructions | 16 | ||
| 17 | pse36 | tce | Translation Cache Extension | 17 | ||
| 18 | (reserved) | (reserved) | 18 | |||
| 19 | ecc | "Athlon MP" / "Sempron" CPU brand identification | nodeid_msr | NodeID MSR (C001_100C) |
19 | |
| 20 | nx | NX bit | (reserved) | 20 | ||
| 21 | (reserved) | tbm | Trailing Bit Manipulation | 21 | ||
| 22 | mmxext | Extended MMX | topoext | Topology Extensions | 22 | |
| 23 | mmx | perfctr_core | Core performance counter extensions | 23 | ||
| 24 | fxsr | perfctr_nb | Northbridge performance counter extensions | 24 | ||
| 25 | fxsr_opt | FXSAVE/FXRSTOR optimizations |
(StreamPerfMon) | Streaming performance monitor architecture | 25 | |
| 26 | pdpe1gb | Gigabyte pages | dbx | Data breakpoint extensions | 26 | |
| 27 | rdtscp | RDTSCP instruction |
perftsc | Performance timestamp counter (PTSC) | 27 | |
| 28 | (reserved) | pcx_l2i | L2I perf counter extensions | 28 | ||
| 29 | lm | Long Mode | monitorx | MONITORX and MWAITX instructions |
29 | |
| 30 | 3dnowext | Extended 3DNow! | addr_mask_ext | Address mask extension to 32 bits for instruction breakpoints | 30 | |
| 31 | 3dnow | 3DNow! | (reserved) | 31 | ||
プロセッサブランド文字列をEAX, EBX, ECX, EDXに格納する。全体で48バイトのNULL終端ASCII文字列のプロセッサブランド文字列を得るために、各パラメータを順番に設定しCPUIDを呼び出す必要がある。
この機能は使用されていない。
ECXにL2キャッシュの詳細情報を格納する。2種類の方法で表したキャッシュサイズと、キャッシュとメモリの対応を示すコードを含む。
この機能は使用されていない。
最大の仮想アドレスサイズと物理アドレスサイズをEAXに格納する。