Skip to content

Commit

Permalink
Updating the JIT to recognize and handle Vector64/128/256<T> for nint…
Browse files Browse the repository at this point in the history
…/nuint (#52016)

* Updating the JIT to recognize and handle Vector64/128/256<T> for nint/nuint

* Update src/coreclr/jit/simd.cpp

Co-authored-by: Anton Lapounov <[email protected]>

* Applying formatting patch

* Updating the VM to treat Vector<nint> and Vector<nuint> as vector types

Co-authored-by: Anton Lapounov <[email protected]>
  • Loading branch information
tannergooding and AntonLapounov authored Apr 30, 2021
1 parent d2dff5d commit a4ba77a
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8297,6 +8297,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
CORINFO_CLASS_HANDLE Vector64LongHandle;
CORINFO_CLASS_HANDLE Vector64UIntHandle;
CORINFO_CLASS_HANDLE Vector64ULongHandle;
CORINFO_CLASS_HANDLE Vector64NIntHandle;
CORINFO_CLASS_HANDLE Vector64NUIntHandle;
#endif // defined(TARGET_ARM64)
CORINFO_CLASS_HANDLE Vector128FloatHandle;
CORINFO_CLASS_HANDLE Vector128DoubleHandle;
Expand All @@ -8308,6 +8310,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
CORINFO_CLASS_HANDLE Vector128LongHandle;
CORINFO_CLASS_HANDLE Vector128UIntHandle;
CORINFO_CLASS_HANDLE Vector128ULongHandle;
CORINFO_CLASS_HANDLE Vector128NIntHandle;
CORINFO_CLASS_HANDLE Vector128NUIntHandle;
#if defined(TARGET_XARCH)
CORINFO_CLASS_HANDLE Vector256FloatHandle;
CORINFO_CLASS_HANDLE Vector256DoubleHandle;
Expand All @@ -8319,6 +8323,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
CORINFO_CLASS_HANDLE Vector256LongHandle;
CORINFO_CLASS_HANDLE Vector256UIntHandle;
CORINFO_CLASS_HANDLE Vector256ULongHandle;
CORINFO_CLASS_HANDLE Vector256NIntHandle;
CORINFO_CLASS_HANDLE Vector256NUIntHandle;
#endif // defined(TARGET_XARCH)
#endif // FEATURE_HW_INTRINSICS

Expand Down
12 changes: 12 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17601,6 +17601,12 @@ GenTree* Compiler::gtGetSIMDZero(var_types simdType, CorInfoType simdBaseJitType
case CORINFO_TYPE_ULONG:
assert(simdHandle == m_simdHandleCache->Vector128ULongHandle);
break;
case CORINFO_TYPE_NATIVEINT:
assert(simdHandle == m_simdHandleCache->Vector128NIntHandle);
break;
case CORINFO_TYPE_NATIVEUINT:
assert(simdHandle == m_simdHandleCache->Vector128NUIntHandle);
break;
#endif // defined(FEATURE_HW_INTRINSICS)

default:
Expand Down Expand Up @@ -17642,6 +17648,12 @@ GenTree* Compiler::gtGetSIMDZero(var_types simdType, CorInfoType simdBaseJitType
case CORINFO_TYPE_ULONG:
assert(simdHandle == m_simdHandleCache->Vector256ULongHandle);
break;
case CORINFO_TYPE_NATIVEINT:
assert(simdHandle == m_simdHandleCache->Vector256NIntHandle);
break;
case CORINFO_TYPE_NATIVEUINT:
assert(simdHandle == m_simdHandleCache->Vector256NUIntHandle);
break;
default:
break;
}
Expand Down
18 changes: 12 additions & 6 deletions src/coreclr/jit/hwintrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ CORINFO_CLASS_HANDLE Compiler::gtGetStructHandleForHWSIMD(var_types simdType, Co
case CORINFO_TYPE_ULONG:
return m_simdHandleCache->Vector128ULongHandle;
case CORINFO_TYPE_NATIVEINT:
break;
return m_simdHandleCache->Vector128NIntHandle;
case CORINFO_TYPE_NATIVEUINT:
break;
return m_simdHandleCache->Vector128NUIntHandle;
default:
assert(!"Didn't find a class handle for simdType");
}
Expand Down Expand Up @@ -150,9 +150,9 @@ CORINFO_CLASS_HANDLE Compiler::gtGetStructHandleForHWSIMD(var_types simdType, Co
case CORINFO_TYPE_ULONG:
return m_simdHandleCache->Vector256ULongHandle;
case CORINFO_TYPE_NATIVEINT:
break;
return m_simdHandleCache->Vector256NIntHandle;
case CORINFO_TYPE_NATIVEUINT:
break;
return m_simdHandleCache->Vector256NUIntHandle;
default:
assert(!"Didn't find a class handle for simdType");
}
Expand Down Expand Up @@ -184,9 +184,9 @@ CORINFO_CLASS_HANDLE Compiler::gtGetStructHandleForHWSIMD(var_types simdType, Co
case CORINFO_TYPE_ULONG:
return m_simdHandleCache->Vector64ULongHandle;
case CORINFO_TYPE_NATIVEINT:
break;
return m_simdHandleCache->Vector64NIntHandle;
case CORINFO_TYPE_NATIVEUINT:
break;
return m_simdHandleCache->Vector64NUIntHandle;
default:
assert(!"Didn't find a class handle for simdType");
}
Expand Down Expand Up @@ -666,6 +666,12 @@ static bool isSupportedBaseType(NamedIntrinsic intrinsic, CorInfoType baseJitTyp
return false;
}

if ((baseJitType == CORINFO_TYPE_NATIVEINT) || (baseJitType == CORINFO_TYPE_NATIVEUINT))
{
// We don't want to support the general purpose helpers for nint/nuint until after they go through API review.
return false;
}

var_types baseType = JitType2PreciseVarType(baseJitType);

// We don't actually check the intrinsic outside of the false case as we expect
Expand Down
66 changes: 66 additions & 0 deletions src/coreclr/jit/simd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,18 @@ CorInfoType Compiler::getBaseJitTypeAndSizeOfSIMDType(CORINFO_CLASS_HANDLE typeH
size = Vector256SizeBytes;
JITDUMP(" Known type Vector256<ulong>\n");
}
else if (typeHnd == m_simdHandleCache->Vector256NIntHandle)
{
simdBaseJitType = CORINFO_TYPE_NATIVEINT;
size = Vector256SizeBytes;
JITDUMP(" Known type Vector256<nint>\n");
}
else if (typeHnd == m_simdHandleCache->Vector256NUIntHandle)
{
simdBaseJitType = CORINFO_TYPE_NATIVEUINT;
size = Vector256SizeBytes;
JITDUMP(" Known type Vector256<nuint>\n");
}
else
#endif // defined(TARGET_XARCH)
if (typeHnd == m_simdHandleCache->Vector128FloatHandle)
Expand Down Expand Up @@ -531,6 +543,18 @@ CorInfoType Compiler::getBaseJitTypeAndSizeOfSIMDType(CORINFO_CLASS_HANDLE typeH
size = Vector128SizeBytes;
JITDUMP(" Known type Vector128<ulong>\n");
}
else if (typeHnd == m_simdHandleCache->Vector128NIntHandle)
{
simdBaseJitType = CORINFO_TYPE_NATIVEINT;
size = Vector128SizeBytes;
JITDUMP(" Known type Vector128<nint>\n");
}
else if (typeHnd == m_simdHandleCache->Vector128NUIntHandle)
{
simdBaseJitType = CORINFO_TYPE_NATIVEUINT;
size = Vector128SizeBytes;
JITDUMP(" Known type Vector128<nuint>\n");
}
else
#if defined(TARGET_ARM64)
if (typeHnd == m_simdHandleCache->Vector64FloatHandle)
Expand Down Expand Up @@ -593,6 +617,18 @@ CorInfoType Compiler::getBaseJitTypeAndSizeOfSIMDType(CORINFO_CLASS_HANDLE typeH
size = Vector64SizeBytes;
JITDUMP(" Known type Vector64<ulong>\n");
}
else if (typeHnd == m_simdHandleCache->Vector64NIntHandle)
{
simdBaseJitType = CORINFO_TYPE_NATIVEINT;
size = Vector64SizeBytes;
JITDUMP(" Known type Vector64<nint>\n");
}
else if (typeHnd == m_simdHandleCache->Vector64NUIntHandle)
{
simdBaseJitType = CORINFO_TYPE_NATIVEUINT;
size = Vector64SizeBytes;
JITDUMP(" Known type Vector64<nuint>\n");
}
#endif // defined(TARGET_ARM64)

// slow path search
Expand Down Expand Up @@ -665,6 +701,16 @@ CorInfoType Compiler::getBaseJitTypeAndSizeOfSIMDType(CORINFO_CLASS_HANDLE typeH
simdBaseJitType = CORINFO_TYPE_BYTE;
JITDUMP(" Found type Hardware Intrinsic SIMD Vector256<sbyte>\n");
break;
case CORINFO_TYPE_NATIVEINT:
m_simdHandleCache->Vector256NIntHandle = typeHnd;
simdBaseJitType = CORINFO_TYPE_NATIVEINT;
JITDUMP(" Found type Hardware Intrinsic SIMD Vector256<nint>\n");
break;
case CORINFO_TYPE_NATIVEUINT:
m_simdHandleCache->Vector256NUIntHandle = typeHnd;
simdBaseJitType = CORINFO_TYPE_NATIVEUINT;
JITDUMP(" Found type Hardware Intrinsic SIMD Vector256<nuint>\n");
break;

default:
JITDUMP(" Unknown Hardware Intrinsic SIMD Type Vector256<T>\n");
Expand Down Expand Up @@ -727,6 +773,16 @@ CorInfoType Compiler::getBaseJitTypeAndSizeOfSIMDType(CORINFO_CLASS_HANDLE typeH
simdBaseJitType = CORINFO_TYPE_BYTE;
JITDUMP(" Found type Hardware Intrinsic SIMD Vector128<sbyte>\n");
break;
case CORINFO_TYPE_NATIVEINT:
m_simdHandleCache->Vector128NIntHandle = typeHnd;
simdBaseJitType = CORINFO_TYPE_NATIVEINT;
JITDUMP(" Found type Hardware Intrinsic SIMD Vector128<nint>\n");
break;
case CORINFO_TYPE_NATIVEUINT:
m_simdHandleCache->Vector128NUIntHandle = typeHnd;
simdBaseJitType = CORINFO_TYPE_NATIVEUINT;
JITDUMP(" Found type Hardware Intrinsic SIMD Vector128<nuint>\n");
break;

default:
JITDUMP(" Unknown Hardware Intrinsic SIMD Type Vector128<T>\n");
Expand Down Expand Up @@ -788,6 +844,16 @@ CorInfoType Compiler::getBaseJitTypeAndSizeOfSIMDType(CORINFO_CLASS_HANDLE typeH
simdBaseJitType = CORINFO_TYPE_BYTE;
JITDUMP(" Found type Hardware Intrinsic SIMD Vector64<sbyte>\n");
break;
case CORINFO_TYPE_NATIVEINT:
m_simdHandleCache->Vector64NIntHandle = typeHnd;
simdBaseJitType = CORINFO_TYPE_NATIVEINT;
JITDUMP(" Found type Hardware Intrinsic SIMD Vector64<nint>\n");
break;
case CORINFO_TYPE_NATIVEUINT:
m_simdHandleCache->Vector64NUIntHandle = typeHnd;
simdBaseJitType = CORINFO_TYPE_NATIVEUINT;
JITDUMP(" Found type Hardware Intrinsic SIMD Vector64<nuint>\n");
break;

default:
JITDUMP(" Unknown Hardware Intrinsic SIMD Type Vector64<T>\n");
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/tools/Common/TypeSystem/Common/TypeDesc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ public bool IsPrimitiveNumeric
case TypeFlags.UInt32:
case TypeFlags.Int64:
case TypeFlags.UInt64:
case TypeFlags.IntPtr:
case TypeFlags.UIntPtr:
case TypeFlags.Single:
case TypeFlags.Double:
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ int MethodTable::GetVectorSize()
// We need to verify that T (the element or "base" type) is a primitive type.
TypeHandle typeArg = GetInstantiation()[0];
CorElementType corType = typeArg.GetSignatureCorElementType();
if (corType >= ELEMENT_TYPE_I1 && corType <= ELEMENT_TYPE_R8)
if (((corType >= ELEMENT_TYPE_I1) && (corType <= ELEMENT_TYPE_R8)) || (corType == ELEMENT_TYPE_I) || (corType == ELEMENT_TYPE_U))
{
_ASSERTE(strcmp(namespaceName, "System.Runtime.Intrinsics") == 0);
return vectorSize;
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4384,6 +4384,12 @@ CorInfoType CEEInfo::getTypeForPrimitiveNumericClass(
case ELEMENT_TYPE_R8:
result = CORINFO_TYPE_DOUBLE;
break;
case ELEMENT_TYPE_I:
result = CORINFO_TYPE_NATIVEINT;
break;
case ELEMENT_TYPE_U:
result = CORINFO_TYPE_NATIVEUINT;
break;

default:
// Error case, we will return CORINFO_TYPE_UNDEF
Expand Down

0 comments on commit a4ba77a

Please sign in to comment.