Skip to content

Commit

Permalink
CoreFX dotnet#24343 Vector using Span
Browse files Browse the repository at this point in the history
dotnet/corefx#24343
  • Loading branch information
WinCPP committed Mar 3, 2018
1 parent f5a4248 commit 3f420d3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/mscorlib/shared/System/Numerics/Vector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Internal.Runtime.CompilerServices;
using System.Globalization;
using System.Numerics.Hashing;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

namespace System.Numerics
Expand Down Expand Up @@ -763,6 +765,17 @@ private Vector(ref Register existingRegister)
{
this.register = existingRegister;
}

/// <summary>
/// Constructs a vector from the given span.
/// The span must contain at least Vector'T.Count elements.
/// </summary>
[Intrinsic]
public unsafe Vector(Span<T> values)
: this()
{
this = Unsafe.ReadUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)));
}
#endregion Constructors

#region Public Instance Methods
Expand Down
13 changes: 13 additions & 0 deletions src/mscorlib/shared/System/Numerics/Vector.tt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
<#@ import namespace="System.Runtime.InteropServices" #>
<#@ include file="GenerationConfig.ttinclude" #><# GenerateCopyrightHeader(); #>

using Internal.Runtime.CompilerServices;
using System.Globalization;
using System.Numerics.Hashing;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

namespace System.Numerics
Expand Down Expand Up @@ -283,6 +285,17 @@ namespace System.Numerics
{
this.register = existingRegister;
}

/// <summary>
/// Constructs a vector from the given span.
/// The span must contain at least Vector'T.Count elements.
/// </summary>
[Intrinsic]
public unsafe Vector(Span<T> values)
: this()
{
this = Unsafe.ReadUnaligned<Vector<T>>(ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(values)));
}
#endregion Constructors

#region Public Instance Methods
Expand Down

0 comments on commit 3f420d3

Please sign in to comment.