PatchworkOS
Loading...
Searching...
No Matches

CPU feature detection. More...

Data Structures

struct  cpuid_output_t
 Output structure for CPUID instruction. More...
 
struct  cpuid_feature_info_t
 CPU feature information structure. More...
 
struct  cpuid_extended_feature_info_t
 CPU extended feature information structure. More...
 

Enumerations

enum  cpuid_input_eax_t {
  CPUID_EAX_NONE = 0x00 ,
  CPUID_EAX_FEATURE_INFO = 0x01 ,
  CPUID_EAX_EXTENDED_FEATURE_INFO = 0x07
}
 Input EAX values. More...
 
enum  cpuid_input_ecx_t { CPUID_ECX_NONE = 0x00 }
 Input ECX values. More...
 
enum  cpuid_ecx_features_t {
  CPUID_ECX_SSE3 = 1 << 0 ,
  CPUID_ECX_PCLMULQDQ = 1 << 1 ,
  CPUID_ECX_DTES64 = 1 << 2 ,
  CPUID_ECX_MONITOR = 1 << 3 ,
  CPUID_ECX_DS_CPL = 1 << 4 ,
  CPUID_ECX_VMX = 1 << 5 ,
  CPUID_ECX_SMX = 1 << 6 ,
  CPUID_ECX_EIST = 1 << 7 ,
  CPUID_ECX_TM2 = 1 << 8 ,
  CPUID_ECX_SSSE3 = 1 << 9 ,
  CPUID_ECX_CNXT_ID = 1 << 10 ,
  CPUID_ECX_SDBG = 1 << 11 ,
  CPUID_ECX_FMA = 1 << 12 ,
  CPUID_ECX_CMPXCHG16B = 1 << 13 ,
  CPUID_ECX_XTPR_UPDATE_CONTROL = 1 << 14 ,
  CPUID_ECX_PDCM = 1 << 15 ,
  CPUID_ECX_PCID = 1 << 17 ,
  CPUID_ECX_DCA = 1 << 18 ,
  CPUID_ECX_SSE4_1 = 1 << 19 ,
  CPUID_ECX_SSE4_2 = 1 << 20 ,
  CPUID_ECX_X2APIC = 1 << 21 ,
  CPUID_ECX_MOVBE = 1 << 22 ,
  CPUID_ECX_POPCNT = 1 << 23 ,
  CPUID_ECX_TSC_DEADLINE = 1 << 24 ,
  CPUID_ECX_AESNI = 1 << 25 ,
  CPUID_ECX_XSAVE = 1 << 26 ,
  CPUID_ECX_OSXSAVE = 1 << 27 ,
  CPUID_ECX_AVX = 1 << 28 ,
  CPUID_ECX_F16C = 1 << 29 ,
  CPUID_ECX_RDRAND = 1 << 30
}
 ECX feature flags. More...
 
enum  cpuid_edx_features_t {
  CPUID_EDX_FPU = 1 << 0 ,
  CPUID_EDX_VME = 1 << 1 ,
  CPUID_EDX_DE = 1 << 2 ,
  CPUID_EDX_PSE = 1 << 3 ,
  CPUID_EDX_TSC = 1 << 4 ,
  CPUID_EDX_MSR = 1 << 5 ,
  CPUID_EDX_PAE = 1 << 6 ,
  CPUID_EDX_MCE = 1 << 7 ,
  CPUID_EDX_CX8 = 1 << 8 ,
  CPUID_EDX_APIC = 1 << 9 ,
  CPUID_EDX_SEP = 1 << 11 ,
  CPUID_EDX_MTRR = 1 << 12 ,
  CPUID_EDX_PGE = 1 << 13 ,
  CPUID_EDX_MCA = 1 << 14 ,
  CPUID_EDX_CMOV = 1 << 15 ,
  CPUID_EDX_PAT = 1 << 16 ,
  CPUID_EDX_PSE36 = 1 << 17 ,
  CPUID_EDX_PSN = 1 << 18 ,
  CPUID_EDX_CLFSH = 1 << 19 ,
  CPUID_EDX_RESERVED1 = 1 << 20 ,
  CPUID_EDX_DS = 1 << 21 ,
  CPUID_EDX_ACPI = 1 << 22 ,
  CPUID_EDX_MMX = 1 << 23 ,
  CPUID_EDX_FXSR = 1 << 24 ,
  CPUID_EDX_SSE = 1 << 25 ,
  CPUID_EDX_SSE2 = 1 << 26 ,
  CPUID_EDX_SS = 1 << 27 ,
  CPUID_EDX_HTT = 1 << 28 ,
  CPUID_EDX_TM = 1 << 29 ,
  CPUID_EDX_RESERVED2 = 1 << 30 ,
  CPUID_EDX_PBE = 1 << 31
}
 
enum  cpuid_ebx_features_t {
  CPUID_EBX_FSGSBASE = 1 << 0 ,
  CPUID_EBX_TSC_ADJUST = 1 << 1 ,
  CPUID_EBX_SGX = 1 << 2 ,
  CPUID_EBX_BMI1 = 1 << 3 ,
  CPUID_EBX_HLE = 1 << 4 ,
  CPUID_EBX_AVX2 = 1 << 5 ,
  CPUID_EBX_FDP_EXCPTN_ONLY = 1 << 6 ,
  CPUID_EBX_SMEP = 1 << 7 ,
  CPUID_EBX_BMI2 = 1 << 8 ,
  CPUID_EBX_ERMS = 1 << 9 ,
  CPUID_EBX_INVPCID = 1 << 10 ,
  CPUID_EBX_RTM = 1 << 11 ,
  CPUID_EBX_RDT_M = 1 << 12 ,
  CPUID_EBX_FPU_CS_DS_DEPR = 1 << 13 ,
  CPUID_EBX_MPX = 1 << 14 ,
  CPUID_EBX_RDT_A = 1 << 15 ,
  CPUID_EBX_AVX512F = 1 << 16 ,
  CPUID_EBX_AVX512DQ = 1 << 17 ,
  CPUID_EBX_RDSEED = 1 << 18 ,
  CPUID_EBX_ADX = 1 << 19 ,
  CPUID_EBX_SMAP = 1 << 20 ,
  CPUID_EBX_AVX512_IFMA = 1 << 21 ,
  CPUID_EBX_RESERVED1 = 1 << 22 ,
  CPUID_EBX_CLFLUSHOPT = 1 << 23 ,
  CPUID_EBX_CLWB = 1 << 24 ,
  CPUID_EBX_INTEL_PT = 1 << 25 ,
  CPUID_EBX_AVX512PF = 1 << 26 ,
  CPUID_EBX_AVX512ER = 1 << 27 ,
  CPUID_EBX_AVX512CD = 1 << 28 ,
  CPUID_EBX_SHA = 1 << 29 ,
  CPUID_EBX_AVX512BW = 1 << 30 ,
  CPUID_EBX_AVX512VL = 1 << 31
}
 EBX feature flags. More...
 

Functions

static void cpuid (cpuid_input_eax_t eax, cpuid_input_ecx_t ecx, cpuid_output_t *out)
 CPUID instruction.
 
static void cpuid_feature_info (cpuid_feature_info_t *info)
 Wrapper to get CPU feature information.
 
static void cpuid_extended_feature_info (cpuid_extended_feature_info_t *info)
 Wrapper to get CPU extended feature information.
 

Detailed Description

CPU feature detection.

The sys/cpuid.h header provides functions for detecting CPU features using the CPUID instruction.

See also
CPUID Instruction

Enumeration Type Documentation

◆ cpuid_ebx_features_t

EBX feature flags.

These flags are returned in the EBX register after calling the CPUID instruction with EAX=CPUID_FEATURE_EXTENDED_ID.

These flags are returned in the EBX register after calling the CPUID instruction with EAX=CPUID_EAX_EXTENDED_FEATURE_INFO and ECX=0.

Enumerator
CPUID_EBX_FSGSBASE 
CPUID_EBX_TSC_ADJUST 
CPUID_EBX_SGX 
CPUID_EBX_BMI1 
CPUID_EBX_HLE 
CPUID_EBX_AVX2 
CPUID_EBX_FDP_EXCPTN_ONLY 
CPUID_EBX_SMEP 
CPUID_EBX_BMI2 
CPUID_EBX_ERMS 
CPUID_EBX_INVPCID 
CPUID_EBX_RTM 
CPUID_EBX_RDT_M 
CPUID_EBX_FPU_CS_DS_DEPR 
CPUID_EBX_MPX 
CPUID_EBX_RDT_A 
CPUID_EBX_AVX512F 
CPUID_EBX_AVX512DQ 
CPUID_EBX_RDSEED 
CPUID_EBX_ADX 
CPUID_EBX_SMAP 
CPUID_EBX_AVX512_IFMA 
CPUID_EBX_RESERVED1 
CPUID_EBX_CLFLUSHOPT 
CPUID_EBX_CLWB 
CPUID_EBX_INTEL_PT 
CPUID_EBX_AVX512PF 
CPUID_EBX_AVX512ER 
CPUID_EBX_AVX512CD 
CPUID_EBX_SHA 
CPUID_EBX_AVX512BW 
CPUID_EBX_AVX512VL 

Definition at line 127 of file cpuid.h.

◆ cpuid_ecx_features_t

ECX feature flags.

These flags are returned in the ECX register after calling the CPUID instruction with EAX=CPUID_EAX_FEATURE_INFO.

Enumerator
CPUID_ECX_SSE3 
CPUID_ECX_PCLMULQDQ 
CPUID_ECX_DTES64 
CPUID_ECX_MONITOR 
CPUID_ECX_DS_CPL 
CPUID_ECX_VMX 
CPUID_ECX_SMX 
CPUID_ECX_EIST 
CPUID_ECX_TM2 
CPUID_ECX_SSSE3 
CPUID_ECX_CNXT_ID 
CPUID_ECX_SDBG 
CPUID_ECX_FMA 
CPUID_ECX_CMPXCHG16B 
CPUID_ECX_XTPR_UPDATE_CONTROL 
CPUID_ECX_PDCM 
CPUID_ECX_PCID 
CPUID_ECX_DCA 
CPUID_ECX_SSE4_1 
CPUID_ECX_SSE4_2 
CPUID_ECX_X2APIC 
CPUID_ECX_MOVBE 
CPUID_ECX_POPCNT 
CPUID_ECX_TSC_DEADLINE 
CPUID_ECX_AESNI 
CPUID_ECX_XSAVE 
CPUID_ECX_OSXSAVE 
CPUID_ECX_AVX 
CPUID_ECX_F16C 
CPUID_ECX_RDRAND 

Definition at line 45 of file cpuid.h.

◆ cpuid_edx_features_t

Enumerator
CPUID_EDX_FPU 
CPUID_EDX_VME 
CPUID_EDX_DE 
CPUID_EDX_PSE 
CPUID_EDX_TSC 
CPUID_EDX_MSR 
CPUID_EDX_PAE 
CPUID_EDX_MCE 
CPUID_EDX_CX8 
CPUID_EDX_APIC 
CPUID_EDX_SEP 
CPUID_EDX_MTRR 
CPUID_EDX_PGE 
CPUID_EDX_MCA 
CPUID_EDX_CMOV 
CPUID_EDX_PAT 
CPUID_EDX_PSE36 
CPUID_EDX_PSN 
CPUID_EDX_CLFSH 
CPUID_EDX_RESERVED1 
CPUID_EDX_DS 
CPUID_EDX_ACPI 
CPUID_EDX_MMX 
CPUID_EDX_FXSR 
CPUID_EDX_SSE 
CPUID_EDX_SSE2 
CPUID_EDX_SS 
CPUID_EDX_HTT 
CPUID_EDX_TM 
CPUID_EDX_RESERVED2 
CPUID_EDX_PBE 

Definition at line 85 of file cpuid.h.

◆ cpuid_input_eax_t

Input EAX values.

Enumerator
CPUID_EAX_NONE 
CPUID_EAX_FEATURE_INFO 
CPUID_EAX_EXTENDED_FEATURE_INFO 

Definition at line 23 of file cpuid.h.

◆ cpuid_input_ecx_t

Input ECX values.

Enumerator
CPUID_ECX_NONE 

Definition at line 34 of file cpuid.h.

Function Documentation

◆ cpuid()

static void cpuid ( cpuid_input_eax_t  eax,
cpuid_input_ecx_t  ecx,
cpuid_output_t out 
)
inlinestatic

CPUID instruction.

Parameters
eaxInput EAX value.
ecxInput ECX value.
outOutput structure.

Definition at line 182 of file cpuid.h.

References cpuid_output_t::eax, cpuid_output_t::ebx, cpuid_output_t::ecx, and cpuid_output_t::edx.

Referenced by cpuid_extended_feature_info(), and cpuid_feature_info().

◆ cpuid_extended_feature_info()

static void cpuid_extended_feature_info ( cpuid_extended_feature_info_t info)
inlinestatic

Wrapper to get CPU extended feature information.

Parameters
infoOutput pointer.

Definition at line 228 of file cpuid.h.

References cpuid(), CPUID_EAX_EXTENDED_FEATURE_INFO, CPUID_ECX_NONE, cpuid_output_t::ebx, and info.

Referenced by simd_cpu_init(), and simd_xsave_init().

◆ cpuid_feature_info()

static void cpuid_feature_info ( cpuid_feature_info_t info)
inlinestatic

Wrapper to get CPU feature information.

Parameters
infoOutput pointer.

Definition at line 204 of file cpuid.h.

References cpuid(), CPUID_EAX_FEATURE_INFO, CPUID_ECX_NONE, cpuid_output_t::eax, cpuid_output_t::ebx, cpuid_output_t::ecx, cpuid_output_t::edx, and info.

Referenced by rand_cpu_init(), simd_cpu_init(), simd_ctx_load(), simd_ctx_save(), and simd_xsave_init().