github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/mpn/generic/div_qr_2u_pi1.c (about) 1 /* mpn_div_qr_2u_pi1 2 3 Contributed to the GNU project by 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 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 unnormalized divisor. Caller must pass shifted d1 and 44 d0, while {np,nn} is shifted on the fly. */ 45 mp_limb_t 46 mpn_div_qr_2u_pi1 (mp_ptr qp, mp_ptr rp, mp_srcptr np, mp_size_t nn, 47 mp_limb_t d1, mp_limb_t d0, int shift, mp_limb_t di) 48 { 49 mp_limb_t qh; 50 mp_limb_t r2, r1, r0; 51 mp_size_t i; 52 53 ASSERT (nn >= 2); 54 ASSERT (d1 & GMP_NUMB_HIGHBIT); 55 ASSERT (shift > 0); 56 57 r2 = np[nn-1] >> (GMP_LIMB_BITS - shift); 58 r1 = (np[nn-1] << shift) | (np[nn-2] >> (GMP_LIMB_BITS - shift)); 59 r0 = np[nn-2] << shift; 60 61 udiv_qr_3by2 (qh, r2, r1, r2, r1, r0, d1, d0, di); 62 63 for (i = nn - 2 - 1; i >= 0; i--) 64 { 65 mp_limb_t q; 66 r0 = np[i]; 67 r1 |= r0 >> (GMP_LIMB_BITS - shift); 68 r0 <<= shift; 69 udiv_qr_3by2 (q, r2, r1, r2, r1, r0, d1, d0, di); 70 qp[i] = q; 71 } 72 73 rp[0] = (r1 >> shift) | (r2 << (GMP_LIMB_BITS - shift)); 74 rp[1] = r2 >> shift; 75 76 return qh; 77 }