diff --git a/libcpuid/CMakeLists.txt b/libcpuid/CMakeLists.txt index 67efebe..1a10ccc 100644 --- a/libcpuid/CMakeLists.txt +++ b/libcpuid/CMakeLists.txt @@ -20,6 +20,12 @@ if("${MSVC_CXX_ARCHITECTURE_ID}" MATCHES "x64") list(APPEND cpuid_sources masm-x64.asm) endif() +option(SUPPORT_DEPRECATED "Build support of deprecated attributes" ON) +if(NOT SUPPORT_DEPRECATED) + message(AUTHOR_WARNING "Deprecated attributes will not be available, the library will be not backward compatible") + add_compile_definitions(LIBCPUID_DISABLE_DEPRECATED) +endif(NOT SUPPORT_DEPRECATED) + add_library(cpuid ${cpuid_sources}) set_property(TARGET cpuid PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON) target_include_directories(cpuid SYSTEM PUBLIC $) diff --git a/libcpuid/cpuid_main.c b/libcpuid/cpuid_main.c index 0b47460d..09d1618 100644 --- a/libcpuid/cpuid_main.c +++ b/libcpuid/cpuid_main.c @@ -80,8 +80,8 @@ static void cpu_id_t_constructor(struct cpu_id_t* id) id->feature_level = FEATURE_LEVEL_UNKNOWN; id->vendor = VENDOR_UNKNOWN; id->l1_data_cache = id->l1_instruction_cache = id->l2_cache = id->l3_cache = id->l4_cache = -1; - id->l1_assoc = id->l1_data_assoc = id->l1_instruction_assoc = id->l2_assoc = id->l3_assoc = id->l4_assoc = -1; - id->l1_cacheline = id->l1_data_cacheline = id->l1_instruction_cacheline = id->l2_cacheline = id->l3_cacheline = id->l4_cacheline = -1; + id->l1_data_assoc = id->l1_instruction_assoc = id->l2_assoc = id->l3_assoc = id->l4_assoc = -1; + id->l1_data_cacheline = id->l1_instruction_cacheline = id->l2_cacheline = id->l3_cacheline = id->l4_cacheline = -1; id->l1_data_instances = id->l1_instruction_instances = id->l2_instances = id->l3_instances = id->l4_instances = -1; id->x86.sse_size = -1; init_affinity_mask(&id->affinity_mask); @@ -1376,8 +1376,11 @@ int cpu_ident_internal(struct cpu_raw_data_t* raw, struct cpu_id_t* data, struct r = cpuid_identify_arm(raw, data); break; default: - return cpuid_set_error(ERR_CPU_UNKN); + r = ERR_CPU_UNKN; + break; } + +#ifndef LIBCPUID_DISABLE_DEPRECATED /* Backward compatibility */ /* - Deprecated since v0.5.0 */ data->l1_assoc = data->l1_data_assoc; @@ -1390,6 +1393,7 @@ int cpu_ident_internal(struct cpu_raw_data_t* raw, struct cpu_id_t* data, struct data->ext_model = data->x86.ext_model; data->sse_size = data->x86.sse_size; data->sgx = data->x86.sgx; +#endif /* LIBCPUID_DISABLE_DEPRECATED */ return cpuid_set_error(r); } diff --git a/libcpuid/libcpuid.h b/libcpuid/libcpuid.h index 5231624..816f5b1 100644 --- a/libcpuid/libcpuid.h +++ b/libcpuid/libcpuid.h @@ -523,6 +523,7 @@ struct cpu_id_t { */ uint8_t flags[CPU_FLAGS_MAX]; +#ifndef LIBCPUID_DISABLE_DEPRECATED /** * CPU family (BaseFamily[3:0]) * @deprecated replaced by \ref x86_id_t::family (prefix member with `x86.`, e.g. `id.x86.family`) @@ -558,6 +559,7 @@ struct cpu_id_t { */ LIBCPUID_DEPRECATED("replace with '.x86.ext_model' in your code to fix the warning") int32_t ext_model; +#endif /* LIBCPUID_DISABLE_DEPRECATED */ /** * contains architecture specific info. @@ -620,11 +622,13 @@ struct cpu_id_t { /** L4 cache size in KB. Zero on most systems */ int32_t l4_cache; +#ifndef LIBCPUID_DISABLE_DEPRECATED /** Cache associativity for the L1 data cache. -1 if undetermined * @deprecated replaced by \ref cpu_id_t::l1_data_assoc */ LIBCPUID_DEPRECATED("replace with 'l1_data_assoc' in your code to fix the warning") int32_t l1_assoc; +#endif /* LIBCPUID_DISABLE_DEPRECATED */ /** Cache associativity for the L1 data cache. -1 if undetermined */ int32_t l1_data_assoc; @@ -641,11 +645,13 @@ struct cpu_id_t { /** Cache associativity for the L4 cache. -1 if undetermined */ int32_t l4_assoc; +#ifndef LIBCPUID_DISABLE_DEPRECATED /** Cache-line size for L1 data cache. -1 if undetermined * @deprecated replaced by \ref cpu_id_t::l1_data_cacheline */ LIBCPUID_DEPRECATED("replace with 'l1_data_cacheline' in your code to fix the warning") int32_t l1_cacheline; +#endif /* LIBCPUID_DISABLE_DEPRECATED */ /** Cache-line size for L1 data cache. -1 if undetermined */ int32_t l1_data_cacheline; diff --git a/libcpuid/rdmsr.c b/libcpuid/rdmsr.c index 125a791..67d030d 100644 --- a/libcpuid/rdmsr.c +++ b/libcpuid/rdmsr.c @@ -734,13 +734,13 @@ static int msr_platform_info_supported(struct msr_info_t *info) if(info->id->vendor == VENDOR_INTEL) { for(i = 0; i < COUNT_OF(msr_platform_info); i++) { - if((info->id->ext_family == msr_platform_info[i].ext_family) && (info->id->ext_model == msr_platform_info[i].ext_model)) { - debugf(2, "Intel CPU with CPUID signature %02X_%02XH supports MSR_PLATFORM_INFO.\n", info->id->ext_family, info->id->ext_model); + if((info->id->x86.ext_family == msr_platform_info[i].ext_family) && (info->id->x86.ext_model == msr_platform_info[i].ext_model)) { + debugf(2, "Intel CPU with CPUID signature %02X_%02XH supports MSR_PLATFORM_INFO.\n", info->id->x86.ext_family, info->id->x86.ext_model); supported = 1; return supported; } } - debugf(2, "Intel CPU with CPUID signature %02X_%02XH does not support MSR_PLATFORM_INFO.\n", info->id->ext_family, info->id->ext_model); + debugf(2, "Intel CPU with CPUID signature %02X_%02XH does not support MSR_PLATFORM_INFO.\n", info->id->x86.ext_family, info->id->x86.ext_model); } supported = 0; @@ -830,13 +830,13 @@ static int msr_perf_status_supported(struct msr_info_t *info) if(info->id->vendor == VENDOR_INTEL) { for(i = 0; i < COUNT_OF(msr_perf_status); i++) { - if((info->id->ext_family == msr_perf_status[i].ext_family) && (info->id->ext_model == msr_perf_status[i].ext_model)) { - debugf(2, "Intel CPU with CPUID signature %02X_%02XH supports MSR_PERF_STATUS.\n", info->id->ext_family, info->id->ext_model); + if((info->id->x86.ext_family == msr_perf_status[i].ext_family) && (info->id->x86.ext_model == msr_perf_status[i].ext_model)) { + debugf(2, "Intel CPU with CPUID signature %02X_%02XH supports MSR_PERF_STATUS.\n", info->id->x86.ext_family, info->id->x86.ext_model); supported = 1; return supported; } } - debugf(2, "Intel CPU with CPUID signature %02X_%02XH does not support MSR_PERF_STATUS.\n", info->id->ext_family, info->id->ext_model); + debugf(2, "Intel CPU with CPUID signature %02X_%02XH does not support MSR_PERF_STATUS.\n", info->id->x86.ext_family, info->id->x86.ext_model); } supported = 0;