Skip to content
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
26 changes: 22 additions & 4 deletions src/libraries/System.Numerics.Vectors/tests/Vector2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,14 @@ public void GreaterThanAllTest()
Assert.False(Vector2.GreaterThanAll(Vector2.Create(2, 2), Vector2.Create(1, 2))); // Y not greater
}

[Fact]
public void GreaterThanAnyTest()
{
Assert.False(Vector2.GreaterThanAny(Vector2.Create(1, 2), Vector2.Create(1, 2)));
Assert.True(Vector2.GreaterThanAny(Vector2.Create(2, 2), Vector2.Create(1, 2)));
Assert.True(Vector2.GreaterThanAny(Vector2.Create(1, 3), Vector2.Create(1, 2)));
}

[Fact]
public void GreaterThanOrEqualAnyTest()
{
Expand All @@ -1943,6 +1951,14 @@ public void LessThanAllTest()
Assert.False(Vector2.LessThanAll(Vector2.Create(1, 3), Vector2.Create(2, 3))); // Y not less
}

[Fact]
public void LessThanAnyTest()
{
Assert.False(Vector2.LessThanAny(Vector2.Create(1, 2), Vector2.Create(1, 2)));
Assert.True(Vector2.LessThanAny(Vector2.Create(0, 2), Vector2.Create(1, 2)));
Assert.True(Vector2.LessThanAny(Vector2.Create(1, 1), Vector2.Create(1, 2)));
}

[Fact]
public void LessThanOrEqualAnyTest()
{
Expand All @@ -1958,27 +1974,29 @@ public void LessThanOrEqualAnyTest()
[Fact]
public void GreaterThanOrEqualAllTest()
{
// Test case that would have failed before fix: all 2 elements pass, but 3rd/4th (0 >= 0) could give false positive
// with undefined upper elements from AsVector128Unsafe
// The zero-filled padding lanes must not affect the result.
Assert.True(Vector2.GreaterThanOrEqualAll(Vector2.Create(2, 3), Vector2.Create(1, 2)));
Assert.True(Vector2.GreaterThanOrEqualAll(Vector2.Create(1, 2), Vector2.Create(1, 2))); // All equal

// Test cases where not all elements pass
Assert.False(Vector2.GreaterThanOrEqualAll(Vector2.Create(0, 3), Vector2.Create(1, 2))); // X not greater or equal
Assert.False(Vector2.GreaterThanOrEqualAll(Vector2.Create(2, 1), Vector2.Create(1, 2))); // Y not greater or equal
Assert.False(Vector2.GreaterThanOrEqualAll(Vector2.Create(float.NaN, 3), Vector2.Create(1, 2)));
Assert.False(Vector2.GreaterThanOrEqualAll(Vector2.Create(2, float.NaN), Vector2.Create(1, 2)));
}

[Fact]
public void LessThanOrEqualAllTest()
{
// Test case that would have failed before fix: all 2 elements pass, but 3rd/4th could give false positive
// with undefined upper elements from AsVector128Unsafe
// The zero-filled padding lanes must not affect the result.
Assert.True(Vector2.LessThanOrEqualAll(Vector2.Create(1, 2), Vector2.Create(2, 3)));
Assert.True(Vector2.LessThanOrEqualAll(Vector2.Create(1, 2), Vector2.Create(1, 2))); // All equal

// Test cases where not all elements pass
Assert.False(Vector2.LessThanOrEqualAll(Vector2.Create(3, 2), Vector2.Create(2, 3))); // X not less or equal
Assert.False(Vector2.LessThanOrEqualAll(Vector2.Create(1, 4), Vector2.Create(2, 3))); // Y not less or equal
Assert.False(Vector2.LessThanOrEqualAll(Vector2.Create(float.NaN, 2), Vector2.Create(2, 3)));
Assert.False(Vector2.LessThanOrEqualAll(Vector2.Create(1, float.NaN), Vector2.Create(2, 3)));
}
}
}
30 changes: 26 additions & 4 deletions src/libraries/System.Numerics.Vectors/tests/Vector3Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,15 @@ public void GreaterThanAllTest()
Assert.False(Vector3.GreaterThanAll(Vector3.Create(2, 3, 3), Vector3.Create(1, 2, 3))); // Z not greater
}

[Fact]
public void GreaterThanAnyTest()
{
Assert.False(Vector3.GreaterThanAny(Vector3.Create(1, 2, 3), Vector3.Create(1, 2, 3)));
Assert.True(Vector3.GreaterThanAny(Vector3.Create(2, 2, 3), Vector3.Create(1, 2, 3)));
Assert.True(Vector3.GreaterThanAny(Vector3.Create(1, 3, 3), Vector3.Create(1, 2, 3)));
Assert.True(Vector3.GreaterThanAny(Vector3.Create(1, 2, 4), Vector3.Create(1, 2, 3)));
}

[Fact]
public void GreaterThanOrEqualAnyTest()
{
Expand All @@ -1975,6 +1984,15 @@ public void LessThanAllTest()
Assert.False(Vector3.LessThanAll(Vector3.Create(1, 2, 4), Vector3.Create(2, 3, 4))); // Z not less
}

[Fact]
public void LessThanAnyTest()
{
Assert.False(Vector3.LessThanAny(Vector3.Create(1, 2, 3), Vector3.Create(1, 2, 3)));
Assert.True(Vector3.LessThanAny(Vector3.Create(0, 2, 3), Vector3.Create(1, 2, 3)));
Assert.True(Vector3.LessThanAny(Vector3.Create(1, 1, 3), Vector3.Create(1, 2, 3)));
Assert.True(Vector3.LessThanAny(Vector3.Create(1, 2, 2), Vector3.Create(1, 2, 3)));
}

[Fact]
public void LessThanOrEqualAnyTest()
{
Expand All @@ -1991,29 +2009,33 @@ public void LessThanOrEqualAnyTest()
[Fact]
public void GreaterThanOrEqualAllTest()
{
// Test case that would have failed before fix: all 3 elements pass, but 4th could give false positive
// with undefined upper element from AsVector128Unsafe
// The zero-filled padding lane must not affect the result.
Assert.True(Vector3.GreaterThanOrEqualAll(Vector3.Create(2, 3, 4), Vector3.Create(1, 2, 3)));
Assert.True(Vector3.GreaterThanOrEqualAll(Vector3.Create(1, 2, 3), Vector3.Create(1, 2, 3))); // All equal

// Test cases where not all elements pass
Assert.False(Vector3.GreaterThanOrEqualAll(Vector3.Create(0, 3, 4), Vector3.Create(1, 2, 3))); // X not greater or equal
Assert.False(Vector3.GreaterThanOrEqualAll(Vector3.Create(2, 1, 4), Vector3.Create(1, 2, 3))); // Y not greater or equal
Assert.False(Vector3.GreaterThanOrEqualAll(Vector3.Create(2, 3, 2), Vector3.Create(1, 2, 3))); // Z not greater or equal
Assert.False(Vector3.GreaterThanOrEqualAll(Vector3.Create(float.NaN, 3, 4), Vector3.Create(1, 2, 3)));
Assert.False(Vector3.GreaterThanOrEqualAll(Vector3.Create(2, float.NaN, 4), Vector3.Create(1, 2, 3)));
Assert.False(Vector3.GreaterThanOrEqualAll(Vector3.Create(2, 3, float.NaN), Vector3.Create(1, 2, 3)));
}

[Fact]
public void LessThanOrEqualAllTest()
{
// Test case that would have failed before fix: all 3 elements pass, but 4th could give false positive
// with undefined upper element from AsVector128Unsafe
// The zero-filled padding lane must not affect the result.
Assert.True(Vector3.LessThanOrEqualAll(Vector3.Create(1, 2, 3), Vector3.Create(2, 3, 4)));
Assert.True(Vector3.LessThanOrEqualAll(Vector3.Create(1, 2, 3), Vector3.Create(1, 2, 3))); // All equal

// Test cases where not all elements pass
Assert.False(Vector3.LessThanOrEqualAll(Vector3.Create(3, 2, 3), Vector3.Create(2, 3, 4))); // X not less or equal
Assert.False(Vector3.LessThanOrEqualAll(Vector3.Create(1, 4, 3), Vector3.Create(2, 3, 4))); // Y not less or equal
Assert.False(Vector3.LessThanOrEqualAll(Vector3.Create(1, 2, 5), Vector3.Create(2, 3, 4))); // Z not less or equal
Assert.False(Vector3.LessThanOrEqualAll(Vector3.Create(float.NaN, 2, 3), Vector3.Create(2, 3, 4)));
Assert.False(Vector3.LessThanOrEqualAll(Vector3.Create(1, float.NaN, 3), Vector3.Create(2, 3, 4)));
Assert.False(Vector3.LessThanOrEqualAll(Vector3.Create(1, 2, float.NaN), Vector3.Create(2, 3, 4)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public static float Cross(Vector2 value1, Vector2 value2)
/// <inheritdoc cref="Vector4.GreaterThanAny(Vector4, Vector4)" />
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool GreaterThanAny(Vector2 left, Vector2 right) => Vector128.EqualsAny(Vector128.GreaterThan(left.AsVector128(), right.AsVector128()).AsInt32(), Vector128.Create(-1, -1, 0, 0));
public static bool GreaterThanAny(Vector2 left, Vector2 right) => Vector128.GreaterThanAny(left.AsVector128(), right.AsVector128());

/// <inheritdoc cref="Vector4.GreaterThanOrEqual(Vector4, Vector4)" />
[Intrinsic]
Expand All @@ -562,7 +562,7 @@ public static float Cross(Vector2 value1, Vector2 value2)
/// <inheritdoc cref="Vector4.GreaterThanOrEqualAll(Vector4, Vector4)" />
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool GreaterThanOrEqualAll(Vector2 left, Vector2 right) => Vector128.EqualsAll(Vector128.GreaterThanOrEqual(left.AsVector128(), right.AsVector128()).AsInt32(), Vector128<int>.AllBitsSet);
public static bool GreaterThanOrEqualAll(Vector2 left, Vector2 right) => Vector128.GreaterThanOrEqualAll(left.AsVector128(), right.AsVector128());

/// <inheritdoc cref="Vector4.GreaterThanOrEqualAny(Vector4, Vector4)" />
[Intrinsic]
Expand Down Expand Up @@ -682,7 +682,7 @@ public static float Cross(Vector2 value1, Vector2 value2)
/// <inheritdoc cref="Vector4.LessThanAny(Vector4, Vector4)" />
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool LessThanAny(Vector2 left, Vector2 right) => Vector128.EqualsAny(Vector128.LessThan(left.AsVector128(), right.AsVector128()).AsInt32(), Vector128.Create(-1, -1, 0, 0));
public static bool LessThanAny(Vector2 left, Vector2 right) => Vector128.LessThanAny(left.AsVector128(), right.AsVector128());

/// <inheritdoc cref="Vector4.LessThanOrEqual(Vector4, Vector4)" />
[Intrinsic]
Expand All @@ -692,7 +692,7 @@ public static float Cross(Vector2 value1, Vector2 value2)
/// <inheritdoc cref="Vector4.LessThanOrEqualAll(Vector4, Vector4)" />
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool LessThanOrEqualAll(Vector2 left, Vector2 right) => Vector128.EqualsAll(Vector128.LessThanOrEqual(left.AsVector128(), right.AsVector128()).AsInt32(), Vector128<int>.AllBitsSet);
public static bool LessThanOrEqualAll(Vector2 left, Vector2 right) => Vector128.LessThanOrEqualAll(left.AsVector128(), right.AsVector128());

/// <inheritdoc cref="Vector4.LessThanOrEqualAny(Vector4, Vector4)" />
[Intrinsic]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ internal static Vector128<float> Cross(Vector128<float> vector1, Vector128<float
/// <inheritdoc cref="Vector4.GreaterThanAny(Vector4, Vector4)" />
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool GreaterThanAny(Vector3 left, Vector3 right) => Vector128.EqualsAny(Vector128.GreaterThan(left.AsVector128(), right.AsVector128()).AsInt32(), Vector128.Create(-1, -1, -1, 0));
public static bool GreaterThanAny(Vector3 left, Vector3 right) => Vector128.GreaterThanAny(left.AsVector128(), right.AsVector128());

/// <inheritdoc cref="Vector4.GreaterThanOrEqual(Vector4, Vector4)" />
[Intrinsic]
Expand All @@ -598,7 +598,7 @@ internal static Vector128<float> Cross(Vector128<float> vector1, Vector128<float
/// <inheritdoc cref="Vector4.GreaterThanOrEqualAll(Vector4, Vector4)" />
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool GreaterThanOrEqualAll(Vector3 left, Vector3 right) => Vector128.EqualsAll(Vector128.GreaterThanOrEqual(left.AsVector128(), right.AsVector128()).AsInt32(), Vector128<int>.AllBitsSet);
public static bool GreaterThanOrEqualAll(Vector3 left, Vector3 right) => Vector128.GreaterThanOrEqualAll(left.AsVector128(), right.AsVector128());

/// <inheritdoc cref="Vector4.GreaterThanOrEqualAny(Vector4, Vector4)" />
[Intrinsic]
Expand Down Expand Up @@ -719,7 +719,7 @@ internal static Vector128<float> Cross(Vector128<float> vector1, Vector128<float
/// <inheritdoc cref="Vector4.LessThanAny(Vector4, Vector4)" />
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool LessThanAny(Vector3 left, Vector3 right) => Vector128.EqualsAny(Vector128.LessThan(left.AsVector128(), right.AsVector128()).AsInt32(), Vector128.Create(-1, -1, -1, 0));
public static bool LessThanAny(Vector3 left, Vector3 right) => Vector128.LessThanAny(left.AsVector128(), right.AsVector128());

/// <inheritdoc cref="Vector4.LessThanOrEqual(Vector4, Vector4)" />
[Intrinsic]
Expand All @@ -729,7 +729,7 @@ internal static Vector128<float> Cross(Vector128<float> vector1, Vector128<float
/// <inheritdoc cref="Vector4.LessThanOrEqualAll(Vector4, Vector4)" />
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool LessThanOrEqualAll(Vector3 left, Vector3 right) => Vector128.EqualsAll(Vector128.LessThanOrEqual(left.AsVector128(), right.AsVector128()).AsInt32(), Vector128<int>.AllBitsSet);
public static bool LessThanOrEqualAll(Vector3 left, Vector3 right) => Vector128.LessThanOrEqualAll(left.AsVector128(), right.AsVector128());

/// <inheritdoc cref="Vector4.LessThanOrEqualAny(Vector4, Vector4)" />
[Intrinsic]
Expand Down
Loading