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

[release/3.0] fix Matrix4x4 + and - operator bugs (#39838) #39889

Merged
merged 1 commit into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/System.Numerics.Vectors/src/System/Numerics/Matrix4x4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1944,10 +1944,10 @@ public static unsafe Matrix4x4 Lerp(Matrix4x4 matrix1, Matrix4x4 matrix2, float
#if HAS_INTRINSICS
if (Sse.IsSupported)
{
Sse.Store(&value1.M11, Sse.Add(Sse.LoadVector128(&value1.M11), Sse.LoadVector128(&value1.M11)));
Sse.Store(&value1.M21, Sse.Add(Sse.LoadVector128(&value1.M21), Sse.LoadVector128(&value1.M21)));
Sse.Store(&value1.M31, Sse.Add(Sse.LoadVector128(&value1.M31), Sse.LoadVector128(&value1.M31)));
Sse.Store(&value1.M41, Sse.Add(Sse.LoadVector128(&value1.M41), Sse.LoadVector128(&value1.M41)));
Sse.Store(&value1.M11, Sse.Add(Sse.LoadVector128(&value1.M11), Sse.LoadVector128(&value2.M11)));
Sse.Store(&value1.M21, Sse.Add(Sse.LoadVector128(&value1.M21), Sse.LoadVector128(&value2.M21)));
Sse.Store(&value1.M31, Sse.Add(Sse.LoadVector128(&value1.M31), Sse.LoadVector128(&value2.M31)));
Sse.Store(&value1.M41, Sse.Add(Sse.LoadVector128(&value1.M41), Sse.LoadVector128(&value2.M41)));
return value1;
}
#endif
Expand Down Expand Up @@ -1984,10 +1984,10 @@ public static unsafe Matrix4x4 Lerp(Matrix4x4 matrix1, Matrix4x4 matrix2, float
#if HAS_INTRINSICS
if (Sse.IsSupported)
{
Sse.Store(&value1.M11, Sse.Subtract(Sse.LoadVector128(&value1.M11), Sse.LoadVector128(&value1.M11)));
Sse.Store(&value1.M21, Sse.Subtract(Sse.LoadVector128(&value1.M21), Sse.LoadVector128(&value1.M21)));
Sse.Store(&value1.M31, Sse.Subtract(Sse.LoadVector128(&value1.M31), Sse.LoadVector128(&value1.M31)));
Sse.Store(&value1.M41, Sse.Subtract(Sse.LoadVector128(&value1.M41), Sse.LoadVector128(&value1.M41)));
Sse.Store(&value1.M11, Sse.Subtract(Sse.LoadVector128(&value1.M11), Sse.LoadVector128(&value2.M11)));
Sse.Store(&value1.M21, Sse.Subtract(Sse.LoadVector128(&value1.M21), Sse.LoadVector128(&value2.M21)));
Sse.Store(&value1.M31, Sse.Subtract(Sse.LoadVector128(&value1.M31), Sse.LoadVector128(&value2.M31)));
Sse.Store(&value1.M41, Sse.Subtract(Sse.LoadVector128(&value1.M41), Sse.LoadVector128(&value2.M41)));
return value1;
}
#endif
Expand Down
56 changes: 42 additions & 14 deletions src/System.Numerics.Vectors/tests/Matrix4x4Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,8 +1205,25 @@ public void Matrix4x4UnaryNegationTest()
public void Matrix4x4SubtractionTest()
{
Matrix4x4 a = GenerateMatrixNumberFrom1To16();
Matrix4x4 b = GenerateMatrixNumberFrom1To16();
Matrix4x4 b = new Matrix4x4(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);

Matrix4x4 expected = new Matrix4x4();
expected.M11 = a.M11 - b.M11;
expected.M12 = a.M12 - b.M12;
expected.M13 = a.M13 - b.M13;
expected.M14 = a.M14 - b.M14;
expected.M21 = a.M21 - b.M21;
expected.M22 = a.M22 - b.M22;
expected.M23 = a.M23 - b.M23;
expected.M24 = a.M24 - b.M24;
expected.M31 = a.M31 - b.M31;
expected.M32 = a.M32 - b.M32;
expected.M33 = a.M33 - b.M33;
expected.M34 = a.M34 - b.M34;
expected.M41 = a.M41 - b.M41;
expected.M42 = a.M42 - b.M42;
expected.M43 = a.M43 - b.M43;
expected.M44 = a.M44 - b.M44;

Matrix4x4 actual = a - b;
Assert.True(MathHelper.Equal(expected, actual), "Matrix4x4.operator - did not return the expected value.");
Expand Down Expand Up @@ -1281,7 +1298,7 @@ public void Matrix4x4MultiplyTest4()
public void Matrix4x4AdditionTest()
{
Matrix4x4 a = GenerateMatrixNumberFrom1To16();
Matrix4x4 b = GenerateMatrixNumberFrom1To16();
Matrix4x4 b = new Matrix4x4(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);

Matrix4x4 expected = new Matrix4x4();
expected.M11 = a.M11 + b.M11;
Expand All @@ -1301,10 +1318,7 @@ public void Matrix4x4AdditionTest()
expected.M43 = a.M43 + b.M43;
expected.M44 = a.M44 + b.M44;

Matrix4x4 actual;

actual = a + b;

Matrix4x4 actual = a + b;
Assert.True(MathHelper.Equal(expected, actual), "Matrix4x4.operator + did not return the expected value.");
}

Expand Down Expand Up @@ -1516,7 +1530,7 @@ public void Matrix4x4ToStringTest()
public void Matrix4x4AddTest()
{
Matrix4x4 a = GenerateMatrixNumberFrom1To16();
Matrix4x4 b = GenerateMatrixNumberFrom1To16();
Matrix4x4 b = new Matrix4x4(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);

Matrix4x4 expected = new Matrix4x4();
expected.M11 = a.M11 + b.M11;
Expand All @@ -1536,9 +1550,7 @@ public void Matrix4x4AddTest()
expected.M43 = a.M43 + b.M43;
expected.M44 = a.M44 + b.M44;

Matrix4x4 actual;

actual = Matrix4x4.Add(a, b);
Matrix4x4 actual = Matrix4x4.Add(a, b);
Assert.Equal(expected, actual);
}

Expand Down Expand Up @@ -1719,11 +1731,27 @@ public void Matrix4x4EqualityTest()
public void Matrix4x4SubtractTest()
{
Matrix4x4 a = GenerateMatrixNumberFrom1To16();
Matrix4x4 b = GenerateMatrixNumberFrom1To16();
Matrix4x4 expected = new Matrix4x4();
Matrix4x4 actual;
Matrix4x4 b = new Matrix4x4(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);

actual = Matrix4x4.Subtract(a, b);
Matrix4x4 expected = new Matrix4x4();
expected.M11 = a.M11 - b.M11;
expected.M12 = a.M12 - b.M12;
expected.M13 = a.M13 - b.M13;
expected.M14 = a.M14 - b.M14;
expected.M21 = a.M21 - b.M21;
expected.M22 = a.M22 - b.M22;
expected.M23 = a.M23 - b.M23;
expected.M24 = a.M24 - b.M24;
expected.M31 = a.M31 - b.M31;
expected.M32 = a.M32 - b.M32;
expected.M33 = a.M33 - b.M33;
expected.M34 = a.M34 - b.M34;
expected.M41 = a.M41 - b.M41;
expected.M42 = a.M42 - b.M42;
expected.M43 = a.M43 - b.M43;
expected.M44 = a.M44 - b.M44;

Matrix4x4 actual = Matrix4x4.Subtract(a, b);
Assert.Equal(expected, actual);
}

Expand Down