Skip to content

Instantly share code, notes, and snippets.

View Mrnikbobjeff's full-sized avatar

Niklas Schilli Mrnikbobjeff

View GitHub Profile
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
public unsafe static int GreaterThanSimd_Avx2_u(int boundary,ref ReadOnlySpan<int> array)
{
Vector128<int> xmm1 = Vector128.Create(boundary);
Vector128<int> xmm2 = Vector128<int>.Zero;
Vector128<int> xmm3;
Vector128<int> xmm4;
ref int start = ref MemoryMarshal.GetReference(array);
for (nuint i = 0; i < (nuint)array.Length; i += 4)
create table Users(
user_id INT NOT NULL AUTO_INCREMENT,
user_name VARCHAR(40) NOT NULL,
PRIMARY KEY ( user_id )
);
create table Documents(
doc_id INT NOT NULL AUTO_INCREMENT,
originalname VARCHAR(400) NOT NULL,
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
// we have a valid GUID, so handle the task
if (!string.IsNullOrEmpty(guid) && pendingTasks.TryRemove(guid, out var tcs) && tcs != null)
{
if (resultCode == Result.Canceled)
{
tcs.TrySetCanceled();
using System.Buffers;
using System.IO;
using System.Threading.Tasks;
using AppKit;
using CoreGraphics;
using CoreImage;
using Foundation;
using ImageIO;
using MobileCoreServices;

Hi, my name is Niklas Schilli. I am a .Net fanatic, a student and am loooking for opportunities to work in high-performance scenarios

internal class NoReturn<TReturn, TException> where TException : Exception
{
static NoReturn()
{
bool GetCorrectConstructor(ParameterInfo[] parameters) => parameters.Length == 1 && parameters[0].ParameterType == typeof(string);
var constructors = typeof(TException).GetConstructors();
var target = Expression.Label();
var constructor = constructors.Single(c => GetCorrectConstructor(c.GetParameters()));
var messageExpression = Expression.Parameter(typeof(string), "message");
var newException = Expression.New(constructor, messageExpression);
@Mrnikbobjeff
Mrnikbobjeff / AllocationProof.cs
Last active November 25, 2019 18:47
It can allocate more :O
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace AllocationBenchmark
{
[DryCoreJob, DryClrJob]
[MemoryDiagnoser]
public class FormatAllocation
{
[Benchmark]
@Mrnikbobjeff
Mrnikbobjeff / AvxNullFind.cs
Last active September 21, 2020 10:57
quick hacky way to find null references
using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using System.Threading;
namespace ObjectPools
{
public class FastRefPool<T> where T : class
{
public unsafe int FreeFasterSimplifiedAsmAlignedNonTemporalUnrolledUnsafePin(T obj)
{
var items = _items;
var length = items.Length;
var nullVector = Vector256<long>.Zero;
fixed (long* addrPtr = &itemsRef[0])
{
var aligned = (long*)(((ulong)addrPtr + 31UL) & ~31UL);
var pos = (int)(aligned - addrPtr);
for (int w = 0; w < pos; w++)