Branching in Rotate function
GoogleCodeExporter opened this issue · comments
I noticed the following code in the rotate function:
static uint64 Rotate(uint64 val, int shift)
{
// Avoid shifting by 64: doing so yields an undefined result.
return shift == 0 ? val : ((val >> shift) | (val << (64 - shift)));
}
Wouldn't it be faster to do an additional bitwise-and instead of introducing
branching? For example:
return ( (val >> shift) | ( val << ((64 - shift) & 63) ) );
Original issue reported on code.google.com by alfonsla...@gmail.com
on 13 Feb 2013 at 12:36
The way I use Rotate, the shift is always a manifest constant, so evaluating
"shift == 0" happens at compile time.
Original comment by gp...@google.com
on 20 Jun 2013 at 10:01
- Changed state: WontFix