• Stars
    star
    99
  • Rank 341,760 (Top 7 %)
  • Language
    C#
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Make QuickSort Quick Again in C#

VxSort Build NuGet

VxSort is a repository that contains both the code accompanying the This goes to Eleven blog post series by @damageboy.

In addition, this repository contains the source code for the NuGet package by the same name that provides a ready to use implementation for sorting with managed code at a much higher speeds than what is currently possible with CoreCLR 3.0.

Usage

Add with Nuget.

using VxSort;

// ...
var r = new Random((int) DateTime.UtcNow.Ticks);
int[] lotOfNumbers = Enumerable.Repeat(100_000_000).Select(r.NextInt()).ToArray();

VectorizedSort.Sort(lotsOfNumbers);

// Wow

Roadmap to 1.0

Currently, VxSort is very feature-less, Here's what it can do:

  • Sort 32-bit integers, ascending

Here's what's missing, in terms of functionality, and the order at which it should probably be implemented:

  • Primitive Support:
    • Add 32-bit descending support: #2
    • Add 32-unsigned ascending support]: #3 (slightly tricky):
      • There is no direct unsigned support in AVX2, e.g. we have:
        _mm256_cmpgt_epi32(__m256i a, __m256i b) / CompareGreaterThan(Vector256<Int32>, Vector256<Int32>
        but no unsigned variant for the comparison operation.
      • Instead we could:
        • Perform a fake descending partition operation around the value 0, where all >= 0 are on the left, and all "fake" < 0 values (e.g what is really unsigned values with the top bit set...) go to the right.
        • Procees to partition with ascending semantics the left portion, while partitioning with descensing semantics the right
        • (Unsigned) Profit!
    • Add 32-bit unsigned descending support.
    • Add 64-bit signed/unsigned ascending/descending support.
    • Support 32/64 bit floating point sorting.
      • Try to generalize the 32/64-bit support with generic wrappers to avoid code duplication
    • 16 bit support (annoying since there is no 16 bit permute so perf will go down doing 16 -> 32 bit and back)
    • 8 bit support (annoying since there is no 8 bit permute so perf will go down doing 16 -> 32 bit and back)
  • Key/Value Sorting:
    • Add a stable variant, tweaking the current double-pumped loop and switching to PCSort for stable sorting.
      This is substantially slower, but such is life
    • Add an explicit unstable variant of sorting, for those who don't care/need it
  • IComparer<T>/Comparison<T> -like based vectorized sorting:
    • In general, all hope is lost if IComparer<T>/Comparison<T> or anything of that sort is provided.
    • Unless the IComparer<T>/Comparison<T> is essentially some sort of a trivial/primitive "compare the struct/class by comparing member X, For example:
      An IComparer<T>/Comparison<T> that is using the 3rd member of T which is at a constant offset of 10-bytes into the T strcut/class.
    • Those sorts of trivial IComparer<T>/Comparison<T> could be actually solved for with a AVX2 gather operation:
      gather all the keys at a given offset and performs the regular vectorized sorting.
    • This would require a new type of API where the user provides (perhaps?) an Expression<Func> that performs the key selection, that could be "reverse-engineered" to understand if the expression tree can be reduced to an AVX2 gather operation and so on...
  • General / Good practices?:
    • Transition to code-generating AVX2 Bitonic sorting to avoid maintaining source files with thousands of source lines that could be instead machine generated.

Credits

VxSort is based on the following ideas/papers:

VxSort uses the following projects:

Author

Dan Shechter, a.k.a @damageboy

More Repositories

1

vxsort-cpp

My very own vxsort re-implemented with "modern" C++ by a complete idiot (in C++)
C++
30
star
2

yaap

.NET version of python's excellent tqdm (https://github.com/tqdm/tqdm)
C#
30
star
3

daemaged.ibnet

Interactive Brokers Client API in .NET
C#
23
star
4

ReJit

Add x64 intrinsics to .NET through the use of ungodly hacks
C#
16
star
5

uftp

uftp
C
16
star
6

daemaged.compression

An algemation of zlib + bzip + liblzma + lzo2 + lz4 native compression libs into one .NET Wrappers
C#
12
star
7

daemaged.gitinfoplanter

Plant Git Information into .NET Assemblies using Mono.Cecil
F#
11
star
8

OpenFAST

A fork/clone of the OpenFAST project from sourceforge for the purpose of updating it to 2015 and pushing artifacts to NuGet
C#
10
star
9

daemaged.inlineil

Provide a post-compiler capable of inserting IL snippets embedded in C#/VB into a managed assembly
C#
8
star
10

bitgoo

C++
8
star
11

memorymodule-net

Implementation of the MemoryModule project in pure .NET...
C#
6
star
12

daemaged.ntp

NTP Client Implementation for .NET / C#
C#
6
star
13

ConcurrentList

A set of improvements on Daniel Tao's ConcurreltList
C#
4
star
14

daemaged.managedhell

A Collection of unsafe, implementation dependant .NET code that will get you sent straight to managed hell for using it...
C#
3
star
15

shame

my stab at https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/knucleotide.html
C#
3
star
16

distorm-net

distorm-net
C
2
star
17

lzo2

gitified public code-drops from lzo2
C
2
star
18

interopcost

Test the cost of Managed/Native Interop in .NET / C++
C#
1
star
19

remark-autonumber

JavaScript
1
star
20

cmake-kernel-module-ninja

C
1
star
21

coreclr-intrinsics-workshop

coreclr-intrinsics-workshop
C#
1
star
22

datetime-deconstruct

C#
1
star
23

daemaged.referencereplacer

.NET Post compilation utility to fixup assembly references to assemblies that were merged with ILMerge / Mono.Linker etc.
F#
1
star
24

damageboy.github.io

a series a charchters
JavaScript
1
star
25

csmatio

C#
1
star