I have 7 bytes whose values are used to form a vector in a lookup table. They must be sorted low-high or high-low. Each byte contains a value from 0-12. I need to sort these quickly because this function is performed millions of times per second. I think that MMX or other extended instruction sets can process it faster, but I don't have much experience with them. What technique might I use to quickly sort these byte values?

Currently the code is:

mov ecx, 7;
mov edi, ;

// input: ecx = number of array elements (dword array)
//          edi = array pointer

sort:
    lea ebx,
    mov eax,
cmploop:
    sub ebx, 4;
    lea ebx,
    cmp eax,
    jle notyet
    xchg eax,
notyet:
    cmp ebx,edi
    jnz cmploop
    stosd
    loop sort
Posted on 2007-05-11 15:06:27 by BinaryMan
First, you should decide which algorithm to use. Wrong algorithm (even if written with MMX/SSE) will execute slower than a decent one. For such small arrays I suggest Insertion Sort or bubble sort, or pancake sort.
Posted on 2007-05-11 15:21:47 by ti_mo_n