Skip to main content

Applying Sorting Networks to Synthesize Optimized Sorting Libraries

  • Conference paper
  • First Online:
Logic-Based Program Synthesis and Transformation (LOPSTR 2015)

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

Abstract

This paper presents an application of the theory of sorting networks to facilitate the synthesis of 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. This enables further program transformations based on sorting network optimizations, and eventually the synthesis of code from sorting networks. We show that, if considering the number of comparisons and swaps, the theory predicts no 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. We provide empirical evidence that using code synthesized from efficient sorting networks as the base case for Quicksort libraries results in significant real-world speed-ups.

Supported by the Israel Science Foundation, grant 182/13 and by the Danish Council for Independent Research, Natural Sciences.

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

Access this chapter

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 EPUB and 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

Notes

  1. 1.

    For details on these features of modern microarchitectures see e.g. [6, 15].

  2. 2.

    See https://graphics.stanford.edu/~seander/bithacks.html#SwappingValuesXOR.

  3. 3.

    See https://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax.

References

  1. Bundala, D., Závodný, J.: Optimal sorting networks. In: Dediu, A.-H., Martín-Vide, C., Sierra-Rodríguez, J.-L., Truthe, B. (eds.) LATA 2014. LNCS, vol. 8370, pp. 236–247. Springer, Heidelberg (2014)

    Chapter  Google Scholar 

  2. Codish, M., Cruz-Filipe, L., Frank, M., Schneider-Kamp, P.: Twenty-five comparators is optimal when sorting nine inputs (and twenty-nine for ten). In: ICTAI 2014, pp. 186–193. IEEE, December 2014

    Google Scholar 

  3. Codish, M., Cruz-Filipe, L., Schneider-Kamp, P.: The quest for optimal sorting networks: efficient generation of two-layer prefixes. In: Winkler, F., Negru, V., Ida, T., Jebelan, T., Petcu, D., Watt, S.M., Zaharie, D., (eds.) SYNASC 2014, pp. 359–366. IEEE (2015)

    Google Scholar 

  4. Codish, M., Cruz-Filipe, L., Schneider-Kamp, P.: Sorting networks: the end game. In: Dediu, A.-H., Formenti, E., Martín-Vide, C., Truthe, B. (eds.) LATA 2015. LNCS, vol. 8977, pp. 664–675. Springer, Heidelberg (2015)

    Google Scholar 

  5. Ehlers, T., Müller, M.: New bounds on optimal sorting networks. In: Beckmann, A., Mitrana, V., Soskova, M. (eds.) CiE 2015. LNCS, vol. 9136, pp. 167–176. Springer, Heidelberg (2015)

    Chapter  Google Scholar 

  6. Fisher, J.A., Faraboschi, P., Young, C.: Embedded Computing: A VLIW Approach to Architecture, Compilers, and Tools. Morgan Kaufman, San Francisco (2005)

    MATH  Google Scholar 

  7. Furtak, T., Amaral, J.N., Niewiadomski, R.: Using SIMD registers and instructions to enable instruction-level parallelism in sorting algorithms. In: SPAA 2007, pp. 348–357. ACM (2007)

    Google Scholar 

  8. Hoare, C.A.R.: Quicksort. Comput. J. 5(1), 10–15 (1962)

    Article  MathSciNet  MATH  Google Scholar 

  9. Knuth, D.E.: The Art of Computer Programming, Volume III: Sorting and Searching. Addison-Wesley, New York (1973)

    MATH  Google Scholar 

  10. Lopez, B., Cruz-Cortes, N.: On the usage of sorting networks to big data. In: Arabnia, H.R., Yang, M.Q., Jandieri, G., Park, J.J., Solo, A.M.G., Tinetti, F.G., (eds.) Advances in Big Data Analytics: The 2014 WorldComp International Conference Proceedings. Mercury Learning and Information (2014)

    Google Scholar 

  11. Parberry, I.: A computer-assisted optimal depth lower bound for nine-input sorting networks. Math. Syst. Theor. 24(2), 101–116 (1991)

    Article  MathSciNet  MATH  Google Scholar 

  12. Sedgewick, R.: The analysis of quicksort programs. Acta Inf. 7, 327–355 (1977)

    Article  MathSciNet  MATH  Google Scholar 

  13. Sedgewick, R., Flajolet, P.: An Introduction to the Analysis of Algorithms. Addison-Wesley-Longman, New York (1996)

    MATH  Google Scholar 

  14. Sedgewick, R., Wayne, K.: Algorithms, 4th edn. Addison-Wesley, Reading (2011)

    Google Scholar 

  15. Silc, J., Robic, B., Ungerer, T.: Processor Architecture: From Dataflow to Superscalar and Beyond. Springer, New York (1999)

    Book  MATH  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Luís Cruz-Filipe .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2015 Springer International Publishing Switzerland

About this paper

Cite this paper

Codish, M., Cruz-Filipe, L., Nebel, M., Schneider-Kamp, P. (2015). Applying Sorting Networks to Synthesize Optimized Sorting Libraries. In: Falaschi, M. (eds) Logic-Based Program Synthesis and Transformation. LOPSTR 2015. Lecture Notes in Computer Science(), vol 9527. Springer, Cham. https://doi.org/10.1007/978-3-319-27436-2_8

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-27436-2_8

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-27435-5

  • Online ISBN: 978-3-319-27436-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics