diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/ISimdVector_2.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/ISimdVector_2.cs index eaa9a524be175a..674d437c0551cb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/ISimdVector_2.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/ISimdVector_2.cs @@ -154,7 +154,14 @@ internal unsafe interface ISimdVector /// The length of is less than . /// The type of the elements in the vector () is not supported. /// is null. - static virtual void CopyTo(TSelf vector, T[] destination) => TSelf.CopyTo(vector, destination.AsSpan()); + static virtual void CopyTo(TSelf vector, T[] destination) + { + if (destination.Length < TSelf.Count) + { + ThrowHelper.ThrowArgumentException_DestinationTooShort(); + } + TSelf.StoreUnsafe(vector, ref MemoryMarshal.GetArrayDataReference(destination)); + } /// Copies a vector to a given array starting at the specified index. /// The vector to be copied. @@ -164,7 +171,18 @@ internal unsafe interface ISimdVector /// is negative or greater than the length of . /// The type of the elements in the vector () is not supported. /// is null. - static virtual void CopyTo(TSelf vector, T[] destination, int startIndex) => TSelf.CopyTo(vector, destination.AsSpan(startIndex)); + static virtual void CopyTo(TSelf vector, T[] destination, int startIndex) + { + if ((uint)startIndex >= (uint)destination.Length) + { + ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_IndexMustBeLess(); + } + if ((destination.Length - startIndex) < TSelf.Count) + { + ThrowHelper.ThrowArgumentException_DestinationTooShort(); + } + TSelf.StoreUnsafe(vector, ref MemoryMarshal.GetArrayDataReference(destination), (uint)startIndex); + } /// Copies a vector to a given span. /// The vector to be copied. @@ -192,7 +210,14 @@ static virtual void CopyTo(TSelf vector, Span destination) /// The length of is less than . /// The type of the elements in the vector () is not supported. /// is null. - static virtual TSelf Create(T[] values) => TSelf.Create(values.AsSpan()); + static virtual TSelf Create(T[] values) + { + if (values.Length < TSelf.Count) + { + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); + } + return TSelf.LoadUnsafe(ref MemoryMarshal.GetArrayDataReference(values)); + } /// Creates a new vector from a given array. /// The array from which the vector is created. @@ -201,7 +226,14 @@ static virtual void CopyTo(TSelf vector, Span destination) /// The length of , starting from , is less than . /// The type of the elements in the vector () is not supported. /// is null. - static virtual TSelf Create(T[] values, int index) => TSelf.Create(values.AsSpan(index)); + static virtual TSelf Create(T[] values, int index) + { + if ((index < 0) || ((values.Length - index) < TSelf.Count)) + { + ThrowHelper.ThrowArgumentOutOfRange_IndexMustBeLessOrEqualException(); + } + return TSelf.LoadUnsafe(ref MemoryMarshal.GetArrayDataReference(values), (uint)index); + } /// Creates a new vector from a given readonly span. /// The readonly span from which the vector is created.