CPUIDは、x86の機械語命令の一つ(およびそのアセンブリ・ニーモニック)である。CPUの識別 (IDentification) の意。486の後期のステッピングで導入され、Pentiumで完全に公開された。

CPUIDを使用することで、ソフトウェアはプロセッサの形式と機能(例えば、MMXやSSEなどの拡張のサポートの有無)を識別することができる。機械語オペコードはであり、オペランドとしてEAXレジスタの値でどのような情報を取得するかを指定する。

CPUID命令の使用可否 CPUID命令は一部の80486およびそれ以降のプロセッサで利用できるため、場合によってはCPUID命令が存在するプロセッサであるか否かを事前に判別する必要が生じる。80486以前のプロセッサを識別する必要がある場合には、それぞれの振舞の微妙な違いを利用する難解なテクニックを駆使する必要があった(たとえばPUSH SPの結果として、PUSHによる変化前と変化後の、どちらの値がプッシュされるか、等)。

80486以上のプロセッサであることが確認できた場合、CPUID命令の存在を確認するためのフラグとして32ビットフラグレジスタ (EFLAGS) の第21ビットが新たに設けられているため、このビットが「変更可能」であればCPUID命令が使用可能であると判断できる。なおEFLAGSは80386以上のプロセッサであればアクセスできるため、80286以下のプロセッサを判別・除外しておく必要はあるものの、CPUID命令の有無だけを調べたいのであれば実質的に80386以上であることが確認できればこのフラグを調べることができる。

CPUID命令の呼び出し CPUID命令は、EAXレジスタが暗黙のオペランドであり、それ以外の(明示的な)オペランドは無い。どのような情報を返すべきかを指定する値をEAXレジスタに設定し、CPUID命令を実行する。まずEAX = 0でCPUIDを呼び出し、CPUでサポートされている最大のパラメータを取得するべきである。CPUIDの拡張機能情報を取得する場合は、EAXのビット31をセットしてCPUIDを呼び出す。拡張機能情報でサポートされている最大の機能番号を得るためには、EAX = 80000000hでCPUIDを呼び出す。

EAX=0: ベンダIDの取得 これは、CPUベンダのID文字列を返す。12文字のASCII文字列がEBX, EDX, ECXの順序で格納される。基本機能の最大機能番号がEAXに格納される。

既知のCPUベンダのID文字列は以下のとおり: - AMD K5の初期のエンジニアリングサンプル - AMD - セントールテクノロジー - サイリックス - インテル , - トランスメタ - ナショナル セミコンダクター - NexGen - Rise Technology - SiS - UMC - VIA Technologies

例えば、ベンダ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

EAX=1: プロセッサ情報とプロセッサの機能 これはCPUのステッピング、モデル、ファミリーをEAXに返す(これはCPUの「シグネチャ」とも呼ばれる)。また、機能フラグをEDXとECXに、追加の機能情報をEBXに返す。

EAXに格納される情報のフォーマットは以下のとおり: 3:0 - ステッピング 7:4 - モデル 11:8 - ファミリー 13:12 - プロセッサタイプ 19:16 - 拡張モデル 27:20 - 拡張ファミリー インテルとAMDは、CPUのファミリーを上記の「ファミリー」と「拡張ファミリー」の合計で表示し、モデルを上記の「モデル」と4ビット左シフトした「拡張モデル」の合計で表示するように提案した。

プロセッサ情報と機能フラグはメーカ個別のものであるが、通常は互換性のためにインテルの値を他のメーカも使用している。

また、80386以上のプロセッサではリセット直後のDXレジスタにはこれらの情報(拡張ファミリ・拡張ステッピングは除く)に相当する値が格納されているため、ハード構成によっては80286がプロテクトモードからリアルモードに戻るためのリセット機構(通例、80386以降のシステムでも互換性のために残されている)を利用することで、386/486系プロセッサでもファミリ・モデル・ステッピングなどに相当する情報を得られる場合がある。詳細はIntel 80286およびIntel 80386を参照。

+ CPUID EAX=1: EDXとECXで取得できる機能フラグ 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)Intel, Itanium Architecture Software Developer's Manual, rev 2.3, volume 4: IA-32 Instruction Set, may 2010, document number: 323208, table 2-5, page 4:81, see bits 20 and 30. Archived on Feb 15, 2012. 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

EAX=2: キャッシュとTLBディスクリプタ情報 これは、キャッシュとTLBの機能を示すディスクリプタのリストをEAX, EBX, ECX, EDXレジスタに格納する。

EAX=3: プロセッサ・シリアル・ナンバ これは、プロセッサのシリアル番号を返す。プロセッサ・シリアル・ナンバは、インテルがPentium IIIで導入したが、プライバシーの懸念のためにこの後のモデルでは実装されていない(PSN機能ビットは常にクリアされている)。トランスメタのEfficeonとCrusoeプロセッサはこの機能を提供している。AMDは、この機能をどのCPUにも実装しなかった。

インテルPentium IIIでは、シリアル番号はEDX:ECXレジスタに格納される。トランスメタのEfficeonではEBX:EAXレジスタに、CrusoeではEBXレジスタだけに格納される。

プロセッサ・シリアル・ナンバ機能を使用するためには、BIOSの設定を有効にする必要があることに注意すべきである。

EAX=7, ECX=0: 拡張機能 EBX, ECX, EDXレジスタに拡張機能フラグを返す。また、EAX=7での呼び出しに使用できるECXの最大値をEAXに返す。

+ CPUID EAX=7,ECX=0: Extended feature bits in EBX, ECX and EDX 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 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 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)Intel, Deprecating the PCOMMIT instruction, sep 12, 2016. Archived on Apr 23, 2023. 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 instructionsIntel, AVX512-FP16 Architecture Specification (PDF), document number 347407-001, June 2021. Archived on Oct 26, 2022 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) andIndirect 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=80000000h: サポートする最大拡張機能番号の取得 最大の拡張機能番号をEAXに格納する。

EAX=80000001h: 拡張プロセッサ情報とプロセッサの機能 AMD社のCPUの拡張機能フラグをEDXとECXに格納するLinux kernel source code。 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に対応しているものもある。