1 /* TomsFastMath, a fast ISO C bignum library.
3 * This project is meant to fill in where LibTomMath
4 * falls short. That is speed ;-)
6 * This project is public domain and free for all purposes.
8 * Tom St Denis, tomstdenis@gmail.com
10 #include <tfm_private.h>
13 void fp_div_2d(fp_int *a, int b, fp_int *c, fp_int *d)
19 /* if the shift count is <= 0 then we do no work */
30 /* get the remainder */
38 /* shift by as many digits in the bit count */
39 if (b >= (int)DIGIT_BIT) {
40 fp_rshd (c, b / DIGIT_BIT);
43 /* shift any bit count < DIGIT_BIT */
44 D = (fp_digit) (b % DIGIT_BIT);
46 register fp_digit *tmpc, mask, shift;
49 mask = (((fp_digit)1) << D) - 1;
52 shift = DIGIT_BIT - D;
55 tmpc = c->dp + (c->used - 1);
59 for (x = c->used - 1; x >= 0; x--) {
60 /* get the lower bits of this word in a temp */
63 /* shift the current word and mix in the carry bits from the previous word */
64 *tmpc = (*tmpc >> D) | (r << shift);
67 /* set the carry to the carry bits of the current word found above */