-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Processing dotnet/runtime#111309 (comment) command:
Command
-amd -arm -profiler
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using BenchmarkDotNet.Attributes;
public class Bench
{
private static int[] Testdata = new int[10000];
[Benchmark]
public int Sum_safe()
{
ReadOnlySpan<int> span = Testdata;
Vector128<int> vSum = default;
int i;
for (i = 0; i < span.Length - Vector128<int>.Count; i += Vector128<int>.Count)
vSum += Vector128.Create(span[i..]);
int sum = Vector128.Sum(vSum);
for (; i < span.Length; i++)
sum += span[i];
return sum;
}
[Benchmark(Baseline = true)]
public int Sum_unsafe()
{
ReadOnlySpan<int> span = Testdata;
Vector128<int> vSum = default;
ref int r = ref MemoryMarshal.GetReference(span);
int i;
for (i = 0; i < span.Length - Vector128<int>.Count; i += Vector128<int>.Count)
vSum += Vector128.LoadUnsafe(ref r, (nuint)i);
int sum = Vector128.Sum(vSum);
for (; i < span.Length; i++)
sum += span[i];
return sum;
}
}(EgorBot will reply in this issue)
Metadata
Metadata
Assignees
Labels
No labels