Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Expose the FusedMultiplyAdd and MultiplyAddEstimate APIs on relevant vector and scalar types#102181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tannergooding merged 10 commits intodotnet:mainfromtannergooding:fix-93513
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
10 commits
Select commitHold shift + click to select a range
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
PrevPrevious commit
NextNext commit
Adding tests covering FusedMultiplyAdd and MultiplyAddEstimate for th…
…e vector types
  • Loading branch information
@tannergooding
tannergooding committedMay 14, 2024
commit940862e4bf6bba4cc0b589a9341f055bfd80deca
View file
Open in desktop

Large diffs are not rendered by default.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Runtime.Intrinsics.Tests.Vectors;
using Xunit;
using Xunit.Sdk;

Expand All@@ -19,6 +20,32 @@ namespace System.Numerics.Tests
[RequiresPreviewFeatures]
public unsafe class GenericVectorTests
{
/// <summary>Verifies that two <see cref="Vector{Single}" /> values are equal, within the <paramref name="variance" />.</summary>
/// <param name="expected">The expected value</param>
/// <param name="actual">The value to be compared against</param>
/// <param name="variance">The total variance allowed between the expected and actual results.</param>
/// <exception cref="EqualException">Thrown when the values are not equal</exception>
internal static void AssertEqual(Vector<float> expected, Vector<float> actual, Vector<float> variance)
{
for (int i = 0; i < Vector<float>.Count; i++)
{
AssertExtensions.Equal(expected.GetElement(i), actual.GetElement(i), variance.GetElement(i));
}
}

/// <summary>Verifies that two <see cref="Vector{Double}" /> values are equal, within the <paramref name="variance" />.</summary>
/// <param name="expected">The expected value</param>
/// <param name="actual">The value to be compared against</param>
/// <param name="variance">The total variance allowed between the expected and actual results.</param>
/// <exception cref="EqualException">Thrown when the values are not equal</exception>
internal static void AssertEqual(Vector<double> expected, Vector<double> actual, Vector<double> variance)
{
for (int i = 0; i < Vector<double>.Count; i++)
{
AssertExtensions.Equal(expected.GetElement(i), actual.GetElement(i), variance.GetElement(i));
}
}

// Static constructor in top-level class\
static System.Numerics.Vector<float> dummy;
static GenericVectorTests()
Expand DownExpand Up@@ -4499,7 +4526,7 @@ private static void TestGetIndices<T>()
private static void TestCreateSequence<T>(T start, T step)
where T : INumber<T>
{
Vector<T> sequence = Vector.CreateSequence(start, step);
Vector<T> sequence =newVector<double>Sequence(start, step);
T expected = start;

for (int index = 0; index < Vector<T>.Count; index++)
Expand All@@ -4508,5 +4535,37 @@ private static void TestCreateSequence<T>(T start, T step)
expected += step;
}
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddDouble), MemberType = typeof(VectorTestMemberData))]
public void FusedMultiplyAddDoubleTest(double left, double right, double addend)
{
Vector<double> actualResult = Vector.FusedMultiplyAdd(new Vector<double>(left), new Vector<double>(right), new Vector<double>(addend));
AssertEqual(new Vector<double>(double.FusedMultiplyAdd(left, right, addend)), actualResult, Vector<double>.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void FusedMultiplyAddSingleTest(float left, float right, float addend)
{
Vector<float> actualResult = Vector.FusedMultiplyAdd(new Vector<float>(left), new Vector<float>(right), new Vector<float>(addend));
AssertEqual(new Vector<float>(float.FusedMultiplyAdd(left, right, addend)), actualResult, Vector<float>.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddDouble), MemberType = typeof(VectorTestMemberData))]
public void MultiplyAddEstimateDoubleTest(double left, double right, double addend)
{
Vector<double> actualResult = Vector.MultiplyAddEstimate(new Vector<double>(left), new Vector<double>(right), new Vector<double>(addend));
AssertEqual(new Vector<double>(double.MultiplyAddEstimate(left, right, addend)), actualResult, Vector<double>.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void MultiplyAddEstimateSingleTest(float left, float right, float addend)
{
Vector<float> actualResult = Vector.MultiplyAddEstimate(new Vector<float>(left), new Vector<float>(right), new Vector<float>(addend));
AssertEqual(new Vector<float>(float.MultiplyAddEstimate(left, right, addend)), actualResult, Vector<float>.Zero);
}
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,5 +18,6 @@
<Compile Include="Matrix4x4Tests.cs" />
<Compile Include="PlaneTests.cs" />
<Compile Include="QuaternionTests.cs" />
<Compile Include="$(CommonTestPath)\System\Runtime\Intrinsics\VectorTestMemberData.cs" Link="Common\System\Runtime\Intrinsics\VectorTestMemberData.cs" />
</ItemGroup>
</Project>
28 changes: 28 additions & 0 deletionssrc/libraries/System.Numerics.Vectors/tests/Vector2Tests.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,12 +3,24 @@

using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.Tests.Vectors;
using Xunit;

namespace System.Numerics.Tests
{
public sealed class Vector2Tests
{
/// <summary>Verifies that two <see cref="Vector2" /> values are equal, within the <paramref name="variance" />.</summary>
/// <param name="expected">The expected value</param>
/// <param name="actual">The value to be compared against</param>
/// <param name="variance">The total variance allowed between the expected and actual results.</param>
/// <exception cref="EqualException">Thrown when the values are not equal</exception>
internal static void AssertEqual(Vector2 expected, Vector2 actual, Vector2 variance)
{
AssertExtensions.Equal(expected.X, actual.X, variance.X);
AssertExtensions.Equal(expected.Y, actual.Y, variance.Y);
}

[Fact]
public void Vector2MarshalSizeTest()
{
Expand DownExpand Up@@ -1286,5 +1298,21 @@ private class EmbeddedVectorObject
{
public Vector2 FieldVector;
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void FusedMultiplyAddSingleTest(float left, float right, float addend)
{
Vector2 actualResult = Vector2.FusedMultiplyAdd(new Vector2(left), new Vector2(right), new Vector2(addend));
AssertEqual(new Vector2(float.FusedMultiplyAdd(left, right, addend)), actualResult, Vector2.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void MultiplyAddEstimateSingleTest(float left, float right, float addend)
{
Vector2 actualResult = Vector2.MultiplyAddEstimate(new Vector2(left), new Vector2(right), new Vector2(addend));
AssertEqual(new Vector2(float.MultiplyAddEstimate(left, right, addend)), actualResult, Vector2.Zero);
}
}
}
29 changes: 29 additions & 0 deletionssrc/libraries/System.Numerics.Vectors/tests/Vector3Tests.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,12 +3,25 @@

using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.Tests.Vectors;
using Xunit;

namespace System.Numerics.Tests
{
public sealed class Vector3Tests
{
/// <summary>Verifies that two <see cref="Vector3" /> values are equal, within the <paramref name="variance" />.</summary>
/// <param name="expected">The expected value</param>
/// <param name="actual">The value to be compared against</param>
/// <param name="variance">The total variance allowed between the expected and actual results.</param>
/// <exception cref="EqualException">Thrown when the values are not equal</exception>
internal static void AssertEqual(Vector3 expected, Vector3 actual, Vector3 variance)
{
AssertExtensions.Equal(expected.X, actual.X, variance.X);
AssertExtensions.Equal(expected.Y, actual.Y, variance.Y);
AssertExtensions.Equal(expected.Z, actual.Z, variance.Z);
}

[Fact]
public void Vector3MarshalSizeTest()
{
Expand DownExpand Up@@ -1335,5 +1348,21 @@ private class EmbeddedVectorObject
{
public Vector3 FieldVector;
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void FusedMultiplyAddSingleTest(float left, float right, float addend)
{
Vector3 actualResult = Vector3.FusedMultiplyAdd(new Vector3(left), new Vector3(right), new Vector3(addend));
AssertEqual(new Vector3(float.FusedMultiplyAdd(left, right, addend)), actualResult, Vector3.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void MultiplyAddEstimateSingleTest(float left, float right, float addend)
{
Vector3 actualResult = Vector3.MultiplyAddEstimate(new Vector3(left), new Vector3(right), new Vector3(addend));
AssertEqual(new Vector3(float.MultiplyAddEstimate(left, right, addend)), actualResult, Vector3.Zero);
}
}
}
30 changes: 30 additions & 0 deletionssrc/libraries/System.Numerics.Vectors/tests/Vector4Tests.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,12 +3,26 @@

using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.Tests.Vectors;
using Xunit;

namespace System.Numerics.Tests
{
public sealed class Vector4Tests
{
/// <summary>Verifies that two <see cref="Vector4" /> values are equal, within the <paramref name="variance" />.</summary>
/// <param name="expected">The expected value</param>
/// <param name="actual">The value to be compared against</param>
/// <param name="variance">The total variance allowed between the expected and actual results.</param>
/// <exception cref="EqualException">Thrown when the values are not equal</exception>
internal static void AssertEqual(Vector4 expected, Vector4 actual, Vector4 variance)
{
AssertExtensions.Equal(expected.X, actual.X, variance.X);
AssertExtensions.Equal(expected.Y, actual.Y, variance.Y);
AssertExtensions.Equal(expected.Z, actual.Z, variance.Z);
AssertExtensions.Equal(expected.W, actual.W, variance.W);
}

[Fact]
public void Vector4MarshalSizeTest()
{
Expand DownExpand Up@@ -1709,5 +1723,21 @@ public struct Level7
}
}
#pragma warning restore 0169

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void FusedMultiplyAddSingleTest(float left, float right, float addend)
{
Vector4 actualResult = Vector4.FusedMultiplyAdd(new Vector4(left), new Vector4(right), new Vector4(addend));
AssertEqual(new Vector4(float.FusedMultiplyAdd(left, right, addend)), actualResult, Vector4.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void MultiplyAddEstimateSingleTest(float left, float right, float addend)
{
Vector4 actualResult = Vector4.MultiplyAddEstimate(new Vector4(left), new Vector4(right), new Vector4(addend));
AssertEqual(new Vector4(float.MultiplyAddEstimate(left, right, addend)), actualResult, Vector4.Zero);
}
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,7 @@
<Compile Include="Vectors\Vector256Tests.cs" />
<Compile Include="Vectors\Vector512Tests.cs" />
<Compile Include="Vectors\Vector64Tests.cs" />
<Compile Include="Vectors\VectorTestMemberData.cs" />
<Compile Include="$(CommonTestPath)\System\Runtime\Intrinsics\VectorTestMemberData.cs" Link="Common\System\Runtime\Intrinsics\VectorTestMemberData.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(CommonTestPath)TestUtilities.Unicode\TestUtilities.Unicode.csproj" />
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4874,6 +4874,38 @@ public void Log2SingleTest(float value, float expectedResult, float variance)
AssertEqual(Vector128.Create(expectedResult), actualResult, Vector128.Create(variance));
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddDouble), MemberType = typeof(VectorTestMemberData))]
public void FusedMultiplyAddDoubleTest(double left, double right, double addend)
{
Vector128<double> actualResult = Vector128.FusedMultiplyAdd(Vector128.Create(left), Vector128.Create(right), Vector128.Create(addend));
AssertEqual(Vector128.Create(double.FusedMultiplyAdd(left, right, addend)), actualResult, Vector128<double>.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void FusedMultiplyAddSingleTest(float left, float right, float addend)
{
Vector128<float> actualResult = Vector128.FusedMultiplyAdd(Vector128.Create(left), Vector128.Create(right), Vector128.Create(addend));
AssertEqual(Vector128.Create(float.FusedMultiplyAdd(left, right, addend)), actualResult, Vector128<float>.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddDouble), MemberType = typeof(VectorTestMemberData))]
public void MultiplyAddEstimateDoubleTest(double left, double right, double addend)
{
Vector128<double> actualResult = Vector128.MultiplyAddEstimate(Vector128.Create(left), Vector128.Create(right), Vector128.Create(addend));
AssertEqual(Vector128.Create(double.MultiplyAddEstimate(left, right, addend)), actualResult, Vector128<double>.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void MultiplyAddEstimateSingleTest(float left, float right, float addend)
{
Vector128<float> actualResult = Vector128.MultiplyAddEstimate(Vector128.Create(left), Vector128.Create(right), Vector128.Create(addend));
AssertEqual(Vector128.Create(float.MultiplyAddEstimate(left, right, addend)), actualResult, Vector128<float>.Zero);
}

[Fact]
[SkipOnMono("https://github.com/dotnet/runtime/issues/100368")]
public void ConvertToInt32Test()
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5889,6 +5889,38 @@ public void Log2SingleTest(float value, float expectedResult, float variance)
AssertEqual(Vector256.Create(expectedResult), actualResult, Vector256.Create(variance));
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddDouble), MemberType = typeof(VectorTestMemberData))]
public void FusedMultiplyAddDoubleTest(double left, double right, double addend)
{
Vector256<double> actualResult = Vector256.FusedMultiplyAdd(Vector256.Create(left), Vector256.Create(right), Vector256.Create(addend));
AssertEqual(Vector256.Create(double.FusedMultiplyAdd(left, right, addend)), actualResult, Vector256<double>.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void FusedMultiplyAddSingleTest(float left, float right, float addend)
{
Vector256<float> actualResult = Vector256.FusedMultiplyAdd(Vector256.Create(left), Vector256.Create(right), Vector256.Create(addend));
AssertEqual(Vector256.Create(float.FusedMultiplyAdd(left, right, addend)), actualResult, Vector256<float>.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddDouble), MemberType = typeof(VectorTestMemberData))]
public void MultiplyAddEstimateDoubleTest(double left, double right, double addend)
{
Vector256<double> actualResult = Vector256.MultiplyAddEstimate(Vector256.Create(left), Vector256.Create(right), Vector256.Create(addend));
AssertEqual(Vector256.Create(double.MultiplyAddEstimate(left, right, addend)), actualResult, Vector256<double>.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void MultiplyAddEstimateSingleTest(float left, float right, float addend)
{
Vector256<float> actualResult = Vector256.MultiplyAddEstimate(Vector256.Create(left), Vector256.Create(right), Vector256.Create(addend));
AssertEqual(Vector256.Create(float.MultiplyAddEstimate(left, right, addend)), actualResult, Vector256<float>.Zero);
}

[Fact]
[SkipOnMono("https://github.com/dotnet/runtime/issues/100368")]
public void ConvertToInt32Test()
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5322,6 +5322,38 @@ public void Log2SingleTest(float value, float expectedResult, float variance)
AssertEqual(Vector512.Create(expectedResult), actualResult, Vector512.Create(variance));
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddDouble), MemberType = typeof(VectorTestMemberData))]
public void FusedMultiplyAddDoubleTest(double left, double right, double addend)
{
Vector512<double> actualResult = Vector512.FusedMultiplyAdd(Vector512.Create(left), Vector512.Create(right), Vector512.Create(addend));
AssertEqual(Vector512.Create(double.FusedMultiplyAdd(left, right, addend)), actualResult, Vector512<double>.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void FusedMultiplyAddSingleTest(float left, float right, float addend)
{
Vector512<float> actualResult = Vector512.FusedMultiplyAdd(Vector512.Create(left), Vector512.Create(right), Vector512.Create(addend));
AssertEqual(Vector512.Create(float.FusedMultiplyAdd(left, right, addend)), actualResult, Vector512<float>.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddDouble), MemberType = typeof(VectorTestMemberData))]
public void MultiplyAddEstimateDoubleTest(double left, double right, double addend)
{
Vector512<double> actualResult = Vector512.MultiplyAddEstimate(Vector512.Create(left), Vector512.Create(right), Vector512.Create(addend));
AssertEqual(Vector512.Create(double.MultiplyAddEstimate(left, right, addend)), actualResult, Vector512<double>.Zero);
}

[Theory]
[MemberData(nameof(VectorTestMemberData.MultiplyAddSingle), MemberType = typeof(VectorTestMemberData))]
public void MultiplyAddEstimateSingleTest(float left, float right, float addend)
{
Vector512<float> actualResult = Vector512.MultiplyAddEstimate(Vector512.Create(left), Vector512.Create(right), Vector512.Create(addend));
AssertEqual(Vector512.Create(float.MultiplyAddEstimate(left, right, addend)), actualResult, Vector512<float>.Zero);
}

[Fact]
[SkipOnMono("https://github.com/dotnet/runtime/issues/100368")]
public void ConvertToInt32Test()
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp