RISC-V CPU detect

This commit is contained in:
Pierce Andjelkovic 2021-07-28 21:58:56 +10:00
parent 43ae3539a6
commit d9a3741fcb
8 changed files with 134 additions and 0 deletions

View File

@ -430,6 +430,7 @@ set(CommonMIPS
source_group(MIPS FILES ${CommonMIPS})
set(CommonRISCV64
Common/RiscVCPUDetect.cpp
Core/MIPS/fake/FakeJit.cpp
Core/MIPS/fake/FakeJit.h
)

View File

@ -898,6 +898,7 @@
<ClCompile Include="Render\Text\draw_text_uwp.cpp" />
<ClCompile Include="Render\Text\draw_text_win.cpp" />
<ClCompile Include="LogReporting.cpp" />
<ClCompile Include="RiscVCPUDetect.cpp" />
<ClCompile Include="Serialize\Serializer.cpp" />
<ClCompile Include="Data\Convert\ColorConv.cpp" />
<ClCompile Include="ConsoleListener.cpp" />

View File

@ -777,6 +777,7 @@
<ClCompile Include="Thread\ParallelLoop.cpp">
<Filter>Thread</Filter>
</ClCompile>
<ClCompile Include="RiscVCPUDetect.cpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="Crypto">

View File

@ -22,6 +22,8 @@
#define REAL_CPUDETECT_AVAIL 1
#elif PPSSPP_ARCH(MIPS) || PPSSPP_ARCH(MIPS64)
#define REAL_CPUDETECT_AVAIL 1
#elif PPSSPP_ARCH(RISCV64)
#define REAL_CPUDETECT_AVAIL 1
#endif
#ifndef REAL_CPUDETECT_AVAIL

121
Common/RiscVCPUDetect.cpp Normal file
View File

@ -0,0 +1,121 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "ppsspp_config.h"
#if PPSSPP_ARCH(RISCV64)
#include "Common/Common.h"
#include "Common/CPUDetect.h"
#include "Common/StringUtils.h"
#include "Common/File/FileUtil.h"
#include "Common/Data/Encoding/Utf8.h"
#include <cstring>
#include <sstream>
// Only Linux platforms have /proc/cpuinfo
#if defined(__linux__)
const char procfile[] = "/proc/cpuinfo";
// https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-system-cpu
const char syscpupresentfile[] = "/sys/devices/system/cpu/present";
std::string GetCPUString() {
std::string cpu_string = "Unknown";
return cpu_string;
}
int GetCoreCount()
{
std::string line, marker = "processor\t: ";
int cores = 1;
std::string presentData;
bool presentSuccess = File::ReadFileToString(true, syscpupresentfile, presentData);
std::istringstream presentFile(presentData);
if (presentSuccess) {
int low, high, found;
std::getline(presentFile, line);
found = sscanf(line.c_str(), "%d-%d", &low, &high);
if (found == 1)
return 1;
if (found == 2)
return high - low + 1;
}
std::string procdata;
if (!File::ReadFileToString(true, procfile, procdata))
return 1;
std::istringstream file(procdata);
while (std::getline(file, line))
{
if (line.find(marker) != std::string::npos)
++cores;
}
return cores;
}
#endif
CPUInfo cpu_info;
CPUInfo::CPUInfo() {
Detect();
}
// Detects the various cpu features
void CPUInfo::Detect()
{
// Set some defaults here
HTT = false;
#if PPSSPP_ARCH(RISCV64)
OS64bit = true;
CPU64bit = true;
Mode64bit = true;
#else
OS64bit = false;
CPU64bit = false;
Mode64bit = false;
#endif
vendor = VENDOR_OTHER;
logical_cpu_count = 1;
// Get the information about the CPU
#if !defined(__linux__)
num_cores = 1;
#else // __linux__
strncpy(cpu_string, GetCPUString().c_str(), sizeof(cpu_string));
unsigned short CPUPart = GetCPUPart();
num_cores = GetCoreCount();
#endif
}
// Turn the cpu info into a string we can show
std::string CPUInfo::Summarize()
{
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 (CPU64bit) sum += ", 64-bit";
return sum;
}
#endif // PPSSPP_ARCH(RISCV64)

View File

@ -423,6 +423,8 @@ const char *GetCompilerABI() {
return "x86";
#elif PPSSPP_ARCH(AMD64)
return "x86-64";
#elif PPSSPP_ARCH(RISCV64)
return "rv64";
#else
return "other";
#endif

View File

@ -300,6 +300,7 @@ SOURCES_CXX += \
$(COMMONDIR)/OSVersion.cpp \
$(COMMONDIR)/MemoryUtil.cpp \
$(COMMONDIR)/MipsCPUDetect.cpp \
$(COMMONDIR)/RiscVCPUDetect.cpp \
$(COMMONDIR)/LogReporting.cpp \
$(COMMONDIR)/SysError.cpp \
$(COMMONDIR)/StringUtils.cpp \

View File

@ -64,6 +64,11 @@
#define PPSSPP_ARCH_32BIT 1
#endif
#if defined(__riscv64__)
#define PPSSPP_ARCH_RISCV64 1
#define PPSSPP_ARCH_64BIT 1
#endif
// PLATFORM defines
#if defined(_WIN32)