1*86d7f5d3SJohn Marino /* mpn_bdiv_q -- Hensel division with precomputed inverse, returning quotient.
2*86d7f5d3SJohn Marino
3*86d7f5d3SJohn Marino Contributed to the GNU project by Torbjorn Granlund.
4*86d7f5d3SJohn Marino
5*86d7f5d3SJohn Marino THE FUNCTIONS IN THIS FILE ARE INTERNAL WITH MUTABLE INTERFACES. IT IS ONLY
6*86d7f5d3SJohn Marino SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST
7*86d7f5d3SJohn Marino GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GMP RELEASE.
8*86d7f5d3SJohn Marino
9*86d7f5d3SJohn Marino Copyright 2006, 2007, 2009 Free Software Foundation, Inc.
10*86d7f5d3SJohn Marino
11*86d7f5d3SJohn Marino This file is part of the GNU MP Library.
12*86d7f5d3SJohn Marino
13*86d7f5d3SJohn Marino The GNU MP Library is free software; you can redistribute it and/or modify
14*86d7f5d3SJohn Marino it under the terms of the GNU Lesser General Public License as published by
15*86d7f5d3SJohn Marino the Free Software Foundation; either version 3 of the License, or (at your
16*86d7f5d3SJohn Marino option) any later version.
17*86d7f5d3SJohn Marino
18*86d7f5d3SJohn Marino The GNU MP Library is distributed in the hope that it will be useful, but
19*86d7f5d3SJohn Marino WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20*86d7f5d3SJohn Marino or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
21*86d7f5d3SJohn Marino License for more details.
22*86d7f5d3SJohn Marino
23*86d7f5d3SJohn Marino You should have received a copy of the GNU Lesser General Public License
24*86d7f5d3SJohn Marino along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
25*86d7f5d3SJohn Marino
26*86d7f5d3SJohn Marino #include "gmp.h"
27*86d7f5d3SJohn Marino #include "gmp-impl.h"
28*86d7f5d3SJohn Marino
29*86d7f5d3SJohn Marino
30*86d7f5d3SJohn Marino /* Computes Q = N / D mod B^n. */
31*86d7f5d3SJohn Marino
32*86d7f5d3SJohn Marino void
mpn_bdiv_q(mp_ptr qp,mp_srcptr np,mp_size_t nn,mp_srcptr dp,mp_size_t dn,mp_ptr tp)33*86d7f5d3SJohn Marino mpn_bdiv_q (mp_ptr qp,
34*86d7f5d3SJohn Marino mp_srcptr np, mp_size_t nn,
35*86d7f5d3SJohn Marino mp_srcptr dp, mp_size_t dn,
36*86d7f5d3SJohn Marino mp_ptr tp)
37*86d7f5d3SJohn Marino {
38*86d7f5d3SJohn Marino mp_limb_t di;
39*86d7f5d3SJohn Marino
40*86d7f5d3SJohn Marino if (BELOW_THRESHOLD (dn, DC_BDIV_Q_THRESHOLD))
41*86d7f5d3SJohn Marino {
42*86d7f5d3SJohn Marino MPN_COPY (tp, np, nn);
43*86d7f5d3SJohn Marino binvert_limb (di, dp[0]); di = -di;
44*86d7f5d3SJohn Marino mpn_sbpi1_bdiv_q (qp, tp, nn, dp, dn, di);
45*86d7f5d3SJohn Marino }
46*86d7f5d3SJohn Marino else if (BELOW_THRESHOLD (dn, MU_BDIV_Q_THRESHOLD))
47*86d7f5d3SJohn Marino {
48*86d7f5d3SJohn Marino MPN_COPY (tp, np, nn);
49*86d7f5d3SJohn Marino binvert_limb (di, dp[0]); di = -di;
50*86d7f5d3SJohn Marino mpn_dcpi1_bdiv_q (qp, tp, nn, dp, dn, di);
51*86d7f5d3SJohn Marino }
52*86d7f5d3SJohn Marino else
53*86d7f5d3SJohn Marino {
54*86d7f5d3SJohn Marino mpn_mu_bdiv_q (qp, np, nn, dp, dn, tp);
55*86d7f5d3SJohn Marino }
56*86d7f5d3SJohn Marino return;
57*86d7f5d3SJohn Marino }
58*86d7f5d3SJohn Marino
59*86d7f5d3SJohn Marino mp_size_t
mpn_bdiv_q_itch(mp_size_t nn,mp_size_t dn)60*86d7f5d3SJohn Marino mpn_bdiv_q_itch (mp_size_t nn, mp_size_t dn)
61*86d7f5d3SJohn Marino {
62*86d7f5d3SJohn Marino if (BELOW_THRESHOLD (dn, MU_BDIV_Q_THRESHOLD))
63*86d7f5d3SJohn Marino return nn;
64*86d7f5d3SJohn Marino else
65*86d7f5d3SJohn Marino return mpn_mu_bdiv_q_itch (nn, dn);
66*86d7f5d3SJohn Marino }
67