| 1812 | #endif |
| 1813 | |
| 1814 | txBigInt *fxBigInt_udiv(txMachine* the, txBigInt *q, txBigInt *a, txBigInt *b, txBigInt **r) |
| 1815 | { |
| 1816 | int sw; |
| 1817 | txBigInt *nb, *na, *tb, *a2, *b2, *tb2, *tb3; |
| 1818 | int i, n, t; |
| 1819 | txU4 *qp, *ap, *bp; |
| 1820 | #define mk_dword(p, i) (((txU8)(p)[i] << mxBigIntWordSize) | (p)[i - 1]) |
| 1821 | |
| 1822 | if (fxBigInt_ucomp(a, b) < 0) { |
| 1823 | if (q == NULL) { |
| 1824 | q = fxBigInt_alloc(the, 1); |
| 1825 | } |
| 1826 | else { |
| 1827 | q->sign = 0; |
| 1828 | q->size = 1; |
| 1829 | } |
| 1830 | q->data[0] = 0; |
| 1831 | if (r != NULL) { |
| 1832 | if (*r == NULL) |
| 1833 | *r = fxBigInt_dup(the, a); |
| 1834 | else |
| 1835 | fxBigInt_copy(*r, a); |
| 1836 | (*r)->sign = 0; |
| 1837 | } |
| 1838 | return(q); |
| 1839 | } |
| 1840 | |
| 1841 | /* CAUTION: if q is present, it must take account of normalization */ |
| 1842 | if (q == NULL) |
| 1843 | q = fxBigInt_alloc(the, a->size - b->size + 2); |
| 1844 | if (r != NULL && *r == NULL) |
| 1845 | *r = fxBigInt_alloc(the, b->size); |
| 1846 | |
| 1847 | /* normalize */ |
| 1848 | sw = fxBigInt_ffs(b); |
| 1849 | nb = fxBigInt_ulsl1(the, NULL, b, sw); |
| 1850 | na = fxBigInt_ulsl1(the, NULL, a, sw); |
| 1851 | t = nb->size - 1; /* the size must not change from 'b' */ |
| 1852 | n = na->size - 1; |
| 1853 | |
| 1854 | /* adjust size of q */ |
| 1855 | q->size = na->size - nb->size + 1; |
| 1856 | fxBigInt_fill0(q); /* set 0 to quotient */ |
| 1857 | |
| 1858 | /* process the most significant word */ |
| 1859 | tb = fxBigInt_ulsl1(the, NULL, nb, (n - t) * mxBigIntWordSize); /* y*b^n */ |
| 1860 | if (fxBigInt_ucomp(na, tb) >= 0) { |
| 1861 | q->data[q->size - 1]++; |
| 1862 | fxBigInt_sub(C_NULL, na, na, tb); |
| 1863 | /* since nomalization done, must be na < tb here */ |
| 1864 | } |
| 1865 | |
| 1866 | /* prepare the constant for the adjustment: y_t*b + y_{t-1} */ |
| 1867 | b2 = fxBigInt_alloc(the, 2); |
| 1868 | fxBigInt_makepoly(b2, nb, t); |
| 1869 | /* and allocate for temporary buffer */ |
| 1870 | a2 = fxBigInt_alloc(the, 3); |
| 1871 | tb2 = fxBigInt_alloc(the, 3); |
no test coverage detected