For fast MTF ( http://en.wikipedia.org/wiki/Move-to-front_transform ) I need a faster version of moving char from inside the array to the front
char mtfSymbol[256], front;
char i;
for(;;) { \\ a very big loop
...
i=get_i(); \\ i is in 0..256 but more likely to be smaller.
front=mtfSymbol[i];
memmove(mtfSymbol+1, mtfSymbol, i);
mtfSymbol[0]=front;
}
cachegrind shows that there are many dummy predictions for memmove.
For a different version of the code (not memmove in the first example, except this one)
do
{
mtfSymbol[i] = mtfSymbol[i-1];
} while ( --i );
there are many read / write bytes, conditional branches and incorrect branch predictions
i is not very large, since MTF is used for "good" input - a text file after BWT (Burrows-Wheeler conversion)
The compiler is GCC.
source
share