Skip to content

Commit

Permalink
Rewrite how Matrix3x2 and Matrix4x4 are implemented (#80091)
Browse files Browse the repository at this point in the history
* Rewrite how Matrix3x2 and Matrix4x4 are implemented

* Fix a bug in lowerxarch related to merging Sse41.Insert chains
  • Loading branch information
tannergooding committed Jan 7, 2023
1 parent 7a6f33b commit f8218f9
Show file tree
Hide file tree
Showing 9 changed files with 2,391 additions and 2,360 deletions.
23 changes: 20 additions & 3 deletions src/coreclr/jit/lowerxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2809,6 +2809,9 @@ GenTree* Lowering::LowerHWIntrinsicCreate(GenTreeHWIntrinsic* node)

if (comp->compOpportunisticallyDependsOn(InstructionSet_SSE41))
{
assert(argCnt <= 4);
GenTree* insertedNodes[4];

for (N = 1; N < argCnt - 1; N++)
{
// We will be constructing the following parts:
Expand Down Expand Up @@ -2837,10 +2840,12 @@ GenTree* Lowering::LowerHWIntrinsicCreate(GenTreeHWIntrinsic* node)
idx = comp->gtNewIconNode(N << 4, TYP_INT);
BlockRange().InsertAfter(tmp2, idx);

tmp1 = comp->gtNewSimdHWIntrinsicNode(simdType, tmp1, tmp2, idx, NI_SSE41_Insert, simdBaseJitType,
tmp3 = comp->gtNewSimdHWIntrinsicNode(simdType, tmp1, tmp2, idx, NI_SSE41_Insert, simdBaseJitType,
simdSize);
BlockRange().InsertAfter(idx, tmp1);
LowerNode(tmp1);
BlockRange().InsertAfter(idx, tmp3);

insertedNodes[N] = tmp3;
tmp1 = tmp3;
}

// We will be constructing the following parts:
Expand Down Expand Up @@ -2868,6 +2873,18 @@ GenTree* Lowering::LowerHWIntrinsicCreate(GenTreeHWIntrinsic* node)
BlockRange().InsertAfter(tmp2, idx);

node->ResetHWIntrinsicId(NI_SSE41_Insert, comp, tmp1, tmp2, idx);

for (N = 1; N < argCnt - 1; N++)
{
// LowerNode for NI_SSE41_Insert specially handles zeros, constants, and certain mask values
// to do the minimal number of operations and may merge together two neighboring inserts that
// don't have any side effects between them. Because of this and because of the interdependence
// of the inserts we've created above, we need to wait to lower the generated inserts until after
// we've completed the chain.

GenTree* insertedNode = insertedNodes[N];
LowerNode(insertedNode);
}
break;
}

Expand Down
13 changes: 8 additions & 5 deletions src/libraries/System.Numerics.Vectors/tests/Matrix3x2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,15 @@ public void Matrix3x2EqualsTest()
public void Matrix3x2GetHashCodeTest()
{
Matrix3x2 target = GenerateIncrementalMatrixNumber();
int expected = HashCode.Combine(target.M11, target.M12,
target.M21, target.M22,
target.M31, target.M32);
int actual;

actual = target.GetHashCode();
int expected = HashCode.Combine(
new Vector2(target.M11, target.M12),
new Vector2(target.M21, target.M22),
new Vector2(target.M31, target.M32)
);

int actual = target.GetHashCode();

Assert.Equal(expected, actual);
}

Expand Down
28 changes: 6 additions & 22 deletions src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,29 +1690,13 @@ public void Matrix4x4GetHashCodeTest()
{
Matrix4x4 target = GenerateIncrementalMatrixNumber();

HashCode hash = default;
int expected = HashCode.Combine(
new Vector4(target.M11, target.M12, target.M13, target.M14),
new Vector4(target.M21, target.M22, target.M23, target.M24),
new Vector4(target.M31, target.M32, target.M33, target.M34),
new Vector4(target.M41, target.M42, target.M43, target.M44)
);

hash.Add(target.M11);
hash.Add(target.M12);
hash.Add(target.M13);
hash.Add(target.M14);

hash.Add(target.M21);
hash.Add(target.M22);
hash.Add(target.M23);
hash.Add(target.M24);

hash.Add(target.M31);
hash.Add(target.M32);
hash.Add(target.M33);
hash.Add(target.M34);

hash.Add(target.M41);
hash.Add(target.M42);
hash.Add(target.M43);
hash.Add(target.M44);

int expected = hash.ToHashCode();
int actual = target.GetHashCode();

Assert.Equal(expected, actual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,9 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Number.Parsing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\BitOperations.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Matrix3x2.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Matrix3x2.Impl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Matrix4x4.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Matrix4x4.Impl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Plane.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\Quaternion.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\TotalOrderIeee754Comparer.cs" />
Expand Down Expand Up @@ -2535,4 +2537,4 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnaryPlusOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnsignedNumber.cs" />
</ItemGroup>
</Project>
</Project>
Loading

0 comments on commit f8218f9

Please sign in to comment.