Skip to content

Commit 3f420d3

Browse files
committed
CoreFX dotnet#24343 Vector using Span
dotnet/corefx#24343
1 parent f5a4248 commit 3f420d3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/mscorlib/shared/System/Numerics/Vector.cs

+13
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using Internal.Runtime.CompilerServices;
56
using System.Globalization;
67
using System.Numerics.Hashing;
78
using System.Runtime.CompilerServices;
9+
using System.Runtime.InteropServices;
810
using System.Text;
911

1012
namespace System.Numerics
@@ -763,6 +765,17 @@ private Vector(ref Register existingRegister)
763765
{
764766
this.register = existingRegister;
765767
}
768+
769+
/// <summary>
770+
/// Constructs a vector from the given span.
771+
/// The span must contain at least Vector'T.Count elements.
772+
/// </summary>
773+
[Intrinsic]
774+
public unsafe Vector(Span<T> values)
775+
: this()
776+
{
777+
this = Unsafe.ReadUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)));
778+
}
766779
#endregion Constructors
767780

768781
#region Public Instance Methods

src/mscorlib/shared/System/Numerics/Vector.tt

+13
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
<#@ import namespace="System.Runtime.InteropServices" #>
88
<#@ include file="GenerationConfig.ttinclude" #><# GenerateCopyrightHeader(); #>
99

10+
using Internal.Runtime.CompilerServices;
1011
using System.Globalization;
1112
using System.Numerics.Hashing;
1213
using System.Runtime.CompilerServices;
14+
using System.Runtime.InteropServices;
1315
using System.Text;
1416

1517
namespace System.Numerics
@@ -283,6 +285,17 @@ namespace System.Numerics
283285
{
284286
this.register = existingRegister;
285287
}
288+
289+
/// <summary>
290+
/// Constructs a vector from the given span.
291+
/// The span must contain at least Vector'T.Count elements.
292+
/// </summary>
293+
[Intrinsic]
294+
public unsafe Vector(Span<T> values)
295+
: this()
296+
{
297+
this = Unsafe.ReadUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)));
298+
}
286299
#endregion Constructors
287300

288301
#region Public Instance Methods

0 commit comments

Comments
 (0)