|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 | // See the LICENSE file in the project root for more information.
|
4 | 4 |
|
| 5 | +#if !netstandard |
5 | 6 | using Internal.Runtime.CompilerServices;
|
| 7 | +#endif |
6 | 8 | using System.Globalization;
|
7 | 9 | using System.Numerics.Hashing;
|
8 | 10 | using System.Runtime.CompilerServices;
|
@@ -388,7 +390,7 @@ public unsafe Vector(T[] values, int index)
|
388 | 390 | }
|
389 | 391 | if (index < 0 || (values.Length - index) < Count)
|
390 | 392 | {
|
391 |
| - throw new IndexOutOfRangeException(); |
| 393 | + throw new IndexOutOfRangeException(String.Format(SR.Arg_InsufficientNumberOfElements, Vector<T>.Count, nameof(values))); |
392 | 394 | }
|
393 | 395 |
|
394 | 396 | if (Vector.IsHardwareAccelerated)
|
@@ -767,14 +769,33 @@ private Vector(ref Register existingRegister)
|
767 | 769 | }
|
768 | 770 |
|
769 | 771 | /// <summary>
|
770 |
| - /// Constructs a vector from the given span. |
771 |
| - /// The span must contain at least Vector'T.Count elements. |
| 772 | + /// Constructs a vector from the given span. The span must contain at least Vector'T.Count elements. |
772 | 773 | /// </summary>
|
773 | 774 | [Intrinsic]
|
774 | 775 | public unsafe Vector(Span<T> values)
|
775 | 776 | : this()
|
776 | 777 | {
|
777 |
| - this = Unsafe.ReadUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values))); |
| 778 | + if ((typeof(T) == typeof(Byte)) |
| 779 | + || (typeof(T) == typeof(SByte)) |
| 780 | + || (typeof(T) == typeof(UInt16)) |
| 781 | + || (typeof(T) == typeof(Int16)) |
| 782 | + || (typeof(T) == typeof(UInt32)) |
| 783 | + || (typeof(T) == typeof(Int32)) |
| 784 | + || (typeof(T) == typeof(UInt64)) |
| 785 | + || (typeof(T) == typeof(Int64)) |
| 786 | + || (typeof(T) == typeof(Single)) |
| 787 | + || (typeof(T) == typeof(Double))) |
| 788 | + { |
| 789 | + if (values.Length < Count) |
| 790 | + { |
| 791 | + throw new IndexOutOfRangeException(String.Format(SR.Arg_InsufficientNumberOfElements, Vector<T>.Count, nameof(values))); |
| 792 | + } |
| 793 | + this = Unsafe.ReadUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values))); |
| 794 | + } |
| 795 | + else |
| 796 | + { |
| 797 | + throw new NotSupportedException(SR.Arg_TypeNotSupported); |
| 798 | + } |
778 | 799 | }
|
779 | 800 | #endregion Constructors
|
780 | 801 |
|
|
0 commit comments