Zoran Vasiljevic schrieb:
Guess what: it is _slower_ now then the
s = (size-1) >> 3;
while (s>1) {s >>= 1; bucket++;}
I tend to like that one as it is really neat.
It will also better illustrate what is being
done.
this is the last for today. It is the unrolled variant, with less tests,
and still human readable. It should be faster than the unrolled
while variants....
-gustaf
{ unsigned register int s = (size-1) >> 4;
while (s >= 0x1000) {
s >>= 12;
bucket += 12;
}
if (s >= 0x0800) { s >>= 11; bucket += 11; } else
if (s >= 0x0400) { s >>= 10; bucket += 10; } else
if (s >= 0x0200) { s >>= 9; bucket += 9; } else
if (s >= 0x0100) { s >>= 8; bucket += 8; } else
if (s >= 0x0080) { s >>= 7; bucket += 7; } else
if (s >= 0x0040) { s >>= 6; bucket += 6; } else
if (s >= 0x0020) { s >>= 5; bucket += 5; } else
if (s >= 0x0010) { s >>= 4; bucket += 4; } else
if (s >= 0x0008) { s >>= 3; bucket += 3; } else
if (s >= 0x0004) { s >>= 2; bucket += 2; } else
if (s >= 0x0002) { s >>= 1; bucket += 1; }
if (s >= 1) {
bucket++;
}
if (bucket > NBUCKETS) {
bucket = NBUCKETS;
}
}
#