I'm trying to learn about the new dotnet core 3 intrinsics (https://devblogs.microsoft.com/dotnet/hardware-intrinsics-in-net-core/ ).
I want to implement the simple c++ example from here
#include "emmintrin.h"
const __m128i v2 = _mm_set1_epi64x(2);
__m128i v = _mm_set_epi64x(1, 0);
for (size_t i=0; i<1000*1000*1000; i += 2)
{
_mm_stream_si128((__m128i *)&data[i], v);
v = _mm_add_epi64(v, v2);
}
(I realize the above can previously be done in C# using SIMD Vector
)
Looking at https://source.dot.net/#System.Private.CoreLib/shared/System/Runtime/Intrinsics/X86/Sse2.cs,1392 , I assume I need to use the function
/// <summary>
/// void _mm_stream_si128 (__m128i* mem_addr, __m128i a)
/// MOVNTDQ m128, xmm
/// </summary>
public static unsafe void StoreAlignedNonTemporal(long* address, Vector128<long> source) => StoreAlignedNonTemporal(address, source);
My C# program is as follows.
Intrinsics.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
</Project>
Program.cs:
using System;
using System.Runtime.Intrinsics.X86;
using System.Runtime.Intrinsics;
public class Program
{
public static void Main(string[] args)
{
if(!Sse2.IsSupported){
Console.WriteLine("Your CPU doesn't support SSE2 Instruction set");
return;
}
var data = new long[100000];
var v = Vector128.Create(1L, 0L);
var v2 = Vector128.Create(0L, 0L);
Span<long> buffer = data.AsSpan();
for (int i=0; i<100000; i+=2)
{
Sse2.StoreAlignedNonTemporal(buffer[i], v);
// TODO: convert this to C#: v = _mm_add_epi64(v, v2);
}
}
}
When I try to build the project, it fails with the following error:
burnsba@debian:~/code/Intrinsics$ dotnet build
Microsoft (R) Build Engine version 16.3.0+0f4c62fea for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 24.2 ms for /home/burnsba/code/Intrinsics/Intrinsics.csproj.
Program.cs(22,42): error CS1503: Argument 1: cannot convert from 'long' to 'byte*' [/home/burnsba/code/Intrinsics/Intrinsics.csproj]
Program.cs(22,53): error CS1503: Argument 2: cannot convert from 'System.Runtime.Intrinsics.Vector128<long>' to 'System.Runtime.Intrinsics.Vector128<byte>' [/home/burnsba/code/Intrinsics/Intrinsics.csproj]
Build FAILED.
Program.cs(22,42): error CS1503: Argument 1: cannot convert from 'long' to 'byte*' [/home/burnsba/code/Intrinsics/Intrinsics.csproj]
Program.cs(22,53): error CS1503: Argument 2: cannot convert from 'System.Runtime.Intrinsics.Vector128<long>' to 'System.Runtime.Intrinsics.Vector128<byte>' [/home/burnsba/code/Intrinsics/Intrinsics.csproj]
0 Warning(s)
2 Error(s)
Time Elapsed 00:00:01.19
burnsba@debian:~/code/Intrinsics$ dotnet --version
3.0.100
How am I supposed to use Sse2.StoreAlignedNonTemporal
?