I'm working on program which has to repetitively compute:
uint64_t funct()
{
if(x & 1)
{
x=(x * a + b) >> 1;
}
else
{
x=(x >> 1) * c + d;
}
return x;
}
But it is about 2 times slower than just:
uint64_t funct()
{
x=(x * a + b) >> 1;
return x;
}
a,b,c,d,x are some 64-bit numbers and x is randomly odd or even. In general I wouldn't expect this, because the main operation in both cases is multiplication with addition. I don't understand why simple condition slows it down twice.
Can it be done somehow faster?