1 /* mpn_dc_bdiv_q -- divide-and-conquer Hensel division with precomputed
2 inverse, returning quotient.
4 Contributed to the GNU project by Niels Möller and Torbjörn Granlund.
6 THE FUNCTIONS IN THIS FILE ARE INTERNAL WITH A MUTABLE INTERFACE. IT IS
7 ONLY SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS
8 ALMOST GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GMP
11 Copyright 2006, 2007 Free Software Foundation, Inc.
13 This file is part of the GNU MP Library.
15 The GNU MP Library is free software; you can redistribute it and/or modify
16 it under the terms of the GNU Lesser General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or (at your
18 option) any later version.
20 The GNU MP Library is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
23 License for more details.
25 You should have received a copy of the GNU Lesser General Public License
26 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
32 /* Computes Q = N / D mod B^n, destroys N. */
35 mpn_dc_bdiv_q_n_itch (mp_size_t n)
37 /* NOTE: Depends om mullow_n interface */
42 mpn_dc_bdiv_q_n (mp_ptr qp,
43 mp_ptr np, mp_srcptr dp, mp_size_t n,
44 mp_limb_t dinv, mp_ptr tp)
46 while (ABOVE_THRESHOLD (n, DC_BDIV_Q_THRESHOLD))
54 cy = mpn_dc_bdiv_qr_n (qp, np, dp, l, dinv, tp);
56 mpn_mullow_n (tp, qp, dp + h, l);
57 mpn_sub_n (np + h, np + h, tp, l);
61 cy += mpn_submul_1 (np + l, qp, l, dp[l]);
68 mpn_sb_bdiv_q (qp, np, n, dp, n, dinv);
72 mpn_dc_bdiv_q (mp_ptr qp,
73 mp_ptr np, mp_size_t nn,
74 mp_srcptr dp, mp_size_t dn,
84 tp = TMP_SALLOC_LIMBS (dn);
90 /* Reduce qn mod dn in a super-efficient manner. */
95 /* Perform the typically smaller block first. */
96 if (BELOW_THRESHOLD (qn, DC_BDIV_QR_THRESHOLD))
97 cy = mpn_sb_bdiv_qr (qp, np, 2 * qn, dp, qn, dinv);
99 cy = mpn_dc_bdiv_qr_n (qp, np, dp, qn, dinv, tp);
104 mpn_mul (tp, qp, qn, dp + qn, dn - qn);
106 mpn_mul (tp, dp + qn, dn - qn, qp, qn);
107 mpn_incr_u (tp + qn, cy);
109 mpn_sub (np + qn, np + qn, nn - qn, tp, dn);
119 mpn_sub_1 (np + dn, np + dn, qn, cy);
120 cy = mpn_dc_bdiv_qr_n (qp, np, dp, dn, dinv, tp);
125 mpn_sub_1 (np + dn, np + dn, qn, cy);
126 mpn_dc_bdiv_q_n (qp, np, dp, dn, dinv, tp);
131 if (BELOW_THRESHOLD (qn, DC_BDIV_Q_THRESHOLD))
132 mpn_sb_bdiv_q (qp, np, 2 * qn, dp, qn, dinv);
134 mpn_dc_bdiv_q_n (qp, np, dp, qn, dinv, tp);