@@ -94,21 +94,28 @@ FORCEINLINE int64_t PalInterlockedCompareExchange64(_Inout_ int64_t volatile *pD
94
94
return result ;
95
95
}
96
96
97
- #if defined(HOST_AMD64 ) || defined( HOST_ARM64 ) || defined( HOST_LOONGARCH64 ) || defined( HOST_RISCV64 )
97
+ #if defined(HOST_64BIT )
98
98
FORCEINLINE uint8_t PalInterlockedCompareExchange128 (_Inout_ int64_t volatile * pDst , int64_t iValueHigh , int64_t iValueLow , int64_t * pComparandAndResult )
99
99
{
100
100
__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
+
106
113
__int128_t iResult = __sync_val_compare_and_swap ((__int128_t volatile * )pDst , iComparand , ((__int128_t )iValueHigh << 64 ) + (uint64_t )iValueLow );
107
114
PalInterlockedOperationBarrier ();
108
115
pComparandAndResult [0 ] = (int64_t )iResult ; pComparandAndResult [1 ] = (int64_t )(iResult >> 64 );
109
116
return iComparand == iResult ;
110
117
}
111
- #endif // HOST_AMD64 || HOST_ARM64 || HOST_LOONGARCH64 || HOST_RISCV64
118
+ #endif // HOST_64BIT
112
119
113
120
#ifdef HOST_64BIT
114
121
0 commit comments