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