Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions src/libraries/System.Linq/src/System/Linq/Range.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace System.Linq
{
Expand Down Expand Up @@ -79,33 +77,26 @@ public override void Dispose()
/// <summary>Fills the <paramref name="destination"/> with incrementing numbers, starting from <paramref name="value"/>.</summary>
private static void FillIncrementing<T>(Span<T> destination, T value) where T : INumber<T>
{
ref T pos = ref MemoryMarshal.GetReference(destination);
ref T end = ref Unsafe.Add(ref pos, destination.Length);

if (Vector.IsHardwareAccelerated &&
Vector<T>.IsSupported &&
destination.Length >= Vector<T>.Count)
{
Vector<T> init = Vector<T>.Indices;
Vector<T> current = new Vector<T>(value) + init;
Vector<T> current = new Vector<T>(value) + Vector<T>.Indices;
Vector<T> increment = new Vector<T>(T.CreateTruncating(Vector<T>.Count));

ref T oneVectorFromEnd = ref Unsafe.Subtract(ref end, Vector<T>.Count);
do
while (destination.Length >= Vector<T>.Count)
{
current.StoreUnsafe(ref pos);
current.CopyTo(destination);
current += increment;
pos = ref Unsafe.Add(ref pos, Vector<T>.Count);
destination = destination.Slice(Vector<T>.Count);
}
while (Unsafe.IsAddressLessThanOrEqualTo(ref pos, ref oneVectorFromEnd));

value = current[0];
}

while (Unsafe.IsAddressLessThan(ref pos, ref end))
foreach (ref T slot in destination)
{
pos = value++;
pos = ref Unsafe.Add(ref pos, 1);
slot = value++;
}
}
}
Expand Down
Loading