Skip to content

Ensure that Vector512 uses the same patterns as Vector64/128/256 #97990

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,7 @@ public static void CopyTo<T>(this Vector512<T> vector, Span<T> destination)
ThrowHelper.ThrowArgumentException_DestinationTooShort();
}

ref byte address = ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(destination));
Unsafe.WriteUnaligned(ref address, vector);
Unsafe.WriteUnaligned(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(destination)), vector);
}

/// <summary>Creates a new <see cref="Vector512{T}" /> instance with all elements initialized to the specified value.</summary>
Expand Down Expand Up @@ -616,8 +615,7 @@ public static Vector512<T> Create<T>(T[] values)
ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException();
}

ref byte address = ref Unsafe.As<T, byte>(ref MemoryMarshal.GetArrayDataReference(values));
return Unsafe.ReadUnaligned<Vector512<T>>(ref address);
return Unsafe.ReadUnaligned<Vector512<T>>(ref Unsafe.As<T, byte>(ref values[0]));
}

/// <summary>Creates a new <see cref="Vector512{T}" /> from a given array.</summary>
Expand All @@ -637,8 +635,7 @@ public static Vector512<T> Create<T>(T[] values, int index)
ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException();
}

ref byte address = ref Unsafe.As<T, byte>(ref MemoryMarshal.GetArrayDataReference(values));
return Unsafe.ReadUnaligned<Vector512<T>>(ref Unsafe.Add(ref address, index));
return Unsafe.ReadUnaligned<Vector512<T>>(ref Unsafe.As<T, byte>(ref values[index]));
}

/// <summary>Creates a new <see cref="Vector512{T}" /> from a given readonly span.</summary>
Expand All @@ -655,8 +652,7 @@ public static Vector512<T> Create<T>(ReadOnlySpan<T> values)
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.values);
}

ref byte address = ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values));
return Unsafe.ReadUnaligned<Vector512<T>>(ref address);
return Unsafe.ReadUnaligned<Vector512<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)));
}

/// <summary>Creates a new <see cref="Vector512{Byte}" /> instance with each element initialized to the corresponding specified value.</summary>
Expand Down Expand Up @@ -2717,8 +2713,7 @@ public static bool TryCopyTo<T>(this Vector512<T> vector, Span<T> destination)
return false;
}

ref byte address = ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(destination));
Unsafe.WriteUnaligned(ref address, vector);
Unsafe.WriteUnaligned(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(destination)), vector);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4539,6 +4539,22 @@ public void Vector128SingleEqualsNonCanonicalNaNTest()
}
}

[Fact]
public void Vector128SingleCreateFromArrayTest()
{
float[] array = [1.0f, 2.0f, 3.0f, 4.0f, 5.0f];
Vector128<float> vector = Vector128.Create(array);
Assert.Equal(Vector128.Create(1.0f, 2.0f, 3.0f, 4.0f), vector);
}

[Fact]
public void Vector128SingleCreateFromArrayOffsetTest()
{
float[] array = [1.0f, 2.0f, 3.0f, 4.0f, 5.0f];
Vector128<float> vector = Vector128.Create(array, 1);
Assert.Equal(Vector128.Create(2.0f, 3.0f, 4.0f, 5.0f), vector);
}

[Fact]
public void Vector128SingleCopyToTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5561,6 +5561,22 @@ public void Vector256SingleEqualsNonCanonicalNaNTest()
}
}

[Fact]
public void Vector256SingleCreateFromArrayTest()
{
float[] array = [1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f];
Vector256<float> vector = Vector256.Create(array);
Assert.Equal(Vector256.Create(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f), vector);
}

[Fact]
public void Vector256SingleCreateFromArrayOffsetTest()
{
float[] array = [1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f];
Vector256<float> vector = Vector256.Create(array, 1);
Assert.Equal(Vector256.Create(2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f), vector);
}

[Fact]
public void Vector256SingleCopyToTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5038,6 +5038,22 @@ public void Vector512SingleEqualsNonCanonicalNaNTest()
}
}

[Fact]
public void Vector512SingleCreateFromArrayTest()
{
float[] array = [1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f];
Vector512<float> vector = Vector512.Create(array);
Assert.Equal(Vector512.Create(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f), vector);
}

[Fact]
public void Vector512SingleCreateFromArrayOffsetTest()
{
float[] array = [1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f];
Vector512<float> vector = Vector512.Create(array, 1);
Assert.Equal(Vector512.Create(2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f), vector);
}

[Fact]
public void Vector512SingleCopyToTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3963,6 +3963,22 @@ public void Vector64SingleEqualsNonCanonicalNaNTest()
}
}

[Fact]
public void Vector64SingleCreateFromArrayTest()
{
float[] array = [1.0f, 2.0f, 3.0f];
Vector64<float> vector = Vector64.Create(array);
Assert.Equal(Vector64.Create(1.0f, 2.0f), vector);
}

[Fact]
public void Vector64SingleCreateFromArrayOffsetTest()
{
float[] array = [1.0f, 2.0f, 3.0f];
Vector64<float> vector = Vector64.Create(array, 1);
Assert.Equal(Vector64.Create(2.0f, 3.0f), vector);
}

[Fact]
public void Vector64SingleCopyToTest()
{
Expand Down