1 /* mpn_bdiv_q_1, mpn_pi1_bdiv_q_1 -- schoolbook Hensel division by 1-limb
2 divisor, returning quotient only.
4 THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY. THEY'RE ALMOST
5 CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
6 FUTURE GNU MP RELEASES.
8 Copyright 2000, 2001, 2002, 2003, 2005, 2009 Free Software Foundation, Inc.
10 This file is part of the GNU MP Library.
12 The GNU MP Library is free software; you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or (at your
15 option) any later version.
17 The GNU MP Library is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20 License for more details.
22 You should have received a copy of the GNU Lesser General Public License
23 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
30 mpn_pi1_bdiv_q_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t d,
31 mp_limb_t di, int shift)
34 mp_limb_t c, h, l, u, u_next, dummy;
38 ASSERT (MPN_SAME_OR_SEPARATE_P (rp, up, n));
50 for (i = 1; i < n; i++)
53 u = ((u >> shift) | (u_next << (GMP_NUMB_BITS-shift))) & GMP_NUMB_MASK;
55 SUBC_LIMB (c, l, u, c);
57 l = (l * di) & GMP_NUMB_MASK;
60 umul_ppmm (h, dummy, l, d);
67 l = (l * di) & GMP_NUMB_MASK;
73 l = (u * di) & GMP_NUMB_MASK;
77 for (i = 1; i < n; i++)
79 umul_ppmm (h, dummy, l, d);
83 SUBC_LIMB (c, l, u, c);
85 l = (l * di) & GMP_NUMB_MASK;
94 mpn_bdiv_q_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t d)
101 ASSERT (MPN_SAME_OR_SEPARATE_P (rp, up, n));
107 count_trailing_zeros (shift, d);
113 binvert_limb (di, d);
114 return mpn_pi1_bdiv_q_1 (rp, up, n, d, di, shift);