|
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 (!netfx && !netstandard) |
| 6 | +using Internal.Runtime.CompilerServices; |
| 7 | +#endif |
5 | 8 | using System.Globalization;
|
6 | 9 | using System.Numerics.Hashing;
|
7 | 10 | using System.Runtime.CompilerServices;
|
| 11 | +using System.Runtime.InteropServices; |
8 | 12 | using System.Text;
|
9 | 13 |
|
10 | 14 | namespace System.Numerics
|
@@ -386,7 +390,7 @@ public unsafe Vector(T[] values, int index)
|
386 | 390 | }
|
387 | 391 | if (index < 0 || (values.Length - index) < Count)
|
388 | 392 | {
|
389 |
| - throw new IndexOutOfRangeException(); |
| 393 | + throw new IndexOutOfRangeException(SR.Format(SR.Arg_InsufficientNumberOfElements, Vector<T>.Count, nameof(values))); |
390 | 394 | }
|
391 | 395 |
|
392 | 396 | if (Vector.IsHardwareAccelerated)
|
@@ -763,6 +767,35 @@ private Vector(ref Register existingRegister)
|
763 | 767 | {
|
764 | 768 | this.register = existingRegister;
|
765 | 769 | }
|
| 770 | + |
| 771 | + /// <summary> |
| 772 | + /// Constructs a vector from the given span. The span must contain at least Vector'T.Count elements. |
| 773 | + /// </summary> |
| 774 | + public Vector(Span<T> values) |
| 775 | + : this() |
| 776 | + { |
| 777 | + if ((typeof(T) == typeof(Byte)) |
| 778 | + || (typeof(T) == typeof(SByte)) |
| 779 | + || (typeof(T) == typeof(UInt16)) |
| 780 | + || (typeof(T) == typeof(Int16)) |
| 781 | + || (typeof(T) == typeof(UInt32)) |
| 782 | + || (typeof(T) == typeof(Int32)) |
| 783 | + || (typeof(T) == typeof(UInt64)) |
| 784 | + || (typeof(T) == typeof(Int64)) |
| 785 | + || (typeof(T) == typeof(Single)) |
| 786 | + || (typeof(T) == typeof(Double))) |
| 787 | + { |
| 788 | + if (values.Length < Count) |
| 789 | + { |
| 790 | + throw new IndexOutOfRangeException(SR.Format(SR.Arg_InsufficientNumberOfElements, Vector<T>.Count, nameof(values))); |
| 791 | + } |
| 792 | + this = Unsafe.ReadUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values))); |
| 793 | + } |
| 794 | + else |
| 795 | + { |
| 796 | + throw new NotSupportedException(SR.Arg_TypeNotSupported); |
| 797 | + } |
| 798 | + } |
766 | 799 | #endregion Constructors
|
767 | 800 |
|
768 | 801 | #region Public Instance Methods
|
|
0 commit comments