2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2014-02-17 10:18:15 +00:00
|
|
|
// Refer to the license.txt file included.
|
2013-02-26 19:49:00 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
#include <asm/hwcap.h>
|
2017-04-21 10:03:40 +00:00
|
|
|
#include <cstring>
|
2014-06-02 23:27:50 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2015-06-13 12:29:19 +00:00
|
|
|
#include <sys/auxv.h>
|
2016-06-24 08:43:46 +00:00
|
|
|
#include <unistd.h>
|
2014-06-02 23:27:50 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/CPUDetect.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2017-12-05 20:23:35 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2014-02-20 03:11:52 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2013-02-26 19:49:00 +00:00
|
|
|
|
|
|
|
const char procfile[] = "/proc/cpuinfo";
|
|
|
|
|
2014-09-22 21:45:42 +00:00
|
|
|
static std::string GetCPUString()
|
2013-02-26 19:49:00 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
const std::string marker = "Hardware\t: ";
|
|
|
|
std::string cpu_string = "Unknown";
|
2014-06-02 23:27:50 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string line;
|
2017-12-05 20:23:35 +00:00
|
|
|
std::ifstream file;
|
|
|
|
File::OpenFStream(file, procfile, std::ios_base::in);
|
2014-06-02 23:27:50 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!file)
|
|
|
|
return cpu_string;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
while (std::getline(file, line))
|
|
|
|
{
|
|
|
|
if (line.find(marker) != std::string::npos)
|
|
|
|
{
|
|
|
|
cpu_string = line.substr(marker.length());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-02 23:27:50 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return cpu_string;
|
2013-02-26 19:49:00 +00:00
|
|
|
}
|
2013-07-16 06:22:06 +00:00
|
|
|
|
2013-02-26 19:49:00 +00:00
|
|
|
CPUInfo cpu_info;
|
|
|
|
|
2014-06-02 23:27:50 +00:00
|
|
|
CPUInfo::CPUInfo()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
Detect();
|
2013-02-26 19:49:00 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 05:17:29 +00:00
|
|
|
// Detects the various CPU features
|
2013-02-26 19:49:00 +00:00
|
|
|
void CPUInfo::Detect()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// Set some defaults here
|
|
|
|
// When ARMv8 CPUs come out, these need to be updated.
|
|
|
|
HTT = false;
|
|
|
|
OS64bit = true;
|
|
|
|
CPU64bit = true;
|
|
|
|
Mode64bit = true;
|
|
|
|
vendor = VENDOR_ARM;
|
|
|
|
|
|
|
|
// Get the information about the CPU
|
|
|
|
num_cores = sysconf(_SC_NPROCESSORS_CONF);
|
|
|
|
strncpy(cpu_string, GetCPUString().c_str(), sizeof(cpu_string));
|
|
|
|
|
|
|
|
unsigned long hwcaps = getauxval(AT_HWCAP);
|
|
|
|
bFP = hwcaps & HWCAP_FP;
|
|
|
|
bASIMD = hwcaps & HWCAP_ASIMD;
|
|
|
|
bAES = hwcaps & HWCAP_AES;
|
|
|
|
bCRC32 = hwcaps & HWCAP_CRC32;
|
|
|
|
bSHA1 = hwcaps & HWCAP_SHA1;
|
|
|
|
bSHA2 = hwcaps & HWCAP_SHA2;
|
2013-02-26 19:49:00 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 05:17:29 +00:00
|
|
|
// Turn the CPU info into a string we can show
|
2013-02-26 19:49:00 +00:00
|
|
|
std::string CPUInfo::Summarize()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string sum;
|
|
|
|
if (num_cores == 1)
|
|
|
|
sum = StringFromFormat("%s, %i core", cpu_string, num_cores);
|
|
|
|
else
|
|
|
|
sum = StringFromFormat("%s, %i cores", cpu_string, num_cores);
|
|
|
|
|
|
|
|
if (bAES)
|
|
|
|
sum += ", AES";
|
|
|
|
if (bCRC32)
|
|
|
|
sum += ", CRC32";
|
|
|
|
if (bSHA1)
|
|
|
|
sum += ", SHA1";
|
|
|
|
if (bSHA2)
|
|
|
|
sum += ", SHA2";
|
|
|
|
if (CPU64bit)
|
|
|
|
sum += ", 64-bit";
|
|
|
|
|
|
|
|
return sum;
|
2013-02-26 19:49:00 +00:00
|
|
|
}
|