8 #include <botan/divide.h>
9 #include <botan/internal/mp_core.h>
10 #include <botan/internal/mp_madd.h>
19 void sign_fixup(
const BigInt& x,
const BigInt& y, BigInt& q, BigInt& r)
24 if(r.is_nonzero()) { --q; r = y.abs() - r; }
30 bool division_check(word q, word y2, word y1,
31 word x3, word x2, word x1)
41 if(y3 > x3)
return true;
42 if(y3 < x3)
return false;
44 if(y2 > x2)
return true;
45 if(y2 < x2)
return false;
47 if(y1 > x1)
return true;
48 if(y1 < x1)
return false;
72 int32_t compare = r.
cmp(y);
87 const size_t n = r.
sig_words() - 1, t = y_words - 1;
98 while(r > y) { r -= y; ++q; }
100 sign_fixup(x, y_arg, q, r);
106 while(r >= temp) { r -= temp; q_words[n-t] += 1; }
108 for(
size_t j = n; j != t; --j)
110 const word x_j0 = r.
word_at(j);
111 const word x_j1 = r.
word_at(j-1);
119 while(division_check(q_words[j-t-1],
137 sign_fixup(x, y_arg, q, r);
word word_at(size_t n) const
void divide(const BigInt &x, const BigInt &y_arg, BigInt &q, BigInt &r)
word bigint_divop(word n1, word n0, word d)
word word_madd2(word a, word b, word *c)
int32_t cmp(const BigInt &n, bool check_signs=true) const
const word MP_WORD_TOP_BIT
const size_t MP_WORD_BITS