Fastest sort of fixed length 6 int array

Posted by kriss on Stack Overflow See other posts from Stack Overflow or by kriss
Published on 2010-05-07T07:24:45Z Indexed on 2010/05/07 7:28 UTC
Read the original article Hit count: 401

Filed under:
|
|
|

Answering to another StackOverflow question (this one) I stumbled upon an interresting sub-problem. What is the fastest way to sort an array of 6 ints ?

As the question is very low level (will be executed by a GPU):

  • we can't assume libraries are available (and the call itself has it's cost), only plain C
  • to avoid emptying instruction pipeline (that has a very high cost) we should probably minimize branches, jumps, and every other kind of control flow breaking (like those hidden behind sequence points in && or ||).
  • room is constrained and minimizing registers and memory use is an issue, ideally in place sort is probably best.

Really this question is a kind of Golf where the goal is not to minimize source length but execution speed. I call it 'Zening` code as used in the title of the book Zen of Code optimization by Michael Abrash and it's sequels.

© Stack Overflow or respective owner

Related posts about c

    Related posts about algorithm