Here is my method:
// can change
DWORD step[2] = { 0xAC, 0x723A };
packageType = 1;
DWORD computeLevel(DWORD blockNum)
{
DWORD num = (blockNum / 0x70E4) * step[1];
if (blockNum < 0x70E4)
return num + step[0];
return (1 << packageType) + num;
}
I am trying to optimize this for speed, as it gets called about 300,000 times and one little operation could add alot of time on. If I change the blockStep to just constant values, this makes it much, much faster. The problem is, is that they can change so I cannot make it const. Also, if I just have it return a straight up 0, no comparisons, it saves my code around 1 minute, 30 seconds, so this function is really slowing me down.
Also, it would be nice if this function could also be enhanced. I already tried by best, but it would be great if it can get better.
DWORD computeLevel0(DWORD blockNum)
{
WORD quotient1 = (blockNum / 0xAA);
BYTE quotient2 = (blockNum / 0x70E4);
DWORD num = quotient1 * 0xAC;
// optimizations (0 comparison)
WORD mult1 = quotient1;
mult1 |= mult1 >> 8;
mult1 |= mult1 >> 4;
mult1 |= mult1 >> 2;
mult1 |= mult1 >> 1;
mult1 &= 1;
BYTE mult2 = quotient2;
mult2 |= mult2 >> 4;
mult2 |= mult2 >> 2;
mult2 |= mult2 >> 1;
mult2 &= 1;
num += ((quotient2 + 1) << packageType) * mult1;
num += (((1 << packageType)) * mult2) * mult1;
return num;
}
step
array out of bounds). Fix those bugs first. \$\endgroup\$