Skip to content

Commit

Permalink
Use IsPowerOf2 in Integer::Divide
Browse files Browse the repository at this point in the history
  • Loading branch information
noloader committed Feb 5, 2019
1 parent b09ca89 commit 4853178
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion integer.cpp
Expand Up @@ -4244,7 +4244,9 @@ void Integer::Divide(word &remainder, Integer &quotient, const Integer &dividend
if (!divisor)
throw Integer::DivideByZero();

if ((divisor & (divisor-1)) == 0) // divisor is a power of 2
// IsPowerOf2 uses BMI on x86 if available. There is a small
// but measurable improvement during decryption and signing.
if (IsPowerOf2(divisor))
{
quotient = dividend >> (BitPrecision(divisor)-1);
remainder = dividend.reg[0] & (divisor-1);
Expand Down

0 comments on commit 4853178

Please sign in to comment.