Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loongarch64 support for Linux/*BSD #97822

Merged
merged 2 commits into from
Dec 5, 2024
Merged

Conversation

stdmnpkg
Copy link
Contributor

@stdmnpkg stdmnpkg commented Oct 4, 2024

This PR add support for 64 bit LoongArch CPU architecture.

Tested on Loongson 3A6000 with AMD RX590.

@akien-mga akien-mga added this to the 4.x milestone Oct 4, 2024
@akien-mga akien-mga changed the title Add loongarch64 support Add loongarch64 support for Linux/*BSD Oct 4, 2024
@stdmnpkg
Copy link
Contributor Author

stdmnpkg commented Oct 5, 2024

bundled PCRE2's JIT is not working on LoongArch, which is fixed on newer version.
OpenXR has no LoongArch support yet, but there's an open PR KhronosGroup/OpenXR-SDK-Source#479
OpenXR just added LoongArch support in OpenXR SDK 1.1.42

@stdmnpkg stdmnpkg marked this pull request as ready for review October 7, 2024 15:30
@stdmnpkg stdmnpkg requested review from a team as code owners October 7, 2024 15:30
@stdmnpkg stdmnpkg requested a review from a team as a code owner November 25, 2024 00:34
@adamscott
Copy link
Member

Merging this PR would require some members of the team to possess a loongarch64-based computer. What do you think @akien-mga ?

@adamscott adamscott requested a review from bruvzg December 2, 2024 19:44
Copy link
Member

@aaronfranke aaronfranke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review is a nitpick, in practice it probably doesn't matter, or won't within our lifetimes.

@@ -248,6 +248,9 @@ String Engine::get_architecture_name() const {
return "ppc";
#endif

#elif defined(__loongarch__)
return "loongarch64";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://loongson.github.io/LoongArch-Documentation/LoongArch-toolchain-conventions-EN.html

According to this page, __loongarch64 is a more specific check than __loongarch__, which we can check for to return "loongarch64", and otherwise fall back to a more generic bitless name (like the rv64 code above), ensuring that in case somebody tries to compile on an 32-bit or 128-bit version of the architecture then Godot doesn't still claim to be the 64-bit version (or it can just not compile in those cases).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decide only do more specific check without fallback to generic name. there is no 32-bit LoongArch desktop CPU yet. I think it's better to notify future developers we didn't actually test it by explicitly only support 64-bit LoongArch CPU.

core/os/os.cpp Outdated
Comment on lines 517 to 524
#elif defined(__loongarch__)
if (p_feature == "loongarch64") {
return true;
}
Copy link
Member

@aaronfranke aaronfranke Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, we can use the __loongarch64 define to be more specific about architecture feature flags.

Suggested change
#elif defined(__loongarch__)
if (p_feature == "loongarch64") {
return true;
}
#elif defined(__loongarch__)
#if defined(__loongarch64)
if (p_feature == "loongarch64") {
return true;
}
#endif
if (p_feature == "loongarch") {
return true;
}

Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine.

Tested it in QEMU VM, seems to be building only with the following patch (but probably will also work with system libpng):

diff --git a/drivers/png/SCsub b/drivers/png/SCsub
index 4268a66475..947f0f5f21 100644
--- a/drivers/png/SCsub
+++ b/drivers/png/SCsub
@@ -58,6 +58,8 @@ if env["builtin_libpng"]:
     elif env["arch"] == "ppc64":
         env_thirdparty.add_source_files(thirdparty_obj, thirdparty_dir + "powerpc/powerpc_init.c")
         env_thirdparty.add_source_files(thirdparty_obj, thirdparty_dir + "powerpc/filter_vsx_intrinsics.c")
+    elif env["arch"] == "loongarch64":
+        env_thirdparty.Append(CPPDEFINES=["PNG_LOONGARCH_LSX_OPT=0"])
 
     env.drivers_sources += thirdparty_obj
 

@@ -11,7 +11,7 @@
<members>
<member name="binary_format/architecture" type="String" setter="" getter="">
Application executable architecture.
Supported architectures: [code]x86_32[/code], [code]x86_64[/code], [code]arm64[/code], [code]arm32[/code], [code]rv64[/code], [code]ppc64[/code], and [code]ppc32[/code].
Supported architectures: [code]x86_32[/code], [code]x86_64[/code], [code]arm64[/code], [code]arm32[/code], [code]rv64[/code], [code]ppc64[/code], [code]ppc32[/code] and [code]loongarch64[/code].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Supported architectures: [code]x86_32[/code], [code]x86_64[/code], [code]arm64[/code], [code]arm32[/code], [code]rv64[/code], [code]ppc64[/code], [code]ppc32[/code] and [code]loongarch64[/code].
Supported architectures: [code]x86_32[/code], [code]x86_64[/code], [code]arm64[/code], [code]arm32[/code], [code]rv64[/code], [code]ppc64[/code], [code]ppc32[/code], and [code]loongarch64[/code].

Please keep the Oxford comma.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me!

@akien-mga akien-mga modified the milestones: 4.x, 4.4 Dec 5, 2024
@Repiteo Repiteo merged commit 9951743 into godotengine:master Dec 5, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Dec 5, 2024

Thanks! Congratulations on your first merged contribution! 🎉

@stdmnpkg stdmnpkg deleted the loongarch branch December 18, 2024 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants