From 916851bd4ae9fffbab6ee89932f5fe3ef940600b Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 9 Nov 2017 20:33:18 +0300 Subject: [PATCH] Optimize cpuid --- Utilities/sysinfo.cpp | 21 ++++++++++++++++++++- Utilities/sysinfo.h | 16 +++------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Utilities/sysinfo.cpp b/Utilities/sysinfo.cpp index c91de4ab35..204cc405bc 100644 --- a/Utilities/sysinfo.cpp +++ b/Utilities/sysinfo.cpp @@ -7,6 +7,25 @@ #include #endif +bool utils::has_ssse3() +{ + static const bool g_value = get_cpuid(0, 0)[0] >= 0x1 && get_cpuid(1, 0)[2] & 0x200; + return g_value; +} + +bool utils::has_avx() +{ + static const bool g_value = get_cpuid(0, 0)[0] >= 0x1 && get_cpuid(1, 0)[2] & 0x10000000; + return g_value; +} + +bool utils::has_rtm() +{ + // Check RTM and MPX extensions in order to filter out TSX on Haswell CPUs + static const bool g_value = get_cpuid(0, 0)[0] >= 0x7 && (get_cpuid(7, 0)[1] & 0x4800) == 0x4800; + return g_value; +} + std::string utils::get_system_info() { std::string result; @@ -49,7 +68,7 @@ std::string utils::get_system_info() if (has_avx()) { - result += " | AVX"; + result += " | AVX+"; } if (has_rtm()) diff --git a/Utilities/sysinfo.h b/Utilities/sysinfo.h index 8f7ca70441..963c20df54 100644 --- a/Utilities/sysinfo.h +++ b/Utilities/sysinfo.h @@ -16,21 +16,11 @@ namespace utils return {0u+regs[0], 0u+regs[1], 0u+regs[2], 0u+regs[3]}; } - inline bool has_ssse3() - { - return get_cpuid(0, 0)[0] >= 0x1 && get_cpuid(1, 0)[2] & 0x200; - } + bool has_ssse3(); - inline bool has_avx() - { - return get_cpuid(0, 0)[0] >= 0x1 && get_cpuid(1, 0)[2] & 0x10000000; - } + bool has_avx(); - inline bool has_rtm() - { - // Check RTM and MPX extensions in order to filter out TSX on Haswell CPUs - return get_cpuid(0, 0)[0] >= 0x7 && (get_cpuid(7, 0)[1] & 0x4800) == 0x4800; - } + bool has_rtm(); inline bool transaction_enter() {