Skip to content

Commit 070c3ba

Browse files
committed
Combine TODO comments related to CAS-128
1 parent 622a48e commit 070c3ba

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,7 @@ The .NET Foundation licenses this file to you under the MIT license.
221221
<NativeSystemLibrary Include="log" Condition="'$(_linuxLibcFlavor)' == 'bionic'" />
222222
<NativeSystemLibrary Include="icucore" Condition="'$(_IsApplePlatform)' == 'true'" />
223223
<NativeSystemLibrary Include="m" />
224-
<!--
225-
TODO: Double-check if libatomic's emulated CAS-128 works as expected once AOT applications are
226-
functional on linux-riscv64: https://github.com/dotnet/runtime/issues/106223.
227-
CAS-128 is natively supported starting with the Zacas extension in Linux 6.8; however, hardware support
228-
for RVA23 profile is not available at the time of writing.
229-
-->
224+
<!-- See the comment in PalInterlockedCompareExchange128 for details. -->
230225
<NativeSystemLibrary Include="atomic" Condition="'$(_targetArchitecture)' == 'riscv64'" />
231226
</ItemGroup>
232227

src/coreclr/nativeaot/Runtime/unix/PalRedhawkInline.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,28 @@ FORCEINLINE int64_t PalInterlockedCompareExchange64(_Inout_ int64_t volatile *pD
9494
return result;
9595
}
9696

97-
#if defined(HOST_AMD64) || defined(HOST_ARM64) || defined(HOST_LOONGARCH64) || defined(HOST_RISCV64)
97+
#if defined(HOST_64BIT)
9898
FORCEINLINE uint8_t PalInterlockedCompareExchange128(_Inout_ int64_t volatile *pDst, int64_t iValueHigh, int64_t iValueLow, int64_t *pComparandAndResult)
9999
{
100100
__int128_t iComparand = ((__int128_t)pComparandAndResult[1] << 64) + (uint64_t)pComparandAndResult[0];
101-
// TODO-LOONGARCH64: for LoongArch64, it supports 128bits atomic from 3A6000-CPU which is ISA1.1's version.
102-
// The LA64's compiler will translate the `__sync_val_compare_and_swap` into calling the libatomic's library interface to emulate
103-
// the 128-bit CAS by mutex_lock if the target processor doesn't support the ISA1.1.
104-
// But this emulation by libatomic doesn't satisfy requirements here which it must update two adjacent pointers atomically.
105-
// this is being discussed in https://github.com/dotnet/runtime/issues/109276.
101+
102+
// TODO-LOONGARCH64: For LoongArch64, the 128-bit CAS is supported starting from the 3A6000 CPU (ISA1.1).
103+
// When running on older hardware that doesn't support native CAS-128, the system falls back
104+
// to a mutex-based approach via libatomic, which is not suitable for runtime requirements.
105+
//
106+
// TODO-RISCV64: Double-check if libatomic's emulated CAS-128 works as expected once AOT applications are
107+
// functional on linux-riscv64: https://github.com/dotnet/runtime/issues/106223.
108+
// CAS-128 is natively supported starting with the Zacas extension in Linux 6.8; however, hardware support
109+
// for RVA23 profile is not available at the time of writing.
110+
//
111+
// See https://github.com/dotnet/runtime/issues/109276.
112+
106113
__int128_t iResult = __sync_val_compare_and_swap((__int128_t volatile*)pDst, iComparand, ((__int128_t)iValueHigh << 64) + (uint64_t)iValueLow);
107114
PalInterlockedOperationBarrier();
108115
pComparandAndResult[0] = (int64_t)iResult; pComparandAndResult[1] = (int64_t)(iResult >> 64);
109116
return iComparand == iResult;
110117
}
111-
#endif // HOST_AMD64 || HOST_ARM64 || HOST_LOONGARCH64 || HOST_RISCV64
118+
#endif // HOST_64BIT
112119

113120
#ifdef HOST_64BIT
114121

0 commit comments

Comments
 (0)