Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/coreclr/clrfeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,3 @@ endif()
# but that would be more expensive.
set(FEATURE_CORECLR_FLUSH_INSTRUCTION_CACHE_TO_PROTECT_STUB_READS 1)

if (CLR_CMAKE_HOST_UNIX AND CLR_CMAKE_HOST_ARCH_AMD64)
# Allow 16 byte compare-exchange (cmpxchg16b)
add_compile_options($<${FEATURE_CORECLR_CACHED_INTERFACE_DISPATCH}:-mcx16>)
endif()
10 changes: 10 additions & 0 deletions src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,20 @@

JITHELPER(CORINFO_HELP_GVMLOOKUP_FOR_SLOT, NULL, METHOD__NIL)
#ifdef FEATURE_RESOLVE_HELPER_DISPATCH
#if defined(FEATURE_CACHED_INTERFACE_DISPATCH)
// Set to RhpInterfaceDispatch when cached interface dispatch is used
DYNAMICJITHELPER(CORINFO_HELP_INTERFACEDISPATCH_FOR_SLOT, JIT_InterfaceDispatchForSlot, METHOD__NIL)
#else
JITHELPER(CORINFO_HELP_INTERFACEDISPATCH_FOR_SLOT, JIT_InterfaceDispatchForSlot, METHOD__NIL)
#endif
JITHELPER(CORINFO_HELP_INTERFACELOOKUP_FOR_SLOT, JIT_InterfaceLookupForSlot, METHOD__NIL)
#else
#if defined(FEATURE_CACHED_INTERFACE_DISPATCH) && !defined(TARGET_WASM)
// Set to RhpInterfaceDispatch when cached interface dispatch is used
DYNAMICJITHELPER(CORINFO_HELP_INTERFACEDISPATCH_FOR_SLOT, NULL, METHOD__NIL)
#else
JITHELPER(CORINFO_HELP_INTERFACEDISPATCH_FOR_SLOT, NULL, METHOD__NIL)
#endif
JITHELPER(CORINFO_HELP_INTERFACELOOKUP_FOR_SLOT, NULL, METHOD__NIL)
#endif

Expand Down
8 changes: 7 additions & 1 deletion src/coreclr/inc/readytorun.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// If you update this, ensure you run `git grep MINIMUM_READYTORUN_MAJOR_VERSION`
// and handle pending work.
#define READYTORUN_MAJOR_VERSION 34
#define READYTORUN_MINOR_VERSION 0x0001
#define READYTORUN_MINOR_VERSION 0x0002

#define MINIMUM_READYTORUN_MAJOR_VERSION 34

Expand Down Expand Up @@ -90,6 +90,9 @@
// only the return address, and the runtime preserves the callee-saved registers around the
// funclets that it calls
// R2R Version 34.1 adds AuxiliaryModuleMetadata sections
// R2R Version 34.2 adds READYTORUN_HELPER_InterfaceDispatch. Images compiled with cached interface dispatch support
// call it with the dispatch cell instead of calling through the cell, and lay out their dispatch
// cells as { MethodTable, Code, Token }.

struct READYTORUN_CORE_HEADER
{
Expand Down Expand Up @@ -539,6 +542,9 @@ enum ReadyToRunHelper
READYTORUN_HELPER_InitInstClass = 0x117,
READYTORUN_HELPER_R2RToInterpreter = 0x118,
READYTORUN_HELPER_WasmProfSamplepoint = 0x119,

// Interface dispatch through a cached interface dispatch cell passed in the VSD parameter register
READYTORUN_HELPER_InterfaceDispatch = 0x11A,
};

#include "readytoruninstructionset.h"
Expand Down
18 changes: 13 additions & 5 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7560,14 +7560,22 @@ GenTree* Lowering::LowerVirtualStubCall(GenTreeCall* call)
}

CORINFO_CONST_LOOKUP helperLookup = m_compiler->compGetHelperFtn(CORINFO_HELP_INTERFACEDISPATCH_FOR_SLOT);
assert(helperLookup.accessType == IAT_VALUE);
call->gtCallType = CT_USER_FUNC;
call->gtCallMethHnd = nullptr;
call->gtDirectCallAddress = helperLookup.addr;
call->gtCallType = CT_USER_FUNC;
call->gtCallMethHnd = Compiler::eeFindHelper(CORINFO_HELP_INTERFACEDISPATCH_FOR_SLOT);
call->gtFlags &= ~GTF_CALL_VIRT_STUB;
call->gtCallMoreFlags &= ~GTF_CALL_M_VIRTSTUB_REL_INDIRECT;

return nullptr;
if (helperLookup.accessType == IAT_VALUE)
{
call->gtDirectCallAddress = helperLookup.addr;
return nullptr;
}

// The helper is called through an indirection cell (e.g. ReadyToRun). The cell register
// holds the dispatch cell, so the helper address is loaded from its cell explicitly.
assert(helperLookup.accessType == IAT_PVALUE);
GenTree* helperCellAddr = AddrGen(helperLookup.addr);
return m_compiler->gtNewIndir(TYP_I_IMPL, helperCellAddr, GTF_IND_NONFAULTING);
}

// An x86 JIT which uses full stub dispatch must generate only
Expand Down
13 changes: 0 additions & 13 deletions src/coreclr/minipal/minipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,4 @@ class VMToOSInterface
static void AlignedFree(void* memblock);
};

#if defined(HOST_64BIT) && defined(FEATURE_CACHED_INTERFACE_DISPATCH)
EXTERN_C uint8_t _InterlockedCompareExchange128(int64_t volatile *, int64_t, int64_t, int64_t *);

#if defined(HOST_WINDOWS)
#pragma intrinsic(_InterlockedCompareExchange128)
#endif

FORCEINLINE uint8_t PalInterlockedCompareExchange128(_Inout_ int64_t volatile *pDst, int64_t iValueHigh, int64_t iValueLow, int64_t *pComparandAndResult)
{
return _InterlockedCompareExchange128(pDst, iValueHigh, iValueLow, pComparandAndResult);
}
#endif // defined(HOST_64BIT) && defined(FEATURE_CACHED_INTERFACE_DISPATCH)

#endif // CORECLR_MINIPAL_H
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ The .NET Foundation licenses this file to you under the MIT license.
<NativeSystemLibrary Include="log" Condition="'$(_linuxLibcFlavor)' == 'bionic'" />
<NativeSystemLibrary Include="icucore" Condition="'$(_IsApplePlatform)' == 'true'" />
<NativeSystemLibrary Include="m" />
<!-- See the comment in PalInterlockedCompareExchange128 for details. -->
<NativeSystemLibrary Include="atomic" Condition="'$(_targetArchitecture)' == 'riscv64' or '$(_targetArchitecture)' == 'loongarch64'" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct ReadyToRunHeaderConstants
static const uint32_t Signature = 0x00525452; // 'RTR'

static const uint32_t CurrentMajorVersion = 34;
static const uint32_t CurrentMinorVersion = 1;
static const uint32_t CurrentMinorVersion = 2;
};

struct ReadyToRunHeader
Expand Down
23 changes: 0 additions & 23 deletions src/coreclr/nativeaot/Runtime/unix/PalInline.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,6 @@ FORCEINLINE int64_t PalInterlockedCompareExchange64(_Inout_ int64_t volatile *pD
return result;
}

#if defined(HOST_64BIT)
FORCEINLINE uint8_t PalInterlockedCompareExchange128(_Inout_ int64_t volatile *pDst, int64_t iValueHigh, int64_t iValueLow, int64_t *pComparandAndResult)
{
__int128_t iComparand = ((__int128_t)pComparandAndResult[1] << 64) + (uint64_t)pComparandAndResult[0];

// TODO-LOONGARCH64: the 128-bit CAS is supported starting from the 3A6000 CPU (ISA1.1).
// When running on older hardware that doesn't support native CAS-128, the system falls back
// to a mutex-based approach via libatomic, which is not suitable for runtime requirements.
//
// TODO-RISCV64: double-check if libatomic's emulated CAS-128 works as expected once AOT applications are
// functional on linux-riscv64: https://github.com/dotnet/runtime/issues/106223.
// CAS-128 is natively supported starting with the Zacas extension in Linux 6.8; however, hardware support
// for RVA23 profile is not available at the time of writing.
//
// See https://github.com/dotnet/runtime/issues/109276.

__int128_t iResult = __sync_val_compare_and_swap((__int128_t volatile*)pDst, iComparand, ((__int128_t)iValueHigh << 64) + (uint64_t)iValueLow);
PalInterlockedOperationBarrier();
pComparandAndResult[0] = (int64_t)iResult; pComparandAndResult[1] = (int64_t)(iResult >> 64);
return iComparand == iResult;
}
#endif // HOST_64BIT

#ifdef HOST_64BIT

#define PalInterlockedExchangePointer(_pDst, _pValue) \
Expand Down
9 changes: 0 additions & 9 deletions src/coreclr/nativeaot/Runtime/windows/PalInline.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,6 @@ FORCEINLINE int64_t PalInterlockedIncrement64(_Inout_ int64_t volatile *pDst)
}
#endif // HOST_X86

#if defined(HOST_AMD64) || defined(HOST_ARM64)
EXTERN_C uint8_t _InterlockedCompareExchange128(int64_t volatile *, int64_t, int64_t, int64_t *);
#pragma intrinsic(_InterlockedCompareExchange128)
FORCEINLINE uint8_t PalInterlockedCompareExchange128(_Inout_ int64_t volatile *pDst, int64_t iValueHigh, int64_t iValueLow, int64_t *pComparandAndResult)
{
return _InterlockedCompareExchange128(pDst, iValueHigh, iValueLow, pComparandAndResult);
}
#endif // HOST_AMD64

#ifdef HOST_64BIT

EXTERN_C void * _InterlockedExchangePointer(void * volatile *, void *);
Expand Down
21 changes: 0 additions & 21 deletions src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2450,27 +2450,6 @@ Define_InterlockMethod(
((PVOID)(UINT_PTR)InterlockedCompareExchange((PLONG)(UINT_PTR)(Destination), (LONG)(UINT_PTR)(ExChange), (LONG)(UINT_PTR)(Comperand)))
#endif

#if defined(HOST_64BIT) && defined(FEATURE_CACHED_INTERFACE_DISPATCH)
FORCEINLINE uint8_t _InterlockedCompareExchange128(int64_t volatile *pDst, int64_t iValueHigh, int64_t iValueLow, int64_t *pComparandAndResult)
{
__int128_t iComparand = ((__int128_t)pComparandAndResult[1] << 64) + (uint64_t)pComparandAndResult[0];
// TODO-LOONGARCH64: the 128-bit CAS is supported starting from the 3A6000 CPU (ISA1.1).
// When running on older hardware that doesn't support native CAS-128, the system falls back
// to a mutex-based approach via libatomic, which is not suitable for runtime requirements.
//
// TODO-RISCV64: double-check if libatomic's emulated CAS-128 works as expected once AOT applications are
// functional on linux-riscv64: https://github.com/dotnet/runtime/issues/106223.
// CAS-128 is natively supported starting with the Zacas extension in Linux 6.8; however, hardware support
// for RVA23 profile is not available at the time of writing.
//
// See https://github.com/dotnet/runtime/issues/109276.
__int128_t iResult = __sync_val_compare_and_swap((__int128_t volatile*)pDst, iComparand, ((__int128_t)iValueHigh << 64) + (uint64_t)iValueLow);
PAL_InterlockedOperationBarrier();
pComparandAndResult[0] = (int64_t)iResult; pComparandAndResult[1] = (int64_t)(iResult >> 64);
return iComparand == iResult;
}
#endif

/*++
Function:
MemoryBarrier
Expand Down
Loading
Loading