Lean programs, branch mispredictions, and sorting
Authors:Amr Elmasry and Jyrki Katajainen
Published in:Proceedings of the 6th International Conference on Fun with Algorithms, Lecture Notes in Computer Science 7288, Springer-Verlag (2012), 119-130
Full text:<pdf.gif>PDF (285 kB)  
Copyright:© Springer-Verlag
Abstract:According to a folk theorem, every program can be transformed into a program that produces the same output and only has one loop. We generalize this to a form where the resulting program has one loop and no other branches than the one associated with the loop control. For this branch, branch prediction is easy even for a static branch predictor. If the original program is of length κ, measured in the number of assembly-language instructions, and runs in t(n) time for an input of size n, the transformed program is of length O(κ) and runs in Ot(n)) time. Normally sorting programs are short, but still κ may be too large for practical purposes. Therefore, we provide more efficient hand-tailored heapsort and mergesort programs. Our programs retain most features of the original programs—e.g. they perform the same number of element comparisons—and they induce O(1) branch mispredictions. On computers where branch mispredictions were expensive, some of our programs were, for integer data and small instances, faster than the counterparts in the GNU implementation of the C++ standard library.
Related:<html.gif>HTML (Slides)  <html.gif>HTML (Slides)  <html.gif>HTML (Source code)  
  author = {Amr Elmasry and Jyrki Katajainen},
  title = {Lean programs, branch mispredictions, and sorting},
  booktitle = {Proceedings of the 6th International Conference on Fun with
  series = {Lecture Notes in Computer Science},
  volume = {7288},
  publisher = {Springer-Verlag},
  year = {2012},
  pages = {119--130},
This page was generated by Jyrki Katajainen <jyrki@di.ku.dk> on 22.05.2015.