Skip to content

Commit

Permalink
Merge pull request #14561 from archanox/master
Browse files Browse the repository at this point in the history
RISC-V Port
  • Loading branch information
hrydgard authored Aug 7, 2021
2 parents f6ef219 + 1e949c8 commit ff340b8
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 1 deletion.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ if(CMAKE_SYSTEM_PROCESSOR)
set(X86_DEVICE ON)
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^mips")
set(MIPS_DEVICE ON)
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^riscv64")
set(RISCV64_DEVICE ON)
else()
message("Unknown CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
Expand Down Expand Up @@ -113,6 +115,7 @@ endif()
option(ARMV7 "Set to ON if targeting an ARMv7 processor" ${ARMV7_DEVICE})
option(ARM "Set to ON if targeting an ARM processor" ${ARM_DEVICE})
option(MIPS "Set to ON if targeting a MIPS processor" ${MIPS_DEVICE})
option(RISCV64 "Set to ON if targeting a RISCV64 processor" ${RISCV64_DEVICE})
option(X86 "Set to ON if targeting an X86 processor" ${X86_DEVICE})
option(X86_64 "Set to ON if targeting an X86_64 processor" ${X86_64_DEVICE})
# :: Environments
Expand Down Expand Up @@ -248,6 +251,9 @@ endif()
if(MIPS)
message("Generating for MIPS, ${CMAKE_BUILD_TYPE}")
endif()
if(RISCV64)
message("Generating for RISCV64, ${CMAKE_BUILD_TYPE}")
endif()
if(X86)
message("Generating for x86, ${CMAKE_BUILD_TYPE}")
endif()
Expand Down Expand Up @@ -423,6 +429,13 @@ set(CommonMIPS
)
source_group(MIPS FILES ${CommonMIPS})

set(CommonRISCV64
Common/RiscVCPUDetect.cpp
Core/MIPS/fake/FakeJit.cpp
Core/MIPS/fake/FakeJit.h
)
source_group(RISCV64 FILES ${CommonRISCV64})

if(WIN32)
set(CommonD3D
Common/GPU/D3D9/D3D9ShaderCompiler.cpp
Expand All @@ -442,6 +455,7 @@ add_library(Common STATIC
${CommonARM}
${CommonARM64}
${CommonMIPS}
${CommonRISCV64}
${CommonD3D}
Common/Serialize/Serializer.cpp
Common/Serialize/Serializer.h
Expand Down Expand Up @@ -712,6 +726,8 @@ if(USE_FFMPEG)
set(PLATFORM_ARCH "linux/arm")
elseif(MIPS)
set(PLATFORM_ARCH "linux/mips32")
elseif(RISCV64)
set(PLATFORM_ARCH "linux/riscv64")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PLATFORM_ARCH "linux/x86_64")
elseif(X86)
Expand Down
1 change: 1 addition & 0 deletions Common/Common.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
1 change: 1 addition & 0 deletions Common/Common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@
<ClCompile Include="Thread\ParallelLoop.cpp">
<Filter>Thread</Filter>
</ClCompile>
<ClCompile Include="RiscVCPUDetect.cpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="Crypto">
Expand Down
2 changes: 2 additions & 0 deletions Common/FakeCPUDetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
131 changes: 131 additions & 0 deletions Common/RiscVCPUDetect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// 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() {
//TODO
std::string cpu_string;
cpu_string = "Unknown";
return cpu_string;
}

std::string GetCPUBrandString() {
//TODO
std::string brand_string;
brand_string = "Unknown";
return brand_string;
}

int GetCoreCount()
{
std::string line, marker = "processor\t: ";
int cores = 1;

std::string presentData;
bool presentSuccess = File::ReadFileToString(true, Path(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, Path(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__
truncate_cpy(cpu_string, GetCPUString().c_str());
truncate_cpy(brand_string, GetCPUBrandString().c_str());
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";

//TODO: parse "isa : rv64imafdc" from /proc/cpuinfo

return sum;
}

#endif // PPSSPP_ARCH(RISCV64)
12 changes: 12 additions & 0 deletions UI/DevScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,18 @@ const char *GetCompilerABI() {
return "x86";
#elif PPSSPP_ARCH(AMD64)
return "x86-64";
#elif PPSSPP_ARCH(RISCV64)
//https://github.com/riscv/riscv-toolchain-conventions#cc-preprocessor-definitions
//https://github.com/riscv/riscv-c-api-doc/blob/master/riscv-c-api.md#abi-related-preprocessor-definitions
#if defined(__riscv_float_abi_single)
return "lp64f";
#elif defined(__riscv_float_abi_double)
return "lp64d";
#elif defined(__riscv_float_abi_quad)
return "lp64q";
#elif defined(__riscv_float_abi_soft)
return "lp64";
#endif
#else
return "other";
#endif
Expand Down
2 changes: 1 addition & 1 deletion ffmpeg
Submodule ffmpeg updated 96 files
+1 −1 PPSSPP-README.md
+5,402 −0 linux/riscv64/include/libavcodec/avcodec.h
+84 −0 linux/riscv64/include/libavcodec/avdct.h
+118 −0 linux/riscv64/include/libavcodec/avfft.h
+112 −0 linux/riscv64/include/libavcodec/d3d11va.h
+131 −0 linux/riscv64/include/libavcodec/dirac.h
+83 −0 linux/riscv64/include/libavcodec/dv_profile.h
+93 −0 linux/riscv64/include/libavcodec/dxva2.h
+107 −0 linux/riscv64/include/libavcodec/qsv.h
+189 −0 linux/riscv64/include/libavcodec/vaapi.h
+230 −0 linux/riscv64/include/libavcodec/vda.h
+253 −0 linux/riscv64/include/libavcodec/vdpau.h
+216 −0 linux/riscv64/include/libavcodec/version.h
+126 −0 linux/riscv64/include/libavcodec/videotoolbox.h
+78 −0 linux/riscv64/include/libavcodec/vorbis_parser.h
+170 −0 linux/riscv64/include/libavcodec/xvmc.h
+2,859 −0 linux/riscv64/include/libavformat/avformat.h
+732 −0 linux/riscv64/include/libavformat/avio.h
+81 −0 linux/riscv64/include/libavformat/version.h
+55 −0 linux/riscv64/include/libavutil/adler32.h
+65 −0 linux/riscv64/include/libavutil/aes.h
+83 −0 linux/riscv64/include/libavutil/aes_ctr.h
+168 −0 linux/riscv64/include/libavutil/attributes.h
+170 −0 linux/riscv64/include/libavutil/audio_fifo.h
+66 −0 linux/riscv64/include/libavutil/avassert.h
+7 −0 linux/riscv64/include/libavutil/avconfig.h
+402 −0 linux/riscv64/include/libavutil/avstring.h
+343 −0 linux/riscv64/include/libavutil/avutil.h
+67 −0 linux/riscv64/include/libavutil/base64.h
+82 −0 linux/riscv64/include/libavutil/blowfish.h
+219 −0 linux/riscv64/include/libavutil/bprint.h
+109 −0 linux/riscv64/include/libavutil/bswap.h
+274 −0 linux/riscv64/include/libavutil/buffer.h
+70 −0 linux/riscv64/include/libavutil/camellia.h
+80 −0 linux/riscv64/include/libavutil/cast5.h
+223 −0 linux/riscv64/include/libavutil/channel_layout.h
+530 −0 linux/riscv64/include/libavutil/common.h
+117 −0 linux/riscv64/include/libavutil/cpu.h
+91 −0 linux/riscv64/include/libavutil/crc.h
+77 −0 linux/riscv64/include/libavutil/des.h
+198 −0 linux/riscv64/include/libavutil/dict.h
+86 −0 linux/riscv64/include/libavutil/display.h
+115 −0 linux/riscv64/include/libavutil/downmix_info.h
+126 −0 linux/riscv64/include/libavutil/error.h
+113 −0 linux/riscv64/include/libavutil/eval.h
+5 −0 linux/riscv64/include/libavutil/ffversion.h
+179 −0 linux/riscv64/include/libavutil/fifo.h
+68 −0 linux/riscv64/include/libavutil/file.h
+723 −0 linux/riscv64/include/libavutil/frame.h
+112 −0 linux/riscv64/include/libavutil/hash.h
+100 −0 linux/riscv64/include/libavutil/hmac.h
+213 −0 linux/riscv64/include/libavutil/imgutils.h
+77 −0 linux/riscv64/include/libavutil/intfloat.h
+629 −0 linux/riscv64/include/libavutil/intreadwrite.h
+62 −0 linux/riscv64/include/libavutil/lfg.h
+359 −0 linux/riscv64/include/libavutil/log.h
+50 −0 linux/riscv64/include/libavutil/macros.h
+89 −0 linux/riscv64/include/libavutil/mastering_display_metadata.h
+165 −0 linux/riscv64/include/libavutil/mathematics.h
+81 −0 linux/riscv64/include/libavutil/md5.h
+406 −0 linux/riscv64/include/libavutil/mem.h
+57 −0 linux/riscv64/include/libavutil/motion_vector.h
+32 −0 linux/riscv64/include/libavutil/murmur3.h
+865 −0 linux/riscv64/include/libavutil/opt.h
+193 −0 linux/riscv64/include/libavutil/parseutils.h
+394 −0 linux/riscv64/include/libavutil/pixdesc.h
+52 −0 linux/riscv64/include/libavutil/pixelutils.h
+473 −0 linux/riscv64/include/libavutil/pixfmt.h
+43 −0 linux/riscv64/include/libavutil/random_seed.h
+173 −0 linux/riscv64/include/libavutil/rational.h
+66 −0 linux/riscv64/include/libavutil/rc4.h
+51 −0 linux/riscv64/include/libavutil/replaygain.h
+75 −0 linux/riscv64/include/libavutil/ripemd.h
+271 −0 linux/riscv64/include/libavutil/samplefmt.h
+74 −0 linux/riscv64/include/libavutil/sha.h
+75 −0 linux/riscv64/include/libavutil/sha512.h
+152 −0 linux/riscv64/include/libavutil/stereo3d.h
+71 −0 linux/riscv64/include/libavutil/tea.h
+107 −0 linux/riscv64/include/libavutil/threadmessage.h
+56 −0 linux/riscv64/include/libavutil/time.h
+140 −0 linux/riscv64/include/libavutil/timecode.h
+78 −0 linux/riscv64/include/libavutil/timestamp.h
+138 −0 linux/riscv64/include/libavutil/tree.h
+70 −0 linux/riscv64/include/libavutil/twofish.h
+128 −0 linux/riscv64/include/libavutil/version.h
+94 −0 linux/riscv64/include/libavutil/xtea.h
+553 −0 linux/riscv64/include/libswresample/swresample.h
+45 −0 linux/riscv64/include/libswresample/version.h
+350 −0 linux/riscv64/include/libswscale/swscale.h
+49 −0 linux/riscv64/include/libswscale/version.h
+ linux/riscv64/lib/libavcodec.a
+ linux/riscv64/lib/libavformat.a
+ linux/riscv64/lib/libavutil.a
+ linux/riscv64/lib/libswresample.a
+ linux/riscv64/lib/libswscale.a
+97 −0 linux_riscv64.sh
1 change: 1 addition & 0 deletions libretro/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
6 changes: 6 additions & 0 deletions ppsspp_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
#define PPSSPP_ARCH_32BIT 1
#endif

#if defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64
//https://github.com/riscv/riscv-c-api-doc/blob/master/riscv-c-api.md
#define PPSSPP_ARCH_RISCV64 1
#define PPSSPP_ARCH_64BIT 1
#endif


// PLATFORM defines
#if defined(_WIN32)
Expand Down

0 comments on commit ff340b8

Please sign in to comment.