2017-07-18 12:21:29 +00:00
|
|
|
#include "sysinfo.h"
|
|
|
|
#include "StrFmt.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "windows.h"
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2017-11-09 17:33:18 +00:00
|
|
|
bool utils::has_ssse3()
|
|
|
|
{
|
|
|
|
static const bool g_value = get_cpuid(0, 0)[0] >= 0x1 && get_cpuid(1, 0)[2] & 0x200;
|
|
|
|
return g_value;
|
|
|
|
}
|
|
|
|
|
2018-04-09 14:45:37 +00:00
|
|
|
bool utils::has_sse41()
|
|
|
|
{
|
|
|
|
static const bool g_value = get_cpuid(0, 0)[0] >= 0x1 && get_cpuid(1, 0)[2] & 0x80000;
|
|
|
|
return g_value;
|
|
|
|
}
|
|
|
|
|
2017-11-09 17:33:18 +00:00
|
|
|
bool utils::has_avx()
|
|
|
|
{
|
2018-03-23 22:08:13 +00:00
|
|
|
static const bool g_value = get_cpuid(0, 0)[0] >= 0x1 && get_cpuid(1, 0)[2] & 0x10000000 && (get_cpuid(1, 0)[2] & 0x0C000000) == 0x0C000000 && (get_xgetbv(0) & 0x6) == 0x6;
|
2017-11-09 17:33:18 +00:00
|
|
|
return g_value;
|
|
|
|
}
|
|
|
|
|
2017-12-16 00:19:21 +00:00
|
|
|
bool utils::has_avx2()
|
|
|
|
{
|
2018-03-23 22:08:13 +00:00
|
|
|
static const bool g_value = get_cpuid(0, 0)[0] >= 0x7 && get_cpuid(7, 0)[1] & 0x20 && (get_cpuid(1, 0)[2] & 0x0C000000) == 0x0C000000 && (get_xgetbv(0) & 0x6) == 0x6;
|
2017-12-16 00:19:21 +00:00
|
|
|
return g_value;
|
|
|
|
}
|
|
|
|
|
2017-11-09 17:33:18 +00:00
|
|
|
bool utils::has_rtm()
|
|
|
|
{
|
2018-06-13 11:54:16 +00:00
|
|
|
static const bool g_value = get_cpuid(0, 0)[0] >= 0x7 && (get_cpuid(7, 0)[1] & 0x800) == 0x800;
|
|
|
|
return g_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool utils::has_mpx()
|
|
|
|
{
|
|
|
|
static const bool g_value = get_cpuid(0, 0)[0] >= 0x7 && (get_cpuid(7, 0)[1] & 0x4000) == 0x4000;
|
2017-11-09 17:33:18 +00:00
|
|
|
return g_value;
|
|
|
|
}
|
|
|
|
|
2017-12-16 00:19:21 +00:00
|
|
|
bool utils::has_512()
|
|
|
|
{
|
|
|
|
// Check AVX512F, AVX512CD, AVX512DQ, AVX512BW, AVX512VL extensions (Skylake-X level support)
|
2018-03-23 22:08:13 +00:00
|
|
|
static const bool g_value = get_cpuid(0, 0)[0] >= 0x7 && (get_cpuid(7, 0)[1] & 0xd0030000) == 0xd0030000 && (get_cpuid(1,0)[2] & 0x0C000000) == 0x0C000000 && (get_xgetbv(0) & 0xe6) == 0xe6;
|
2017-12-16 00:19:21 +00:00
|
|
|
return g_value;
|
|
|
|
}
|
|
|
|
|
2018-01-16 11:32:57 +00:00
|
|
|
bool utils::has_xop()
|
|
|
|
{
|
|
|
|
static const bool g_value = has_avx() && get_cpuid(0x80000001, 0)[2] & 0x800;
|
|
|
|
return g_value;
|
|
|
|
}
|
|
|
|
|
2017-07-18 12:21:29 +00:00
|
|
|
std::string utils::get_system_info()
|
|
|
|
{
|
|
|
|
std::string result;
|
|
|
|
std::string brand;
|
|
|
|
|
|
|
|
if (get_cpuid(0x80000000, 0)[0] >= 0x80000004)
|
|
|
|
{
|
|
|
|
for (u32 i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
brand.append(reinterpret_cast<const char*>(get_cpuid(0x80000002 + i, 0).data()), 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
brand = "Unknown CPU";
|
|
|
|
}
|
|
|
|
|
2018-09-16 09:46:40 +00:00
|
|
|
brand.erase(brand.find_last_not_of('\0') + 1);
|
2017-07-18 12:21:29 +00:00
|
|
|
brand.erase(brand.find_last_not_of(' ') + 1);
|
2018-09-16 09:46:40 +00:00
|
|
|
brand.erase(0, brand.find_first_not_of(' '));
|
2017-07-18 12:21:29 +00:00
|
|
|
|
|
|
|
while (auto found = brand.find(" ") + 1)
|
|
|
|
{
|
|
|
|
brand.erase(brand.begin() + found);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
::SYSTEM_INFO sysInfo;
|
|
|
|
::GetNativeSystemInfo(&sysInfo);
|
|
|
|
::MEMORYSTATUSEX memInfo;
|
|
|
|
memInfo.dwLength = sizeof(memInfo);
|
|
|
|
::GlobalMemoryStatusEx(&memInfo);
|
|
|
|
const u32 num_proc = sysInfo.dwNumberOfProcessors;
|
|
|
|
const u64 mem_total = memInfo.ullTotalPhys;
|
|
|
|
#else
|
|
|
|
const u32 num_proc = ::sysconf(_SC_NPROCESSORS_ONLN);
|
|
|
|
const u64 mem_total = ::sysconf(_SC_PHYS_PAGES) * ::sysconf(_SC_PAGE_SIZE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fmt::append(result, "%s | %d Threads | %.2f GiB RAM", brand, num_proc, mem_total / (1024.0f * 1024 * 1024));
|
2017-07-18 17:03:47 +00:00
|
|
|
|
|
|
|
if (has_avx())
|
|
|
|
{
|
2017-12-16 00:19:21 +00:00
|
|
|
result += " | AVX";
|
|
|
|
|
|
|
|
if (has_avx2())
|
|
|
|
{
|
|
|
|
result += '+';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_512())
|
|
|
|
{
|
|
|
|
result += '+';
|
|
|
|
}
|
2018-01-16 11:32:57 +00:00
|
|
|
|
|
|
|
if (has_xop())
|
|
|
|
{
|
|
|
|
result += 'x';
|
|
|
|
}
|
2017-07-18 17:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (has_rtm())
|
|
|
|
{
|
|
|
|
result += " | TSX";
|
2018-06-13 11:54:16 +00:00
|
|
|
if (!has_mpx())
|
|
|
|
{
|
|
|
|
result += " disabled by default";
|
|
|
|
}
|
2017-07-18 17:03:47 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 12:21:29 +00:00
|
|
|
return result;
|
|
|
|
}
|