From 474d0f58f5f7c788f75798504173d653f4371b0a Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Sat, 28 Aug 2021 17:40:32 -0500 Subject: [PATCH] Add support for the RISC-V architecture Supports RV64GC (RISC-V 64-bit with general-purpose and compressed-instruction extensions) --- core/os/os.cpp | 9 +++++++++ modules/denoise/config.py | 5 +++-- modules/mono/config.py | 2 +- modules/raycast/config.py | 2 ++ modules/regex/config.py | 2 +- modules/theora/config.py | 2 ++ platform/linuxbsd/detect.py | 7 +++++++ 7 files changed, 25 insertions(+), 4 deletions(-) diff --git a/core/os/os.cpp b/core/os/os.cpp index 7404ffdcd5..5892f91ff3 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -431,6 +431,15 @@ bool OS::has_feature(const String &p_feature) { if (p_feature == "arm") { return true; } +#elif defined(__riscv) +#if __riscv_xlen == 8 + if (p_feature == "rv64") { + return true; + } +#endif + if (p_feature == "riscv") { + return true; + } #endif if (_check_internal_feature_support(p_feature)) { diff --git a/modules/denoise/config.py b/modules/denoise/config.py index 49a1f036ed..6f650354cb 100644 --- a/modules/denoise/config.py +++ b/modules/denoise/config.py @@ -1,11 +1,12 @@ def can_build(env, platform): # Thirdparty dependency OpenImage Denoise includes oneDNN library - # which only supports 64-bit architectures. + # and the version we use only supports x86_64. # It's also only relevant for tools build and desktop platforms, # as doing lightmap generation and denoising on Android or HTML5 # would be a bit far-fetched. desktop_platforms = ["linuxbsd", "osx", "windows"] - return env["tools"] and platform in desktop_platforms and env["bits"] == "64" and env["arch"] != "arm64" + supported_arch = env["bits"] == "64" and env["arch"] != "arm64" and not env["arch"].startswith("rv") + return env["tools"] and platform in desktop_platforms and supported_arch def configure(env): diff --git a/modules/mono/config.py b/modules/mono/config.py index 4c851a2989..df02d9a309 100644 --- a/modules/mono/config.py +++ b/modules/mono/config.py @@ -2,7 +2,7 @@ supported_platforms = ["windows", "osx", "linuxbsd", "server", "android", "haiku def can_build(env, platform): - return True + return not env["arch"].startswith("rv") def configure(env): diff --git a/modules/raycast/config.py b/modules/raycast/config.py index 5de36c5322..2f8bacd4ae 100644 --- a/modules/raycast/config.py +++ b/modules/raycast/config.py @@ -1,5 +1,7 @@ def can_build(env, platform): # Depends on Embree library, which only supports x86_64 and aarch64. + if env["arch"].startswith("rv"): + return False if platform == "android": return env["android_arch"] in ["arm64v8", "x86_64"] diff --git a/modules/regex/config.py b/modules/regex/config.py index df9f44cb95..1248a8374d 100644 --- a/modules/regex/config.py +++ b/modules/regex/config.py @@ -1,5 +1,5 @@ def can_build(env, platform): - return True + return not env["arch"].startswith("rv") def configure(env): diff --git a/modules/theora/config.py b/modules/theora/config.py index b063ed51f9..7f354a8fda 100644 --- a/modules/theora/config.py +++ b/modules/theora/config.py @@ -1,4 +1,6 @@ def can_build(env, platform): + if env["arch"].startswith("rv"): + return False return env.module_check_dependencies("theora", ["ogg", "vorbis"]) diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py index 1b9dd1e8f3..4b3804d049 100644 --- a/platform/linuxbsd/detect.py +++ b/platform/linuxbsd/detect.py @@ -119,6 +119,13 @@ def configure(env): if env["bits"] == "default": env["bits"] = "64" if is64 else "32" + if env["arch"] == "" and platform.machine() == "riscv64": + env["arch"] = "rv64" + + if env["arch"] == "rv64": + # G = General-purpose extensions, C = Compression extension (very common). + env.Append(CCFLAGS=["-march=rv64gc"]) + ## Compiler configuration if "CXX" in env and "clang" in os.path.basename(env["CXX"]):