Optimize cpuid

This commit is contained in:
Nekotekina 2017-11-09 20:33:18 +03:00
parent 9bc0ec586a
commit 916851bd4a
2 changed files with 23 additions and 14 deletions

View File

@ -7,6 +7,25 @@
#include <unistd.h>
#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())

View File

@ -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()
{