mirror of
https://github.com/NixOS/nix
synced 2025-06-27 00:11:17 +02:00
Use feature_level field from libcpuid (#12674)
Close #11375 Co-authored-by: John Ericson <git@JohnEricson.me>
This commit is contained in:
parent
c97f779dbb
commit
83ec81789a
2 changed files with 14 additions and 53 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#if HAVE_LIBCPUID
|
#if HAVE_LIBCPUID
|
||||||
#include <libcpuid/libcpuid.h>
|
#include <libcpuid/libcpuid.h>
|
||||||
|
#include <map>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
@ -10,61 +11,21 @@ namespace nix {
|
||||||
|
|
||||||
StringSet computeLevels() {
|
StringSet computeLevels() {
|
||||||
StringSet levels;
|
StringSet levels;
|
||||||
|
struct cpu_id_t data;
|
||||||
|
|
||||||
if (!cpuid_present())
|
const std::map<cpu_feature_level_t, std::string> feature_strings = {
|
||||||
|
{ FEATURE_LEVEL_X86_64_V1, "x86_64-v1" },
|
||||||
|
{ FEATURE_LEVEL_X86_64_V2, "x86_64-v2" },
|
||||||
|
{ FEATURE_LEVEL_X86_64_V3, "x86_64-v3" },
|
||||||
|
{ FEATURE_LEVEL_X86_64_V4, "x86_64-v4" },
|
||||||
|
};
|
||||||
|
|
||||||
|
if (cpu_identify(NULL, &data) < 0)
|
||||||
return levels;
|
return levels;
|
||||||
|
|
||||||
cpu_raw_data_t raw;
|
for (auto & [level, levelString] : feature_strings)
|
||||||
cpu_id_t data;
|
if (data.feature_level >= level)
|
||||||
|
levels.insert(levelString);
|
||||||
if (cpuid_get_raw_data(&raw) < 0)
|
|
||||||
return levels;
|
|
||||||
|
|
||||||
if (cpu_identify(&raw, &data) < 0)
|
|
||||||
return levels;
|
|
||||||
|
|
||||||
if (!(data.flags[CPU_FEATURE_CMOV] &&
|
|
||||||
data.flags[CPU_FEATURE_CX8] &&
|
|
||||||
data.flags[CPU_FEATURE_FPU] &&
|
|
||||||
data.flags[CPU_FEATURE_FXSR] &&
|
|
||||||
data.flags[CPU_FEATURE_MMX] &&
|
|
||||||
data.flags[CPU_FEATURE_SSE] &&
|
|
||||||
data.flags[CPU_FEATURE_SSE2]))
|
|
||||||
return levels;
|
|
||||||
|
|
||||||
levels.insert("x86_64-v1");
|
|
||||||
|
|
||||||
if (!(data.flags[CPU_FEATURE_CX16] &&
|
|
||||||
data.flags[CPU_FEATURE_LAHF_LM] &&
|
|
||||||
data.flags[CPU_FEATURE_POPCNT] &&
|
|
||||||
// SSE3
|
|
||||||
data.flags[CPU_FEATURE_PNI] &&
|
|
||||||
data.flags[CPU_FEATURE_SSSE3] &&
|
|
||||||
data.flags[CPU_FEATURE_SSE4_1] &&
|
|
||||||
data.flags[CPU_FEATURE_SSE4_2]))
|
|
||||||
return levels;
|
|
||||||
|
|
||||||
levels.insert("x86_64-v2");
|
|
||||||
|
|
||||||
if (!(data.flags[CPU_FEATURE_AVX] &&
|
|
||||||
data.flags[CPU_FEATURE_AVX2] &&
|
|
||||||
data.flags[CPU_FEATURE_F16C] &&
|
|
||||||
data.flags[CPU_FEATURE_FMA3] &&
|
|
||||||
// LZCNT
|
|
||||||
data.flags[CPU_FEATURE_ABM] &&
|
|
||||||
data.flags[CPU_FEATURE_MOVBE]))
|
|
||||||
return levels;
|
|
||||||
|
|
||||||
levels.insert("x86_64-v3");
|
|
||||||
|
|
||||||
if (!(data.flags[CPU_FEATURE_AVX512F] &&
|
|
||||||
data.flags[CPU_FEATURE_AVX512BW] &&
|
|
||||||
data.flags[CPU_FEATURE_AVX512CD] &&
|
|
||||||
data.flags[CPU_FEATURE_AVX512DQ] &&
|
|
||||||
data.flags[CPU_FEATURE_AVX512VL]))
|
|
||||||
return levels;
|
|
||||||
|
|
||||||
levels.insert("x86_64-v4");
|
|
||||||
|
|
||||||
return levels;
|
return levels;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ cpuid_required = get_option('cpuid')
|
||||||
if host_machine.cpu_family() != 'x86_64' and cpuid_required.enabled()
|
if host_machine.cpu_family() != 'x86_64' and cpuid_required.enabled()
|
||||||
warning('Force-enabling seccomp on non-x86_64 does not make sense')
|
warning('Force-enabling seccomp on non-x86_64 does not make sense')
|
||||||
endif
|
endif
|
||||||
cpuid = dependency('libcpuid', 'cpuid', required : cpuid_required)
|
cpuid = dependency('libcpuid', 'cpuid', version : '>= 0.7.0', required : cpuid_required)
|
||||||
configdata.set('HAVE_LIBCPUID', cpuid.found().to_int())
|
configdata.set('HAVE_LIBCPUID', cpuid.found().to_int())
|
||||||
deps_private += cpuid
|
deps_private += cpuid
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue