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

     1  /* mpn_div_qr_2n_pi1
     2  
     3     Contributed to the GNU project by Torbjorn Granlund and Niels Möller
     4  
     5     THIS FILE CONTAINS INTERNAL FUNCTIONS WITH MUTABLE INTERFACES.  IT IS ONLY
     6     SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
     7     GUARANTEED THAT THEY'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
     8  
     9  
    10  Copyright 1993-1996, 1999-2002, 2011 Free Software Foundation, Inc.
    11  
    12  This file is part of the GNU MP Library.
    13  
    14  The GNU MP Library is free software; you can redistribute it and/or modify
    15  it under the terms of either:
    16  
    17    * the GNU Lesser General Public License as published by the Free
    18      Software Foundation; either version 3 of the License, or (at your
    19      option) any later version.
    20  
    21  or
    22  
    23    * the GNU General Public License as published by the Free Software
    24      Foundation; either version 2 of the License, or (at your option) any
    25      later version.
    26  
    27  or both in parallel, as here.
    28  
    29  The GNU MP Library is distributed in the hope that it will be useful, but
    30  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    31  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    32  for more details.
    33  
    34  You should have received copies of the GNU General Public License and the
    35  GNU Lesser General Public License along with the GNU MP Library.  If not,
    36  see https://www.gnu.org/licenses/.  */
    37  
    38  #include "gmp.h"
    39  #include "gmp-impl.h"
    40  #include "longlong.h"
    41  
    42  
    43  /* 3/2 loop, for normalized divisor */
    44  mp_limb_t
    45  mpn_div_qr_2n_pi1 (mp_ptr qp, mp_ptr rp, mp_srcptr np, mp_size_t nn,
    46  		   mp_limb_t d1, mp_limb_t d0, mp_limb_t di)
    47  {
    48    mp_limb_t qh;
    49    mp_size_t i;
    50    mp_limb_t r1, r0;
    51  
    52    ASSERT (nn >= 2);
    53    ASSERT (d1 & GMP_NUMB_HIGHBIT);
    54  
    55    np += nn - 2;
    56    r1 = np[1];
    57    r0 = np[0];
    58  
    59    qh = 0;
    60    if (r1 >= d1 && (r1 > d1 || r0 >= d0))
    61      {
    62  #if GMP_NAIL_BITS == 0
    63        sub_ddmmss (r1, r0, r1, r0, d1, d0);
    64  #else
    65        r0 = r0 - d0;
    66        r1 = r1 - d1 - (r0 >> GMP_LIMB_BITS - 1);
    67        r0 &= GMP_NUMB_MASK;
    68  #endif
    69        qh = 1;
    70      }
    71  
    72    for (i = nn - 2 - 1; i >= 0; i--)
    73      {
    74        mp_limb_t n0, q;
    75        n0 = np[-1];
    76        udiv_qr_3by2 (q, r1, r0, r1, r0, n0, d1, d0, di);
    77        np--;
    78        qp[i] = q;
    79      }
    80  
    81    rp[1] = r1;
    82    rp[0] = r0;
    83  
    84    return qh;
    85  }