Because in branchless quicksort, no matter how long it takes to figure out where the element has to go relative to the pivot it doesn't obstruct the CPU's ability in this algorithm to start working on the next element the next cycle.
27 karma · joined May 30, 2020
Because in branchless quicksort, no matter how long it takes to figure out where the element has to go relative to the pivot it doesn't obstruct the CPU's ability in this algorithm to start working on the next element the next cycle.
Here is an implementation. This should work with all types. Unfortunate I had to annotate with restrict, but a small price to pay.
Certainly this is worth an experiment
This amplifies the the strength of each scheme and mitigates the weakness. Ie. Lomuto does too many swaps, but naturally fits a branchfree implementation. Hoare is frugal with swaps, but is rather branchy. The "hybrid" here inherits the frugality of swaps from Hoare's scheme, while benefits from the branchfree implementation of Lomuto scheme.
What you seem to describe here is the classical and well-known hybridization of divide and conquer algorithms. This is also used and implicitly implied when branchless bubble sort is discussed. But the "hybrid" as used in the article wasn't meant to refer to this.
As I mention in the article, dependency analysis has, IMO, not received the widespread attention it should. I like Fabian Giesen's article if you want an introduction.
https://fgiesen.wordpress.com/2018/03/05/a-whirlwind-introdu...
BM_IndirectionSort<1, std_sort> 93 ns 93 ns 7700000
BM_IndirectionSort<1, std_stable_sort> 126 ns 125 ns 5600000
BM_IndirectionSort<1, std_heap_sort> 172 ns 172 ns 4200000
BM_IndirectionSort<1, exp_gerbens::QuickSort> 34 ns 34 ns 19000000
BM_IndirectionSort<1, HeapSort> 157 ns 157 ns 4700000
BM_IndirectionMergeSort<1> 68 ns 68 ns 10400000
BM_IndirectionSort<0, std_sort> 74 ns 74 ns 9500000
BM_IndirectionSort<0, std_stable_sort> 91 ns 91 ns 7800000
BM_IndirectionSort<0, std_heap_sort> 125 ns 125 ns 5800000
BM_IndirectionSort<0, exp_gerbens::QuickSort> 26 ns 26 ns 27200000
BM_IndirectionSort<0, HeapSort> 77 ns 77 ns 9300000
BM_IndirectionMergeSort<0> 36 ns 36 ns 19400000