I have two integral variables a
and b
and a constant s
resp. d
. I need to calculate the value of (a*b)>>s
I haven't exhaustively tested this, but could you do the division first, then account for the remainder, at the expense of extra operations? Since d
is a power of two, all the divisions can be reduced to bitwise operations.
For example, always assume a > b
(you want to divide the larger number first). Then a * b / d
= ((a / d) * b) + (((a % d) * b) / d)