186d7f5d3SJohn Marino /* mpn_preinv_mod_1 (up, un, d, dinv) -- Divide (UP,,UN) by the normalized D.
286d7f5d3SJohn Marino DINV should be 2^(2*GMP_LIMB_BITS) / D - 2^GMP_LIMB_BITS.
386d7f5d3SJohn Marino Return the single-limb remainder.
486d7f5d3SJohn Marino
586d7f5d3SJohn Marino Copyright 1991, 1993, 1994, 2000, 2001, 2002, 2004, 2005 Free Software
686d7f5d3SJohn Marino Foundation, Inc.
786d7f5d3SJohn Marino
886d7f5d3SJohn Marino This file is part of the GNU MP Library.
986d7f5d3SJohn Marino
1086d7f5d3SJohn Marino The GNU MP Library is free software; you can redistribute it and/or modify it
1186d7f5d3SJohn Marino under the terms of the GNU Lesser General Public License as published by the
1286d7f5d3SJohn Marino Free Software Foundation; either version 3 of the License, or (at your
1386d7f5d3SJohn Marino option) any later version.
1486d7f5d3SJohn Marino
1586d7f5d3SJohn Marino The GNU MP Library is distributed in the hope that it will be useful, but
1686d7f5d3SJohn Marino WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1786d7f5d3SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
1886d7f5d3SJohn Marino for more details.
1986d7f5d3SJohn Marino
2086d7f5d3SJohn Marino You should have received a copy of the GNU Lesser General Public License along
2186d7f5d3SJohn Marino with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
2286d7f5d3SJohn Marino
2386d7f5d3SJohn Marino #include "gmp.h"
2486d7f5d3SJohn Marino #include "gmp-impl.h"
2586d7f5d3SJohn Marino #include "longlong.h"
2686d7f5d3SJohn Marino
2786d7f5d3SJohn Marino
2886d7f5d3SJohn Marino /* This function used to be documented, but is now considered obsolete. It
2986d7f5d3SJohn Marino continues to exist for binary compatibility, even when not required
3086d7f5d3SJohn Marino internally. */
3186d7f5d3SJohn Marino
3286d7f5d3SJohn Marino mp_limb_t
mpn_preinv_mod_1(mp_srcptr up,mp_size_t un,mp_limb_t d,mp_limb_t dinv)3386d7f5d3SJohn Marino mpn_preinv_mod_1 (mp_srcptr up, mp_size_t un, mp_limb_t d, mp_limb_t dinv)
3486d7f5d3SJohn Marino {
3586d7f5d3SJohn Marino mp_size_t i;
3686d7f5d3SJohn Marino mp_limb_t n0, r;
3786d7f5d3SJohn Marino mp_limb_t dummy;
3886d7f5d3SJohn Marino
3986d7f5d3SJohn Marino ASSERT (un >= 1);
4086d7f5d3SJohn Marino ASSERT (d & GMP_LIMB_HIGHBIT);
4186d7f5d3SJohn Marino
4286d7f5d3SJohn Marino r = up[un - 1];
4386d7f5d3SJohn Marino if (r >= d)
4486d7f5d3SJohn Marino r -= d;
4586d7f5d3SJohn Marino
4686d7f5d3SJohn Marino for (i = un - 2; i >= 0; i--)
4786d7f5d3SJohn Marino {
4886d7f5d3SJohn Marino n0 = up[i];
4986d7f5d3SJohn Marino udiv_qrnnd_preinv (dummy, r, r, n0, d, dinv);
5086d7f5d3SJohn Marino }
5186d7f5d3SJohn Marino return r;
5286d7f5d3SJohn Marino }
53