Skip to content

Instantly share code, notes, and snippets.

View Turnerj's full-sized avatar

James Turner Turnerj

View GitHub Profile
@Turnerj
Turnerj / Adler32.cs
Created April 30, 2020 08:23
Adler32 C# with Intrinsics (Not Passing Tests)
// Copyright (c) Six Labors and contributors.
// See LICENSE for more details.
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#if NETCOREAPP3_1
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
#endif
@Turnerj
Turnerj / Levenshtein.FullBranchlessV3.cs
Created March 6, 2020 08:36
Third attempt - still not as good as still having branches
/// <summary>
/// Using SSE4.1, calculates the costs for the virtual matrix.
/// This performs a 4x outer loop unrolling allowing fewer lookups of target character and deletion cost data across the rows.
/// </summary>
/// <param name="previousRowPtr"></param>
/// <param name="source"></param>
/// <param name="rowIndex"></param>
/// <param name="targetPtr"></param>
/// <param name="targetLength"></param>
private static unsafe void CalculateRows_4Rows_Sse41(int* previousRowPtr, ReadOnlySpan<char> source, ref int rowIndex, char* targetPtr, int targetLength)
@Turnerj
Turnerj / Levenshtein.Intrinsics.cs
Created February 14, 2020 07:20
Second attempt - probably just as bad as my first, code is neater though.
#if NETCOREAPP3_0
using System;
using System.Buffers;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics.X86;
using System.Runtime.Intrinsics;
namespace Quickenshtein
{
/// <summary>
@Turnerj
Turnerj / Levenshtein.Avx.cs
Created February 5, 2020 14:40
A really really terrible (but worth while keeping around) version of an AVX Levenshtein calculator
#if NETCOREAPP3_0
using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
namespace Quickenshtein
{
public static partial class Levenshtein
{
@Turnerj
Turnerj / OneOrMany.cs
Created December 19, 2019 07:17
OneOrMany using Array-only
namespace Schema.NET
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
/// <summary>
/// A single or list of values.
/// </summary>
@Turnerj
Turnerj / ThingJsonConverter.cs
Created December 1, 2019 04:53
Custom "Thing" converter for Schema.NET
namespace Schema.NET
{
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;