Convert String Value to Operator in C#

Using SSE in c# is it possible?

The upcoming Mono 2.2 release will have SIMD support. Miguel de Icaza blogged about the upcoming feature here, and the API is here.

Although there will be a library that will support development under Microsoft's .NET Windows runtime, it will not have the performance benefits that you are looking for unless you run the code under the Mono runtime. Which might be doable depending on your circumstances.

Update: Mono 2.2 is released

Using SSE in C#

Open-source Yeppp! library (of which I am the author) provides SIMD-optimized data processing functions, and is usable from .Net languages via official bindings. It supports not only SSE, but also later SIMD extensions up to AVX2 from the upcoming Intel Haswell processors. The library automatically chooses the optimal version for the processor it runs on.

Implement sending Server Sent Events in C# (no ASP.NET / MVC / ...)

This sounds like a good fit for SignalR. Note SignalR is part of the ASP.NET family, however this does NOT require the ASP.NET framework (System.Web), or IIS, as mentioned in comments.

To clarify, SignalR is part of ASP.NET. According to their site:

ASP.NET is an open source web framework for building modern web apps
and services with .NET. ASP.NET creates websites based on HTML5, CSS,
and JavaScript that are simple, fast, and can scale to millions of
users.

SignalR has no hard dependency on System.Web or on IIS.

You can self-host your ASP.Net application (see https://learn.microsoft.com/en-us/aspnet/signalr/overview/deployment/tutorial-signalr-self-host). If you use .net core, it is actually self-hosted by default and runs as a normal console application.

Using SSE 4.2 crc32 algorithm in c# ? Is it possible?

Nowadays we've been spoiled with the System.Runtime.Intrinsics.X86 namespace available in .NET Core 3.0. Here's the full implementation of the CRC32-C algorithm using SSE 4.2:

using System;
using System.Runtime.Intrinsics.X86;
using System.Security.Cryptography;

/// <summary>
/// The hardware implementation of the CRC32-C polynomial
/// implemented on Intel CPUs supporting SSE4.2.
/// </summary>
public class Crc32HardwareAlgorithm : HashAlgorithm
{
/// <summary>
/// the current CRC value, bit-flipped
/// </summary>
private uint _crc;

/// <summary>
/// We can further optimize the algorithm when X64 is available.
/// </summary>
private bool _x64Available;

/// <summary>
/// Default constructor
/// </summary>
public Crc32HardwareAlgorithm()
{
if (!Sse42.IsSupported)
{
throw new NotSupportedException("SSE4.2 is not supported");
}

_x64Available = Sse42.X64.IsSupported;

// The size, in bits, of the computed hash code.
this.HashSizeValue = 32;
this.Reset();
}

/// <summary>When overridden in a derived class, routes data written to the object into the hash algorithm for computing the hash.</summary>
/// <param name="array">The input to compute the hash code for.</param>
/// <param name="ibStart">The offset into the byte array from which to begin using data.</param>
/// <param name="cbSize">The number of bytes in the byte array to use as data.</param>
protected override void HashCore(byte[] array, int ibStart, int cbSize)
{
if (_x64Available)
{
while (cbSize >= 8)
{
_crc = (uint)Sse42.X64.Crc32(_crc, BitConverter.ToUInt64(array, ibStart));
ibStart += 8;
cbSize -= 8;
}
}

while (cbSize > 0)
{
_crc = Sse42.Crc32(_crc, array[ibStart]);
ibStart++;
cbSize--;
}
}

/// <summary>When overridden in a derived class, finalizes the hash computation after the last data is processed by the cryptographic stream object.</summary>
/// <returns>The computed hash code.</returns>
protected override byte[] HashFinal()
{
uint outputCrcValue = ~_crc;

return BitConverter.GetBytes(outputCrcValue);
}

/// <summary>Initializes an implementation of the <see cref="T:System.Security.Cryptography.HashAlgorithm"></see> class.</summary>
public override void Initialize()
{
this.Reset();
}

private void Reset()
{
_crc = uint.MaxValue;
}
}

No overflow exception thrown for long/ulong SSE addition in C#?

Below is an implementation of ulong summation using SSE in C#. I'm posting it, since it's quite a bit shorter and easier to understand than the long summation.

private static decimal SumToDecimalSseFasterInner(this ulong[] arrayToSum, int l, int r)
{
decimal overallSum = 0;
var sumVector = new Vector<ulong>();
var newSumVector = new Vector<ulong>();
var zeroVector = new Vector<ulong>(0);
int sseIndexEnd = l + ((r - l + 1) / Vector<ulong>.Count) * Vector<ulong>.Count;
int i;

for (i = l; i < sseIndexEnd; i += Vector<ulong>.Count)
{
var inVector = new Vector<ulong>(arrayToSum, i);
newSumVector = sumVector + inVector;
Vector<ulong> gteMask = Vector.GreaterThanOrEqual(newSumVector, sumVector); // if true then 0xFFFFFFFFFFFFFFFFL else 0L at each element of the Vector<long>
if (Vector.EqualsAny(gteMask, zeroVector))
{
for(int j = 0; j < Vector<ulong>.Count; j++)
{
if (gteMask[j] == 0) // this particular sum overflowed, since sum decreased
{
overallSum += sumVector[j];
overallSum += inVector[ j];
}
}
}
sumVector = Vector.ConditionalSelect(gteMask, newSumVector, zeroVector);
}
for (; i <= r; i++)
overallSum += arrayToSum[i];
for (i = 0; i < Vector<ulong>.Count; i++)
overallSum += sumVector[i];
return overallSum;
}

Both ulong[] and long[] summations using SSE and accumulating to Decimal, to produce a perfectly accurate result have been added to the HPCsharp nuget package that I maintain (open source). The version for long[] is in SumParallel.cs and is called SumToDecimalSseFasterInner().

It's pretty cool to be able to sum long[] or ulong[] arrays using SSE, handling arithmetic overflow in SSE, since the CPU doesn't produce overflow flags for SSE, and do it at SSE speeds, and multi-core!

Receive Server Sent Events (SSE) in UWP

I found a solution here https://techblog.dorogin.com/server-sent-event-aspnet-core-a42dc9b9ffa9.
The trick was to not set up a WebAPI-call that continuously returns data like in the question but to create a data-strem with the MIME-type text/event-stream.

On the UWP client side you then read the stream like this:

var stream = httpClient.GetStreamAsync(requestUri).Result;

using (var reader = new StreamReader(stream))
{
while (!reader.EndOfStream)
{
Debug.WriteLine(reader.ReadLine());
}
}


Related Topics



Leave a reply



Submit