diff --git a/src/coreclr/interpreter/compiler.h b/src/coreclr/interpreter/compiler.h index 5349da7a98f082..6a534f1152c0dd 100644 --- a/src/coreclr/interpreter/compiler.h +++ b/src/coreclr/interpreter/compiler.h @@ -4,6 +4,7 @@ #ifndef _COMPILER_H_ #define _COMPILER_H_ +#include "static_assert.h" #include "intops.h" #include "datastructs.h" #include "enum_class_flags.h" @@ -150,15 +151,15 @@ class InterpDataItemIndexMap int32_t GetDataItemIndex(const InterpGenericLookup& lookup) { - size_t sizeOfFieldsConcatenated = sizeof(InterpGenericLookup::offsets) + + const size_t sizeOfFieldsConcatenated = sizeof(InterpGenericLookup::offsets) + sizeof(InterpGenericLookup::indirections) + sizeof(InterpGenericLookup::sizeOffset) + sizeof(InterpGenericLookup::lookupType) + sizeof(InterpGenericLookup::signature); - size_t sizeOfStruct = sizeof(InterpGenericLookup); + const size_t sizeOfStruct = sizeof(InterpGenericLookup); - assert(sizeOfFieldsConcatenated == sizeOfStruct); // Assert that there is no padding in the struct, so a fixed size hash unaware of padding is safe to use + static_assert_no_msg(sizeOfFieldsConcatenated == sizeOfStruct); // Assert that there is no padding in the struct, so a fixed size hash unaware of padding is safe to use return GetDataItemIndexForT(lookup); } @@ -539,8 +540,7 @@ class InterpCompiler dn_simdhash_ptr_ptr_holder m_pointerToNameMap; bool PointerInNameMap(void* ptr) { - void* result; - if (dn_simdhash_ptr_ptr_try_get_value(m_pointerToNameMap.GetValue(), ptr, &result)) + if (dn_simdhash_ptr_ptr_try_get_value(m_pointerToNameMap.GetValue(), ptr, NULL)) { return true; } @@ -548,10 +548,7 @@ class InterpCompiler } void AddPointerToNameMap(void* ptr, const char* name) { - if (!PointerInNameMap(ptr)) - { - dn_simdhash_ptr_ptr_try_add(m_pointerToNameMap.GetValue(), ptr, (void*)name); - } + dn_simdhash_ptr_ptr_try_add(m_pointerToNameMap.GetValue(), ptr, (void*)name); } void PrintNameInPointerMap(void* ptr); #endif @@ -850,9 +847,9 @@ int32_t InterpDataItemIndexMap::GetDataItemIndexForT(const T& lookup) } // Assert that there is no padding in the struct, so a fixed size hash unaware of padding is safe to use - assert(sizeof(VarSizedData) == sizeof(void*)); - assert(sizeof(T) % sizeof(void*) == 0); - assert(sizeof(VarSizedDataWithPayload) == sizeof(T) + sizeof(void*)); + static_assert_no_msg(sizeof(VarSizedData) == sizeof(void*)); + static_assert_no_msg(sizeof(T) % sizeof(void*) == 0); + static_assert_no_msg(sizeof(VarSizedDataWithPayload) == sizeof(T) + sizeof(void*)); void** LookupAsPtrs = (void**)&lookup; int32_t dataItemIndex = _dataItems->Add(LookupAsPtrs[0]); diff --git a/src/coreclr/vm/interpexec.cpp b/src/coreclr/vm/interpexec.cpp index 723deb9ca447ab..f8926d69369718 100644 --- a/src/coreclr/vm/interpexec.cpp +++ b/src/coreclr/vm/interpexec.cpp @@ -105,10 +105,10 @@ CallStubHeader *CreateNativeToInterpreterCallStub(InterpMethod* pInterpMethod) return pHeader; } -typedef void* (*HELPER_FTN_PP)(void*); +typedef void* (*HELPER_FTN_P_P)(void*); typedef void* (*HELPER_FTN_BOX_UNBOX)(MethodTable*, void*); typedef Object* (*HELPER_FTN_NEWARR)(MethodTable*, intptr_t); -typedef void* (*HELPER_FTN_PP_2)(void*, void*); +typedef void* (*HELPER_FTN_P_PP)(void*, void*); typedef void (*HELPER_FTN_V_PPP)(void*, void*, void*); @@ -362,10 +362,6 @@ void* DoGenericLookup(void* genericVarAsPtr, InterpGenericLookup* pLookup) return result; } -#define DO_GENERIC_LOOKUP(genericVar, lookupIndex) \ - InterpGenericLookup *pLookup = (InterpGenericLookup*)&pMethod->pDataItems[ip[lookupIndex]]; \ - void* result = DoGenericLookup(LOCAL_VAR(genericVar, void*), pLookup) - void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFrame *pFrame, InterpThreadContext *pThreadContext, ExceptionClauseArgs *pExceptionClauseArgs) { CONTRACTL @@ -1588,97 +1584,84 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr } case INTOP_CALL_HELPER_P_P: - case INTOP_CALL_HELPER_P_PP: { - int base = (*ip == INTOP_CALL_HELPER_P_P) ? 2 : 3; + HELPER_FTN_P_P helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[2]]); + void* helperArg = pMethod->pDataItems[ip[3]]; - HELPER_FTN_PP helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[base]]); - void* helperArg = pMethod->pDataItems[ip[base + 1]]; - - // This can call either native or compiled managed code. For an interpreter - // only configuration, this might be problematic, at least performance wise. + LOCAL_VAR(ip[1], void*) = helperFtn(helperArg); + ip += 4; + break; + } + case INTOP_CALL_HELPER_P_PP: + { + HELPER_FTN_P_PP helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[3]]); + void* helperArg = pMethod->pDataItems[ip[4]]; - if (*ip == INTOP_CALL_HELPER_P_P) - { - LOCAL_VAR(ip[1], void*) = ((HELPER_FTN_PP)helperFtn)(helperArg); - ip += 4; - } - else - { - LOCAL_VAR(ip[1], void*) = ((HELPER_FTN_PP_2)helperFtn)(helperArg, LOCAL_VAR(ip[2], void*)); - ip += 5; - } + LOCAL_VAR(ip[1], void*) = helperFtn(helperArg, LOCAL_VAR(ip[2], void*)); + ip += 5; break; } case INTOP_CALL_HELPER_P_G: - case INTOP_CALL_HELPER_P_GP: { - int base = (*ip == INTOP_CALL_HELPER_P_G) ? 3 : 4; + InterpGenericLookup *pLookup = (InterpGenericLookup*)&pMethod->pDataItems[ip[4]]; + void* helperArg = DoGenericLookup(LOCAL_VAR(ip[2], void*), pLookup); + + HELPER_FTN_P_P helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[3]]); - DO_GENERIC_LOOKUP(ip[2], base + 1); + LOCAL_VAR(ip[1], void*) = helperFtn(helperArg); + ip += 5; + break; + } - HELPER_FTN_PP helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[base]]); - void* helperArg = result; + case INTOP_CALL_HELPER_P_GP: + { + InterpGenericLookup *pLookup = (InterpGenericLookup*)&pMethod->pDataItems[ip[5]]; + void* helperArg = DoGenericLookup(LOCAL_VAR(ip[2], void*), pLookup); - // This can call either native or compiled managed code. For an interpreter - // only configuration, this might be problematic, at least performance wise. + HELPER_FTN_P_PP helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[4]]); - if (*ip == INTOP_CALL_HELPER_P_G) - { - LOCAL_VAR(ip[1], void*) = ((HELPER_FTN_PP)helperFtn)(helperArg); - ip += 5; - } - else - { - LOCAL_VAR(ip[1], void*) = ((HELPER_FTN_PP_2)helperFtn)(helperArg, LOCAL_VAR(ip[3], void*)); - ip += 6; - } + LOCAL_VAR(ip[1], void*) = helperFtn(helperArg, LOCAL_VAR(ip[3], void*)); + ip += 6; break; } case INTOP_CALL_HELPER_P_GA: { - int base = 4; - DO_GENERIC_LOOKUP(ip[2], base + 1); + InterpGenericLookup *pLookup = (InterpGenericLookup*)&pMethod->pDataItems[ip[5]]; + void* helperArg = DoGenericLookup(LOCAL_VAR(ip[2], void*), pLookup); - HELPER_FTN_PP helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[base]]); - void* helperArg = result; - LOCAL_VAR(ip[1], void*) = ((HELPER_FTN_PP_2)helperFtn)(helperArg, LOCAL_VAR_ADDR(ip[3], void*)); + HELPER_FTN_P_PP helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[4]]); + LOCAL_VAR(ip[1], void*) = helperFtn(helperArg, LOCAL_VAR_ADDR(ip[3], void*)); ip += 6; break; } case INTOP_CALL_HELPER_P_PA: { - int base = 3; - - HELPER_FTN_PP helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[base]]); - void* helperArg = pMethod->pDataItems[ip[base + 1]]; - LOCAL_VAR(ip[1], void*) = ((HELPER_FTN_PP_2)helperFtn)(helperArg, LOCAL_VAR_ADDR(ip[2], void*)); + HELPER_FTN_P_PP helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[3]]); + void* helperArg = pMethod->pDataItems[ip[4]]; + LOCAL_VAR(ip[1], void*) = helperFtn(helperArg, LOCAL_VAR_ADDR(ip[2], void*)); ip += 5; break; } case INTOP_CALL_HELPER_V_AGP: { - int base = 4; - DO_GENERIC_LOOKUP(ip[2], base + 1); + InterpGenericLookup *pLookup = (InterpGenericLookup*)&pMethod->pDataItems[ip[5]]; + void* helperArg = DoGenericLookup(LOCAL_VAR(ip[2], void*), pLookup); - HELPER_FTN_PP helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[base]]); - void* helperArg = result; - ((HELPER_FTN_V_PPP)helperFtn)(LOCAL_VAR_ADDR(ip[1], void*), helperArg, LOCAL_VAR(ip[3], void*)); + HELPER_FTN_V_PPP helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[4]]); + helperFtn(LOCAL_VAR_ADDR(ip[1], void*), helperArg, LOCAL_VAR(ip[3], void*)); ip += 6; break; } case INTOP_CALL_HELPER_V_APP: { - int base = 3; - - HELPER_FTN_PP helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[base]]); - void* helperArg = pMethod->pDataItems[ip[base + 1]]; - ((HELPER_FTN_V_PPP)helperFtn)(LOCAL_VAR_ADDR(ip[1], void*), helperArg, LOCAL_VAR(ip[2], void*)); + HELPER_FTN_V_PPP helperFtn = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[3]]); + void* helperArg = pMethod->pDataItems[ip[4]]; + helperFtn(LOCAL_VAR_ADDR(ip[1], void*), helperArg, LOCAL_VAR(ip[2], void*)); ip += 5; break; } @@ -1784,9 +1767,8 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr returnOffset = ip[1]; callArgsOffset = ip[2]; methodSlot = ip[4]; - DO_GENERIC_LOOKUP(ip[3], 5); - - MethodTable *pMTNewObj = (MethodTable*)result; // result comes from the generic lookup + InterpGenericLookup *pLookup = (InterpGenericLookup*)&pMethod->pDataItems[ip[5]]; + MethodTable *pMTNewObj = (MethodTable*)DoGenericLookup(LOCAL_VAR(ip[3], void*), pLookup); OBJECTREF objRef = AllocateObject(pMTNewObj); @@ -1822,8 +1804,9 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr } case INTOP_NEWMDARR_GENERIC: { - DO_GENERIC_LOOKUP(ip[3], 4); - MethodTable *pMTArray = (MethodTable*)result; // result comes from the generic lookup + InterpGenericLookup *pLookup = (InterpGenericLookup*)&pMethod->pDataItems[ip[4]]; + MethodTable *pMTArray = (MethodTable*)DoGenericLookup(LOCAL_VAR(ip[3], void*), pLookup); + LOCAL_VAR(ip[1], OBJECTREF) = CreateMultiDimArray(pMTArray, stack, ip[2], ip[5]); ip += 6; break; @@ -1933,8 +1916,9 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr int opcode = *ip; int dreg = ip[1]; int sreg = ip[3]; - DO_GENERIC_LOOKUP(ip[2], 5); - MethodTable *pMTBoxedObj = (MethodTable*)result; // result comes from the generic lookup + InterpGenericLookup *pLookup = (InterpGenericLookup*)&pMethod->pDataItems[ip[5]]; + MethodTable *pMTBoxedObj = (MethodTable*)DoGenericLookup(LOCAL_VAR(ip[2], void*), pLookup); + HELPER_FTN_BOX_UNBOX helper = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[4]]); // private static ref byte Unbox(MethodTable* toTypeHnd, object obj) @@ -1966,9 +1950,9 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr if (length < 0) COMPlusThrow(kArgumentOutOfRangeException); - DO_GENERIC_LOOKUP(ip[2], 5); + InterpGenericLookup *pLookup = (InterpGenericLookup*)&pMethod->pDataItems[ip[5]]; + MethodTable *arrayClsHnd = (MethodTable*)DoGenericLookup(LOCAL_VAR(ip[2], void*), pLookup); - MethodTable* arrayClsHnd = (MethodTable*)result; HELPER_FTN_NEWARR helper = GetPossiblyIndirectHelper(pMethod->pDataItems[ip[4]]); Object* arr = helper(arrayClsHnd, (intptr_t)length); @@ -2243,7 +2227,8 @@ do { \ case INTOP_GENERICLOOKUP: { int dreg = ip[1]; - DO_GENERIC_LOOKUP(ip[2], 3); + InterpGenericLookup *pLookup = (InterpGenericLookup*)&pMethod->pDataItems[ip[3]]; + void* result = DoGenericLookup(LOCAL_VAR(ip[2], void*), pLookup); LOCAL_VAR(dreg, void*) = result; ip += 4; break; diff --git a/src/native/containers/dn-simdhash-specialization-declarations.h b/src/native/containers/dn-simdhash-specialization-declarations.h index 047727ebb50f73..97dc6fe32d2310 100644 --- a/src/native/containers/dn-simdhash-specialization-declarations.h +++ b/src/native/containers/dn-simdhash-specialization-declarations.h @@ -58,9 +58,11 @@ DN_SIMDHASH_TRY_ADD (DN_SIMDHASH_T_PTR hash, DN_SIMDHASH_KEY_T key, DN_SIMDHASH_ uint8_t DN_SIMDHASH_TRY_ADD_WITH_HASH (DN_SIMDHASH_T_PTR hash, DN_SIMDHASH_KEY_T key, uint32_t key_hash, DN_SIMDHASH_VALUE_T value); +// result is an optional parameter that will be set to the value of the item if it was found. uint8_t DN_SIMDHASH_TRY_GET_VALUE (DN_SIMDHASH_T_PTR hash, DN_SIMDHASH_KEY_T key, DN_SIMDHASH_VALUE_T *result); +// result is an optional parameter that will be set to the value of the item if it was found. uint8_t DN_SIMDHASH_TRY_GET_VALUE_WITH_HASH (DN_SIMDHASH_T_PTR hash, DN_SIMDHASH_KEY_T key, uint32_t key_hash, DN_SIMDHASH_VALUE_T *result);