2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
2021-07-05 03:22:19 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2013-02-26 20:49:00 +01:00
|
|
|
|
2017-04-21 12:03:40 +02:00
|
|
|
#include <cstring>
|
2014-06-03 01:27:50 +02:00
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2019-11-26 05:31:45 +01:00
|
|
|
#include <thread>
|
|
|
|
|
2021-04-18 01:50:24 +02:00
|
|
|
#if !defined(_WIN32) && !defined(__APPLE__)
|
2020-08-27 22:54:04 +02:00
|
|
|
#ifndef __FreeBSD__
|
2019-11-26 05:31:45 +01:00
|
|
|
#include <asm/hwcap.h>
|
2020-08-27 22:54:04 +02:00
|
|
|
#endif
|
2015-06-13 14:29:19 +02:00
|
|
|
#include <sys/auxv.h>
|
2015-12-23 01:20:48 +01:00
|
|
|
#include <unistd.h>
|
2019-11-26 05:31:45 +01:00
|
|
|
#endif
|
2014-06-03 01:27:50 +02:00
|
|
|
|
2019-06-14 16:53:46 +02:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "Common/CPUDetect.h"
|
2014-09-08 03:06:58 +02:00
|
|
|
#include "Common/CommonTypes.h"
|
2017-12-05 21:23:35 +01:00
|
|
|
#include "Common/FileUtil.h"
|
2013-02-26 20:49:00 +01:00
|
|
|
|
2019-11-26 05:31:45 +01:00
|
|
|
#ifndef WIN32
|
|
|
|
|
2013-02-26 20:49:00 +01:00
|
|
|
const char procfile[] = "/proc/cpuinfo";
|
|
|
|
|
2014-09-22 23:45:42 +02:00
|
|
|
static std::string GetCPUString()
|
2013-02-26 20:49:00 +01:00
|
|
|
{
|
2014-06-03 01:27:50 +02:00
|
|
|
const std::string marker = "Hardware\t: ";
|
|
|
|
std::string cpu_string = "Unknown";
|
|
|
|
|
|
|
|
std::string line;
|
2017-12-05 21:23:35 +01:00
|
|
|
std::ifstream file;
|
|
|
|
File::OpenFStream(file, procfile, std::ios_base::in);
|
2014-06-03 01:27:50 +02:00
|
|
|
|
|
|
|
if (!file)
|
|
|
|
return cpu_string;
|
2013-10-29 06:23:17 +01:00
|
|
|
|
2014-06-03 01:27:50 +02:00
|
|
|
while (std::getline(file, line))
|
2013-02-26 20:49:00 +01:00
|
|
|
{
|
2014-06-03 01:27:50 +02:00
|
|
|
if (line.find(marker) != std::string::npos)
|
|
|
|
{
|
|
|
|
cpu_string = line.substr(marker.length());
|
|
|
|
break;
|
|
|
|
}
|
2013-02-26 20:49:00 +01:00
|
|
|
}
|
2014-06-03 01:27:50 +02:00
|
|
|
|
|
|
|
return cpu_string;
|
2013-02-26 20:49:00 +01:00
|
|
|
}
|
2013-07-16 08:22:06 +02:00
|
|
|
|
2019-11-26 05:31:45 +01:00
|
|
|
#endif
|
|
|
|
|
2013-02-26 20:49:00 +01:00
|
|
|
CPUInfo cpu_info;
|
|
|
|
|
2014-06-03 01:27:50 +02:00
|
|
|
CPUInfo::CPUInfo()
|
|
|
|
{
|
2013-02-26 20:49:00 +01:00
|
|
|
Detect();
|
|
|
|
}
|
|
|
|
|
2015-01-11 06:17:29 +01:00
|
|
|
// Detects the various CPU features
|
2013-02-26 20:49:00 +01:00
|
|
|
void CPUInfo::Detect()
|
|
|
|
{
|
|
|
|
// Set some defaults here
|
|
|
|
HTT = false;
|
2014-06-02 06:49:23 +02:00
|
|
|
OS64bit = true;
|
|
|
|
CPU64bit = true;
|
|
|
|
Mode64bit = true;
|
2018-04-01 23:43:40 +02:00
|
|
|
vendor = CPUVendor::ARM;
|
2021-06-14 15:51:59 +02:00
|
|
|
bFMA = true;
|
2021-01-20 14:18:05 +01:00
|
|
|
bFlushToZero = true;
|
2021-05-26 14:38:29 +02:00
|
|
|
bAFP = false;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2021-01-13 15:23:57 +01:00
|
|
|
#ifdef __APPLE__
|
|
|
|
num_cores = std::thread::hardware_concurrency();
|
|
|
|
|
|
|
|
// M-series CPUs have all of these
|
|
|
|
bFP = true;
|
|
|
|
bASIMD = true;
|
|
|
|
bAES = true;
|
|
|
|
bSHA1 = true;
|
|
|
|
bSHA2 = true;
|
|
|
|
bCRC32 = true;
|
|
|
|
#elif defined(_WIN32)
|
2019-11-26 05:31:45 +01:00
|
|
|
num_cores = std::thread::hardware_concurrency();
|
|
|
|
|
|
|
|
// Windows does not provide any mechanism for querying the system registers on ARMv8, unlike Linux
|
|
|
|
// which traps the register reads and emulates them in the kernel. There are environment variables
|
|
|
|
// containing some of the CPU-specific values, which we could use for a lookup table in the
|
|
|
|
// future. For now, assume all features are present as all known devices which are Windows-on-ARM
|
|
|
|
// compatible also support these extensions.
|
|
|
|
bFP = true;
|
|
|
|
bASIMD = true;
|
|
|
|
bAES = true;
|
|
|
|
bCRC32 = true;
|
|
|
|
bSHA1 = true;
|
|
|
|
bSHA2 = true;
|
|
|
|
#else
|
2013-02-26 20:49:00 +01:00
|
|
|
// Get the information about the CPU
|
2015-06-13 14:29:19 +02:00
|
|
|
num_cores = sysconf(_SC_NPROCESSORS_CONF);
|
2014-06-02 06:49:23 +02:00
|
|
|
strncpy(cpu_string, GetCPUString().c_str(), sizeof(cpu_string));
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2020-08-27 22:54:04 +02:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
u_long hwcaps = 0;
|
|
|
|
elf_aux_info(AT_HWCAP, &hwcaps, sizeof(u_long));
|
|
|
|
#else
|
2015-06-13 14:29:19 +02:00
|
|
|
unsigned long hwcaps = getauxval(AT_HWCAP);
|
2020-08-27 22:54:04 +02:00
|
|
|
#endif
|
2015-06-13 14:29:19 +02:00
|
|
|
bFP = hwcaps & HWCAP_FP;
|
|
|
|
bASIMD = hwcaps & HWCAP_ASIMD;
|
|
|
|
bAES = hwcaps & HWCAP_AES;
|
|
|
|
bCRC32 = hwcaps & HWCAP_CRC32;
|
|
|
|
bSHA1 = hwcaps & HWCAP_SHA1;
|
|
|
|
bSHA2 = hwcaps & HWCAP_SHA2;
|
2019-11-26 05:31:45 +01:00
|
|
|
#endif
|
2013-02-26 20:49:00 +01:00
|
|
|
}
|
|
|
|
|
2015-01-11 06:17:29 +01:00
|
|
|
// Turn the CPU info into a string we can show
|
2013-02-26 20:49:00 +01:00
|
|
|
std::string CPUInfo::Summarize()
|
|
|
|
{
|
|
|
|
std::string sum;
|
|
|
|
if (num_cores == 1)
|
2019-06-14 16:53:46 +02:00
|
|
|
sum = fmt::format("{}, 1 core", cpu_string);
|
2013-02-26 20:49:00 +01:00
|
|
|
else
|
2019-06-14 16:53:46 +02:00
|
|
|
sum = fmt::format("{}, {} cores", cpu_string, num_cores);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2015-06-13 14:29:19 +02:00
|
|
|
if (bAES)
|
|
|
|
sum += ", AES";
|
|
|
|
if (bCRC32)
|
|
|
|
sum += ", CRC32";
|
|
|
|
if (bSHA1)
|
|
|
|
sum += ", SHA1";
|
|
|
|
if (bSHA2)
|
|
|
|
sum += ", SHA2";
|
2014-06-02 06:49:23 +02:00
|
|
|
if (CPU64bit)
|
|
|
|
sum += ", 64-bit";
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-02-26 20:49:00 +01:00
|
|
|
return sum;
|
|
|
|
}
|