I'm writing code that will subtract corresponding bytes in two arrays and count the number of resulting bytes surpassing a given threshold. AFAIU, it would really benefit from .NET SIMD, but System.Numerics.Vector.IsHardwareAccelerated returns false when I compile C# on Raspberry Pi 4.
My dotnet version is 3.1.406, I've added
<PropertyGroup>
<Optimize>true</Optimize>
</PropertyGroup>
to the csproj and running release configuration.
Is there any way I can leverage SIMD support in .NET on Raspberry Pi 4? Maybe with .NET 5?
Update I installed .NET 5 and tried .NET Intrinsics, but none is supported:
Console.WriteLine(System.Runtime.Intrinsics.Arm.AdvSimd.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Aes.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.ArmBase.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Crc32.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Dp.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Rdm.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Sha1.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Sha256.IsSupported); //false
I'm on 32-bit Raspbian (Debian derivative), is there any chance I need 64-bit version for this to work?
P.S. To clarify, in plain C# the algorhytm looks like this:
public static int ScalarTest(byte[] lhs, byte[] rhs)
{
var result = 0;
for (int index = 0; index < lhs.Length; index++)
{
var a = lhs[index];
var b = rhs[index];
if (b > a)
{
(b, a) = (a, b);
}
result += ((a - b) >= 16) ? 1 : 0;
}
return result;
}