Affiliation:
1. Trinity College Dublin, Ireland
Abstract
Sorting is one of the most important and well-studied problems in computer science. Many good algorithms are known which offer various trade-offs in efficiency, simplicity, memory use, and other factors. However, these algorithms do not take into account features of modern computer architectures that significantly influence performance. Caches and branch predictors are two such features and, while there has been a significant amount of research into the cache performance of general purpose sorting algorithms, there has been little research on their branch prediction properties. In this paper, we empirically examine the behavior of the branches in all the most common sorting algorithms. We also consider the interaction of cache optimization on the predictability of the branches in these algorithms. We find insertion sort to have the fewest branch mispredictions of any comparison-based sorting algorithm, that bubble and shaker sort operate in a fashion that makes their branches highly unpredictable, that the unpredictability of shellsort's branches improves its caching behavior, and that several cache optimizations have little effect on mergesort's branch mispredictions. We find also that optimizations to quicksort, for example the choice of pivot, have a strong influence on the predictability of its branches. We point out a simple way of removing branch instructions from a classic heapsort implementation and also show that unrolling a loop in a cache-optimized heapsort implementation improves the predicitability of its branches. Finally, we note that when sorting random data two-level adaptive branch predictors are usually no better than simpler bimodal predictors. This is despite the fact that two-level adaptive predictors are almost always superior to bimodal predictors, in general.
Publisher
Association for Computing Machinery (ACM)
Subject
Theoretical Computer Science
Reference38 articles.
1. A super scalar sort algorithm for RISC processors
2. The input/output complexity of sorting and related problems
3. Austin T. Ernst D. Larson E. Weaver C. Raj Desikan R. N. Huh J. Yoder B. Burger D. and Keckler S. 2001. SimpleScalar Tutorial (for release 4.0). Austin T. Ernst D. Larson E. Weaver C. Raj Desikan R. N. Huh J. Yoder B. Burger D. and Keckler S. 2001. SimpleScalar Tutorial (for release 4.0).
4. Engineering a sort function
Cited by
5 articles.
订阅此论文施引文献
订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献
1. BlockQuicksort;ACM Journal of Experimental Algorithmics;2019-12-17
2. Ternary-Decimal Exclusion Algorithm for Multiattribute Utility Functions;Lecture Notes in Computer Science;2019
3. When Merging and Branch Predictors Collide;2014 4th Workshop on Irregular Applications: Architectures and Algorithms (IA^3);2014-11-16
4. Branch Mispredictions Don’t Affect Mergesort;Experimental Algorithms;2012
5. Lean Programs, Branch Mispredictions, and Sorting;Lecture Notes in Computer Science;2012