Close

Has anybody...

A project log for YAMS Yet Another Merge Sort

There are already so many sorting algorithms... So let's make another!

yann-guidon-ygdesYann Guidon / YGDES 08/20/2022 at 12:550 Comments

Has anybody merged runs from both ends ?

...

Merge sort is traditionally done from one end (usually the low one) to the other. But what can prevent us from doing it from both ends ?

The code is longer, sure, but modern OOOx processors have incredibly large windows of execution with more than a hundred instructions "in flight" at the same time so managing both ends at the same time would help "parallelise"  the execution and the only time both ends must re-sync is when they reach the middle of the output buffer.

Instant 2x speedup with little algorithmic change, who could refuse ?

.

.

.

Edit:

OK I see a situation where this would create problems : with runs of equal data so this is a special case to take into account.

Discussions