Nothing Special   »   [go: up one dir, main page]

Skip to main content

Lean Programs, Branch Mispredictions, and Sorting

  • Conference paper
Fun with Algorithms (FUN 2012)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 7288))

Included in the following conference series:

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 O(κt(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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Similar content being viewed by others

References

  1. Aho, A.V., Lam, M.S., Sethi, R., Ullman, J.D.: Compilers: Principles, Techniques, & Tools, 2nd edn. Pearson Education, Inc., Boston (2007)

    Google Scholar 

  2. Biggar, P., Nash, N., Williams, K., Gregg, D.: An experimental study of sorting and branch prediction. ACM J. Exp. Algorithmics 12, Article 1.8 (2008)

    Google Scholar 

  3. Brodal, G., Moruz, G.: Tradeoffs Between Branch Mispredictions and Comparisons for Sorting Algorithms. In: Dehne, F., López-Ortiz, A., Sack, J.-R. (eds.) WADS 2005. LNCS, vol. 3608, pp. 385–395. Springer, Heidelberg (2005)

    Chapter  Google Scholar 

  4. Floyd, R.W.: Algorithm 245: Treesort 3. Commun. ACM 7(12), 701 (1964)

    Article  Google Scholar 

  5. Harel, D.: On folk theorems. Commun. ACM 23(7), 379–389 (1980)

    Article  MATH  Google Scholar 

  6. Katajainen, J., Träff, J.L.: A Meticulous Analysis of Mergesort Programs. In: Bongiovanni, G., Bovet, D.P., Di Battista, G. (eds.) CIAC 1997. LNCS, vol. 1203, pp. 217–228. Springer, Heidelberg (1997)

    Chapter  Google Scholar 

  7. Kernighan, B.W., Ritchie, D.M.: The C Programming Language, 2nd edn. Prentice Hall, Englewood Cliffs (1988)

    Google Scholar 

  8. Mortensen, S.: Refining the pure-C cost model. Master’s Thesis, Department of Computer Science. University of Copenhagen, Copenhagen (2001)

    Google Scholar 

  9. Patterson, D.A., Hennessy, J.L.: Computer Organization and Design, The Hardware/Software Interface, 4th edn. Morgan Kaufmann Publishers, Burlington (2009)

    Google Scholar 

  10. Sanders, P., Winkel, S.: Super Scalar Sample Sort. In: Albers, S., Radzik, T. (eds.) ESA 2004. LNCS, vol. 3221, pp. 784–796. Springer, Heidelberg (2004)

    Chapter  Google Scholar 

  11. Sedgewick, R.: Algorithms in C++, Parts 1–4: Fundamentals, Data Structures, Sorting, Searching, 3rd edn. Addison-Wesley Publishing Company, Inc., Reading (1998)

    Google Scholar 

  12. Williams, J.W.J.: Algorithm 232: Heapsort. Commun. ACM 7(6), 347–348 (1964)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2012 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Elmasry, A., Katajainen, J. (2012). Lean Programs, Branch Mispredictions, and Sorting. In: Kranakis, E., Krizanc, D., Luccio, F. (eds) Fun with Algorithms. FUN 2012. Lecture Notes in Computer Science, vol 7288. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-30347-0_14

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-30347-0_14

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-30346-3

  • Online ISBN: 978-3-642-30347-0

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics