aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-08-18 17:08:13 +0000
committerlloyd <[email protected]>2006-08-18 17:08:13 +0000
commitf0a67e294fed993981ea215b899ac61fe89eba33 (patch)
tree63a4d6555d08abc7ed2271308aa54403e6496ef8
parent914a5c0c3200073c95d510e14150da81d2eac105 (diff)
Simplify the implementation of bigint_divop
-rw-r--r--src/mp_misc.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/mp_misc.cpp b/src/mp_misc.cpp
index f551948b7..0ccb4314c 100644
--- a/src/mp_misc.cpp
+++ b/src/mp_misc.cpp
@@ -56,21 +56,23 @@ s32bit bigint_cmp(const word x[], u32bit x_size,
*************************************************/
word bigint_divop(word n1, word n0, word d)
{
- word high = n1 % d;
- word quotient = 0;
+ word high = n1 % d, quotient = 0;
+
for(u32bit j = 0; j != MP_WORD_BITS; ++j)
{
- const word mask = (word)1 << (MP_WORD_BITS-1-j);
- const bool high_top_bit = (high & MP_WORD_TOP_BIT) ? true : false;
+ const bool high_top_bit = (high & MP_WORD_TOP_BIT);
- high = (high << 1) | ((n0 & mask) >> (MP_WORD_BITS-1-j));
+ high <<= 1;
+ high |= (n0 >> MP_WORD_BITS-1-j) & 1;
+ quotient <<= 1;
if(high_top_bit || high >= d)
{
high -= d;
- quotient |= mask;
+ quotient |= 1;
}
}
+
return quotient;
}