github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/mpn/generic/bdiv_q.c (about)

     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.h"
    38  #include "gmp-impl.h"
    39  
    40  
    41  /* Computes Q = N / D mod B^n. */
    42  
    43  void
    44  mpn_bdiv_q (mp_ptr qp,
    45  	    mp_srcptr np, mp_size_t nn,
    46  	    mp_srcptr dp, mp_size_t dn,
    47  	    mp_ptr tp)
    48  {
    49    mp_limb_t di;
    50  
    51    if (BELOW_THRESHOLD (dn, DC_BDIV_Q_THRESHOLD))
    52      {
    53        MPN_COPY (tp, np, nn);
    54        binvert_limb (di, dp[0]);  di = -di;
    55        mpn_sbpi1_bdiv_q (qp, tp, nn, dp, dn, di);
    56      }
    57    else if (BELOW_THRESHOLD (dn, MU_BDIV_Q_THRESHOLD))
    58      {
    59        MPN_COPY (tp, np, nn);
    60        binvert_limb (di, dp[0]);  di = -di;
    61        mpn_dcpi1_bdiv_q (qp, tp, nn, dp, dn, di);
    62      }
    63    else
    64      {
    65        mpn_mu_bdiv_q (qp, np, nn, dp, dn, tp);
    66      }
    67    return;
    68  }
    69  
    70  mp_size_t
    71  mpn_bdiv_q_itch (mp_size_t nn, mp_size_t dn)
    72  {
    73    if (BELOW_THRESHOLD (dn, MU_BDIV_Q_THRESHOLD))
    74      return nn;
    75    else
    76      return mpn_mu_bdiv_q_itch (nn, dn);
    77  }