Skip to search boxSkip to navigationSkip to main content

Optimizing Sorting Algorithms by Using Sorting Networks

  • Michael Codish
    ,
  • Luis Cruz-Filipe
    ,
  • Markus Nebel
    ,
  • Peter Schneider-Kamp
  • Ben-Gurion University of the Negev
    ,
  • University of Southern Denmark
Research Output:
Journal Article or Conference Article in Journal
Journal article
Peer-review

Open access

Publication Information

Output type

Research Output:
Journal Article or Conference Article in Journal
Journal article
Peer-review

Original language

English

Pages from-to (Number of pages)

Pages 559-579 (21 pages)

Journal (Volume, Issue Number)

Formal Aspects of Computing (Volume 29, Issue 3)

Publication milestones

  • Published - 01/05/2017

Publication status

Published - 01/05/2017

ISSN

0934-5043

Publication IDs

  • Scopus: 84994504826

Abstract

In this paper, we show how the theory of sorting networks can be applied to synthesize optimized general-purpose sorting libraries. Standard sorting libraries are often based on combinations of the classic Quicksort algorithm, with insertion sort applied as base case for small, fixed, numbers of inputs. Unrolling the code for the base case by ignoring loop conditions eliminates branching, resulting in code equivalent to a sorting network. By replacing it with faster sorting networks, we can improve the performance of these algorithms. We show that by considering the number of comparisons and swaps alone we are not able to predict any real advantage of this approach. However, significant speed-ups are obtained when taking advantage of instruction level parallelism and non-branching conditional assignment instructions, both of which are common in modern CPU architectures. Furthermore, a close control of how often registers have to be spilled to memory gives us a complete explanation of the performance of different sorting networks, allowing us to choose an optimal one for each particular architecture. Our experimental results show that using code synthesized from these efficient sorting networks as the base case for Quicksort libraries results in significant real-world speed-ups.

Publication metrics

PlumX, opens in new tab

Citations
5
Captures
6