diff --git a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
index f62c8b95b7c143..e1230d59401d86 100644
--- a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
+++ b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
@@ -78,6 +78,10 @@
AnyCPU
$(DefineConstants);TARGET_ARM64
+
+ AnyCPU
+ $(DefineConstants);TARGET_LOONGARCH64
+
diff --git a/src/libraries/Microsoft.NETCore.Platforms/src/runtime.compatibility.json b/src/libraries/Microsoft.NETCore.Platforms/src/runtime.compatibility.json
index 8d9a5386431a9c..3d7f5a57eeeb85 100644
--- a/src/libraries/Microsoft.NETCore.Platforms/src/runtime.compatibility.json
+++ b/src/libraries/Microsoft.NETCore.Platforms/src/runtime.compatibility.json
@@ -3638,6 +3638,14 @@
"any",
"base"
],
+ "linux-loongarch64": [
+ "linux-loongarch64",
+ "linux",
+ "unix-loongarch64",
+ "unix",
+ "any",
+ "base"
+ ],
"linux-mips64": [
"linux-mips64",
"linux",
@@ -8100,6 +8108,12 @@
"any",
"base"
],
+ "unix-loongarch64": [
+ "unix-loongarch64",
+ "unix",
+ "any",
+ "base"
+ ],
"unix-mips64": [
"unix-mips64",
"unix",
@@ -8754,4 +8768,4 @@
"any",
"base"
]
-}
+}
\ No newline at end of file
diff --git a/src/libraries/Microsoft.NETCore.Platforms/src/runtime.json b/src/libraries/Microsoft.NETCore.Platforms/src/runtime.json
index 39ca7bdb933c3e..76d454fc536c3a 100644
--- a/src/libraries/Microsoft.NETCore.Platforms/src/runtime.json
+++ b/src/libraries/Microsoft.NETCore.Platforms/src/runtime.json
@@ -1475,6 +1475,12 @@
"unix-armel"
]
},
+ "linux-loongarch64": {
+ "#import": [
+ "linux",
+ "unix-loongarch64"
+ ]
+ },
"linux-mips64": {
"#import": [
"linux",
@@ -3399,6 +3405,11 @@
"unix"
]
},
+ "unix-loongarch64": {
+ "#import": [
+ "unix"
+ ]
+ },
"unix-mips64": {
"#import": [
"unix"
@@ -3743,4 +3754,4 @@
]
}
}
-}
+}
\ No newline at end of file
diff --git a/src/libraries/Microsoft.NETCore.Platforms/src/runtimeGroups.props b/src/libraries/Microsoft.NETCore.Platforms/src/runtimeGroups.props
index bc7832c33b61fc..b8345349409ecb 100644
--- a/src/libraries/Microsoft.NETCore.Platforms/src/runtimeGroups.props
+++ b/src/libraries/Microsoft.NETCore.Platforms/src/runtimeGroups.props
@@ -3,11 +3,11 @@
any
- x64;x86;arm;armel;arm64;mips64;s390x
+ x64;x86;arm;armel;arm64;loongarch64;mips64;s390x
unix
- x64;x86;arm;armel;arm64;mips64;s390x
+ x64;x86;arm;armel;arm64;loongarch64;mips64;s390x
linux
diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Padding.cs b/src/libraries/System.Private.CoreLib/src/Internal/Padding.cs
index 17f3643be3e469..5f846ce3f8b985 100644
--- a/src/libraries/System.Private.CoreLib/src/Internal/Padding.cs
+++ b/src/libraries/System.Private.CoreLib/src/Internal/Padding.cs
@@ -9,7 +9,7 @@ namespace Internal
internal static class PaddingHelpers
{
/// A size greater than or equal to the size of the most common CPU cache lines.
-#if TARGET_ARM64
+#if TARGET_ARM64 || TARGET_LOONGARCH64
internal const int CACHE_LINE_SIZE = 128;
#else
internal const int CACHE_LINE_SIZE = 64;
diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
index 24b049b1df2ff1..3fb7dafbb308b5 100644
--- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
+++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
@@ -17,7 +17,7 @@
true
$(MSBuildThisFileDirectory)ILLink\
true
- true
+ true
true
diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffer.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Buffer.Unix.cs
index 4d0c18ca9d7108..008bc9310a2417 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Buffer.Unix.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Buffer.Unix.cs
@@ -5,7 +5,7 @@ namespace System
{
public static partial class Buffer
{
-#if TARGET_ARM64
+#if TARGET_ARM64 || TARGET_LOONGARCH64
// Managed code is currently faster than glibc unoptimized memmove
// TODO-ARM64-UNIX-OPT revisit when glibc optimized memmove is in Linux distros
// https://github.com/dotnet/runtime/issues/8897
diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffer.cs b/src/libraries/System.Private.CoreLib/src/System/Buffer.cs
index 64bd6fca168e33..027c138d1ac6aa 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Buffer.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Buffer.cs
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-#if TARGET_AMD64 || TARGET_ARM64 || (TARGET_32BIT && !TARGET_ARM)
+#if TARGET_AMD64 || TARGET_ARM64 || (TARGET_32BIT && !TARGET_ARM) || TARGET_LOONGARCH64
#define HAS_CUSTOM_BLOCKS
#endif
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Architecture.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Architecture.cs
index 2c52a9b8ea433c..225fec28c763ac 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Architecture.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Architecture.cs
@@ -10,6 +10,7 @@ public enum Architecture
Arm,
Arm64,
Wasm,
- S390x
+ S390x,
+ LoongArch64
}
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.ProcessArchitecture.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.ProcessArchitecture.cs
index 298d0395042990..0da595b95e0746 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.ProcessArchitecture.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.ProcessArchitecture.cs
@@ -18,6 +18,8 @@ public static Architecture ProcessArchitecture
=> Architecture.Wasm;
#elif TARGET_S390X
=> Architecture.S390x;
+#elif TARGET_LOONGARCH64
+ => Architecture.LoongArch64;
#else
#error Unknown Architecture
#endif
diff --git a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.cs b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.cs
index a7f99e440bfc4b..9cc75163f097f3 100644
--- a/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.cs
@@ -14,7 +14,7 @@ public static unsafe void ClearWithoutReferences(ref byte b, nuint byteLength)
if (byteLength == 0)
return;
-#if TARGET_AMD64 || TARGET_ARM64
+#if TARGET_AMD64 || TARGET_ARM64 || TARGET_LOONGARCH64
// The exact matrix on when ZeroMemory is faster than InitBlockUnaligned is very complex. The factors to consider include
// type of hardware and memory alignment. This threshold was chosen as a good balance across different configurations.
if (byteLength > 768)
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs
index 796c0e505a5e21..7a79c9980447c8 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs
@@ -13,7 +13,7 @@ internal sealed partial class PortableThreadPool
private static class WorkerThread
{
private const int SemaphoreSpinCountDefaultBaseline = 70;
-#if !TARGET_ARM64 && !TARGET_ARM
+#if !TARGET_ARM64 && !TARGET_ARM && !TARGET_LOONGARCH64
private const int SemaphoreSpinCountDefault = SemaphoreSpinCountDefaultBaseline;
#else
// On systems with ARM processors, more spin-waiting seems to be necessary to avoid perf regressions from incurring
diff --git a/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs b/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs
index fee9b78b71fa02..db86c83fe7350a 100644
--- a/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs
+++ b/src/libraries/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs
@@ -3271,6 +3271,8 @@ public enum Machine : ushort
Amd64 = (ushort)34404,
M32R = (ushort)36929,
Arm64 = (ushort)43620,
+ LoongArch32 = (ushort)25138,
+ LoongArch64 = (ushort)25188,
}
public partial class ManagedPEBuilder : System.Reflection.PortableExecutable.PEBuilder
{
diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/Machine.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/Machine.cs
index 2d1dc8ed54afce..c4d3e336616ad6 100644
--- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/Machine.cs
+++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/Machine.cs
@@ -129,5 +129,15 @@ public enum Machine : ushort
/// ARM64
///
Arm64 = 0xAA64,
+
+ ///
+ /// LOONGARCH32
+ ///
+ LoongArch32 = 0x6232,
+
+ ///
+ /// LOONGARCH64
+ ///
+ LoongArch64 = 0x6264,
}
}
diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckArchitectureTests.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckArchitectureTests.cs
index 50c52fa853158f..6f1b289fd00eea 100644
--- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckArchitectureTests.cs
+++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckArchitectureTests.cs
@@ -40,6 +40,10 @@ public void VerifyArchitecture()
Assert.Equal(Architecture.S390x, processArch);
break;
+ case Architecture.LoongArch64:
+ Assert.Equal(Architecture.LoongArch64, processArch);
+ break;
+
default:
Assert.False(true, "Unexpected Architecture.");
break;
diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs
index 840ecbdff7ce8a..41c562ff9d5fef 100644
--- a/src/libraries/System.Runtime/ref/System.Runtime.cs
+++ b/src/libraries/System.Runtime/ref/System.Runtime.cs
@@ -13431,6 +13431,7 @@ public enum Architecture
Arm64 = 3,
Wasm = 4,
S390x = 5,
+ LoongArch64 = 6,
}
public enum CharSet
{
diff --git a/src/native/corehost/bundle/reader.h b/src/native/corehost/bundle/reader.h
index 576ecd04c8e0fe..b96934e537f011 100644
--- a/src/native/corehost/bundle/reader.h
+++ b/src/native/corehost/bundle/reader.h
@@ -17,6 +17,8 @@
#if defined(TARGET_ARM64)
#define TARGET_CPU_TYPE CPU_TYPE_ARM64
+#elif defined(TARGET_LOONGARCH64)
+#define TARGET_CPU_TYPE CPU_TYPE_LOONGARCH64
#else
#define TARGET_CPU_TYPE CPU_TYPE_X86_64
#endif
diff --git a/src/native/corehost/hostmisc/utils.cpp b/src/native/corehost/hostmisc/utils.cpp
index 21cc7e9c9b49ef..7f5fdbca40ab03 100644
--- a/src/native/corehost/hostmisc/utils.cpp
+++ b/src/native/corehost/hostmisc/utils.cpp
@@ -195,6 +195,8 @@ const pal::char_t* get_arch()
return _X("arm");
#elif defined(TARGET_ARM64)
return _X("arm64");
+#elif defined(TARGET_LOONGARCH64)
+ return _X("loongarch64");
#elif defined(TARGET_S390X)
return _X("s390x");
#else
diff --git a/src/native/eventpipe/ep-event-source.c b/src/native/eventpipe/ep-event-source.c
index 36eac2dcbbfc45..78d1c4852b991c 100644
--- a/src/native/eventpipe/ep-event-source.c
+++ b/src/native/eventpipe/ep-event-source.c
@@ -40,6 +40,8 @@ const ep_char8_t* _ep_arch_info = "arm32";
const ep_char8_t* _ep_arch_info = "arm64";
#elif defined(TARGET_S390X)
const ep_char8_t* _ep_arch_info = "s390x";
+#elif defined(TARGET_LOONGARCH64)
+const ep_char8_t* _ep_arch_info = "loongarch64";
#else
const ep_char8_t* _ep_arch_info = "Unknown";
#endif
diff --git a/src/native/libs/System.Native/pal_runtimeinformation.h b/src/native/libs/System.Native/pal_runtimeinformation.h
index 6b13077b1a730d..adae223d48339b 100644
--- a/src/native/libs/System.Native/pal_runtimeinformation.h
+++ b/src/native/libs/System.Native/pal_runtimeinformation.h
@@ -22,5 +22,6 @@ enum
ARCH_ARM,
ARCH_ARM64,
ARCH_WASM,
- ARCH_S390X
+ ARCH_S390X,
+ ARCH_LOONGARCH64
};