From 286c43a716fd6382c1cbc730dcdd9b24705dde48 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Wed, 31 Jan 2018 10:59:35 -0600 Subject: [PATCH] Add Vector to CoreLib. This requires the runtime to change to recognize the Vector classes in either System.Numerics.Vectors.dll or in System.Private.CoreLib.dll. To do this, I added the [Intrinsic] attribute to Vector struct and Vector static class. --- src/mscorlib/Resources/Strings.resx | 62 ++++++++++++---------- src/mscorlib/System.Private.CoreLib.csproj | 20 +++++++ .../shared/System.Private.CoreLib.Shared.projitems | 32 +++++++++++ src/mscorlib/shared/System/Numerics/Vector.cs | 2 + src/mscorlib/shared/System/Numerics/Vector.tt | 2 + .../Runtime/CompilerServices/IntrinsicAttribute.cs | 2 +- src/vm/jitinterface.cpp | 16 +++++- src/vm/methodtablebuilder.cpp | 5 +- src/vm/methodtablebuilder.h | 3 +- 9 files changed, 111 insertions(+), 33 deletions(-) diff --git a/src/mscorlib/Resources/Strings.resx b/src/mscorlib/Resources/Strings.resx index 585cbc7..2b66ce5 100644 --- a/src/mscorlib/Resources/Strings.resx +++ b/src/mscorlib/Resources/Strings.resx @@ -1,17 +1,17 @@  - @@ -3700,4 +3700,10 @@ The read operation returned an invalid length. - + + Number of elements in source vector is greater than the destination array + + + The method was called with a null array argument. + + \ No newline at end of file diff --git a/src/mscorlib/System.Private.CoreLib.csproj b/src/mscorlib/System.Private.CoreLib.csproj index df394ed..6c08a12 100644 --- a/src/mscorlib/System.Private.CoreLib.csproj +++ b/src/mscorlib/System.Private.CoreLib.csproj @@ -596,6 +596,26 @@ + + + + TextTemplatingFileGenerator + ConstantHelper.cs + + + + TextTemplatingFileGenerator + Register.cs + + + TextTemplatingFileGenerator + Vector.cs + + diff --git a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems index bb1a284..26b0ba6 100644 --- a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems @@ -621,6 +621,38 @@ + + + True + True + ConstantHelper.tt + + + TextTemplatingFileGenerator + ConstantHelper.cs + + + + + True + True + Register.tt + + + TextTemplatingFileGenerator + Register.cs + + + True + True + Vector.tt + + + TextTemplatingFileGenerator + Vector.cs + + + diff --git a/src/mscorlib/shared/System/Numerics/Vector.cs b/src/mscorlib/shared/System/Numerics/Vector.cs index 984f82f..5fd2867 100644 --- a/src/mscorlib/shared/System/Numerics/Vector.cs +++ b/src/mscorlib/shared/System/Numerics/Vector.cs @@ -38,6 +38,7 @@ namespace System.Numerics /// This struct only supports numerical types. This type is intended to be used as a building block for vectorizing /// large algorithms. This type is immutable, individual elements cannot be modified. /// + [Intrinsic] public struct Vector : IEquatable>, IFormattable where T : struct { #region Fields @@ -4953,6 +4954,7 @@ namespace System.Numerics #endregion } + [Intrinsic] public static partial class Vector { #region Widen/Narrow diff --git a/src/mscorlib/shared/System/Numerics/Vector.tt b/src/mscorlib/shared/System/Numerics/Vector.tt index 84e57b0..82aa73d 100644 --- a/src/mscorlib/shared/System/Numerics/Vector.tt +++ b/src/mscorlib/shared/System/Numerics/Vector.tt @@ -43,6 +43,7 @@ namespace System.Numerics /// This struct only supports numerical types. This type is intended to be used as a building block for vectorizing /// large algorithms. This type is immutable, individual elements cannot be modified. /// + [Intrinsic] public struct Vector : IEquatable>, IFormattable where T : struct { #region Fields @@ -1681,6 +1682,7 @@ namespace System.Numerics #endregion } + [Intrinsic] public static partial class Vector { #region Widen/Narrow diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/IntrinsicAttribute.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/IntrinsicAttribute.cs index 381b4c6..bb73946 100644 --- a/src/mscorlib/shared/System/Runtime/CompilerServices/IntrinsicAttribute.cs +++ b/src/mscorlib/shared/System/Runtime/CompilerServices/IntrinsicAttribute.cs @@ -7,7 +7,7 @@ namespace System.Runtime.CompilerServices // Calls to methods or references to fields marked with this attribute may be replaced at // some call sites with jit intrinsic expansions. // Types marked with this attribute may be specially treated by the rumtime/compiler. - [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Field, Inherited = false)] + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Field, Inherited = false)] internal sealed class IntrinsicAttribute : Attribute { } diff --git a/src/vm/jitinterface.cpp b/src/vm/jitinterface.cpp index a5981d3..0fb8ea6 100644 --- a/src/vm/jitinterface.cpp +++ b/src/vm/jitinterface.cpp @@ -8689,6 +8689,7 @@ CorInfoIntrinsics CEEInfo::getIntrinsicID(CORINFO_METHOD_HANDLE methodHnd, } /*********************************************************************/ +// This method should probably be renamed to something like "isSIMDType" bool CEEInfo::isInSIMDModule(CORINFO_CLASS_HANDLE classHnd) { CONTRACTL { @@ -8702,10 +8703,23 @@ CONTRACTL { JIT_TO_EE_TRANSITION_LEAF(); TypeHandle VMClsHnd(classHnd); - if (VMClsHnd.GetMethodTable()->GetAssembly()->IsSIMDVectorAssembly()) + PTR_MethodTable methodTable = VMClsHnd.GetMethodTable(); + if (methodTable->GetAssembly()->IsSIMDVectorAssembly()) { result = true; } + else if (methodTable->IsIntrinsicType()) + { + LPCUTF8 namespaceName; + LPCUTF8 className = methodTable->GetFullyQualifiedNameInfo(&namespaceName); + + if (strcmp(className, "Vector`1") == 0 || strcmp(className, "Vector") == 0) + { + assert(strcmp(namespaceName, "System.Numerics") == 0); + + result = true; + } + } EE_TO_JIT_TRANSITION_LEAF(); return result; diff --git a/src/vm/methodtablebuilder.cpp b/src/vm/methodtablebuilder.cpp index 1d58704..dce3e3c 100644 --- a/src/vm/methodtablebuilder.cpp +++ b/src/vm/methodtablebuilder.cpp @@ -1170,7 +1170,7 @@ BOOL MethodTableBuilder::CheckIfSIMDAndUpdateSize() STANDARD_VM_CONTRACT; #if defined(_TARGET_X86_) || defined(_TARGET_AMD64_) - if (!GetAssembly()->IsSIMDVectorAssembly()) + if (!(GetAssembly()->IsSIMDVectorAssembly() || GetModule()->IsSystem())) return false; if (bmtFP->NumInstanceFieldBytes != 16) @@ -10432,7 +10432,8 @@ MethodTableBuilder::SetupMethodTable2( // Currently, only SIMD types have [Intrinsic] attribute // // We check this here fairly early to ensure other downstream checks on these types can be slightly more efficient. - if ((GetModule()->IsSystem() || GetAssembly()->IsSIMDVectorAssembly()) && IsValueClass() && bmtGenerics->HasInstantiation()) + if ((GetModule()->IsSystem() || GetAssembly()->IsSIMDVectorAssembly()) && + ((IsValueClass() && bmtGenerics->HasInstantiation()) || (IsAbstract() && IsSealed()))) { HRESULT hr = GetMDImport()->GetCustomAttributeByName(bmtInternal->pType->GetTypeDefToken(), g_CompilerServicesIntrinsicAttribute, diff --git a/src/vm/methodtablebuilder.h b/src/vm/methodtablebuilder.h index d736368..1d10904 100644 --- a/src/vm/methodtablebuilder.h +++ b/src/vm/methodtablebuilder.h @@ -218,7 +218,8 @@ private: BOOL HasNonPublicFields() { WRAPPER_NO_CONTRACT; return GetHalfBakedClass()->HasNonPublicFields(); } BOOL IsValueClass() { WRAPPER_NO_CONTRACT; return bmtProp->fIsValueClass; } BOOL IsUnsafeValueClass() { WRAPPER_NO_CONTRACT; return GetHalfBakedClass()->IsUnsafeValueClass(); } - BOOL IsAbstract() { WRAPPER_NO_CONTRACT; return GetHalfBakedClass()->IsAbstract(); } + BOOL IsAbstract() { WRAPPER_NO_CONTRACT; return GetHalfBakedClass()->IsAbstract(); } + BOOL IsSealed() { WRAPPER_NO_CONTRACT; return GetHalfBakedClass()->IsSealed(); } BOOL HasLayout() { WRAPPER_NO_CONTRACT; return GetHalfBakedClass()->HasLayout(); } BOOL IsDelegate() { WRAPPER_NO_CONTRACT; return GetHalfBakedClass()->IsDelegate(); } BOOL IsNested() { WRAPPER_NO_CONTRACT; return GetHalfBakedClass()->IsNested(); } -- 2.7.4