Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Fix SIMD intrinsics handling in crossgen2 (#27853)
Browse files Browse the repository at this point in the history
* Fix SIMD intrinsics handling in crossgen2

Crossgen2 was compiling methods that call SIMD intrinsics
(System.Numerics.Vector<T>). This is not correct, as the size of the
vector is a runtime specific detail - e.g. when running on devices
without SSE2 support, the size is 4 and when running on devices with
SSE2 support, the size is 8.
This fixes runtime errors in 6 coreclr pri 0 tests.

* Reflect PR feedback

Create a IsVectorOfT method and use it at all places where we were
previously checking the namespace and type name of Vector<T>
  • Loading branch information
janvorli authored Nov 13, 2019
1 parent 0812430 commit 0f9814c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,10 @@ public static bool IsVectorType(DefType type)
type.Name == "Vector128`1" ||
type.Name == "Vector256`1");
}

public static bool IsVectorOfTType(DefType type)
{
return type.IsIntrinsic && type.Namespace == "System.Numerics" && type.Name == "Vector`1";
}
}
}
9 changes: 9 additions & 0 deletions src/tools/crossgen2/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,15 @@ private uint getMethodAttribsInternal(MethodDesc method)
result |= CorInfoFlag.CORINFO_FLG_FINAL;
}

#if READYTORUN
// Check for SIMD intrinsics
DefType owningDefType = method.OwningType as DefType;
if (owningDefType != null && VectorFieldLayoutAlgorithm.IsVectorOfTType(owningDefType))
{
throw new RequiresRuntimeJitException("This function is using SIMD intrinsics, their size is machine specific");
}
#endif

// Check for hardware intrinsics
if (HardwareIntrinsicHelpers.IsHardwareIntrinsic(method))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using ILCompiler;
using Internal.TypeSystem;

namespace Internal.JitInterface
Expand Down Expand Up @@ -261,16 +262,8 @@ private static bool ClassifyEightBytes(TypeDesc typeDesc,
InstantiatedType instantiatedType = typeDesc as InstantiatedType;
if (instantiatedType != null)
{
string typeName = instantiatedType.Name;
string namespaceName = instantiatedType.Namespace;

if (typeName == "Vector256`1" || typeName == "Vector128`1" || typeName == "Vector64`1")
{
Debug.Assert(namespaceName == "System.Runtime.Intrinsics");
return false;
}

if ((typeName == "Vector`1") && (namespaceName == "System.Numerics"))
if (VectorFieldLayoutAlgorithm.IsVectorType(instantiatedType) ||
VectorFieldLayoutAlgorithm.IsVectorOfTType(instantiatedType))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override FieldLayoutAlgorithm GetLayoutAlgorithmForType(DefType type)
throw new NotImplementedException();
else if (type.IsRuntimeDeterminedType)
throw new NotImplementedException();
else if (type.IsIntrinsic && (type.Name == "Vector`1") && (type.Namespace == "System.Numerics"))
else if (VectorIntrinsicFieldLayoutAlgorithm.IsVectorOfTType(type))
{
return _vectorFieldLayoutAlgorithm;
}
Expand Down

0 comments on commit 0f9814c

Please sign in to comment.