(root)/
gmp-6.3.0/
mpn/
generic/
div_qr_2n_pi1.c
       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-impl.h"
      39  #include "longlong.h"
      40  
      41  
      42  /* 3/2 loop, for normalized divisor */
      43  mp_limb_t
      44  mpn_div_qr_2n_pi1 (mp_ptr qp, mp_ptr rp, mp_srcptr np, mp_size_t nn,
      45  		   mp_limb_t d1, mp_limb_t d0, mp_limb_t di)
      46  {
      47    mp_limb_t qh;
      48    mp_size_t i;
      49    mp_limb_t r1, r0;
      50  
      51    ASSERT (nn >= 2);
      52    ASSERT (d1 & GMP_NUMB_HIGHBIT);
      53  
      54    np += nn - 2;
      55    r1 = np[1];
      56    r0 = np[0];
      57  
      58    qh = 0;
      59    if (r1 >= d1 && (r1 > d1 || r0 >= d0))
      60      {
      61  #if GMP_NAIL_BITS == 0
      62        sub_ddmmss (r1, r0, r1, r0, d1, d0);
      63  #else
      64        r0 = r0 - d0;
      65        r1 = r1 - d1 - (r0 >> GMP_LIMB_BITS - 1);
      66        r0 &= GMP_NUMB_MASK;
      67  #endif
      68        qh = 1;
      69      }
      70  
      71    for (i = nn - 2 - 1; i >= 0; i--)
      72      {
      73        mp_limb_t n0, q;
      74        n0 = np[-1];
      75        udiv_qr_3by2 (q, r1, r0, r1, r0, n0, d1, d0, di);
      76        np--;
      77        qp[i] = q;
      78      }
      79  
      80    rp[1] = r1;
      81    rp[0] = r0;
      82  
      83    return qh;
      84  }