github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/mpn/generic/pre_mod_1.c (about) 1 /* mpn_preinv_mod_1 (up, un, d, dinv) -- Divide (UP,,UN) by the normalized D. 2 DINV should be 2^(2*GMP_LIMB_BITS) / D - 2^GMP_LIMB_BITS. 3 Return the single-limb remainder. 4 5 Copyright 1991, 1993, 1994, 2000-2002, 2004, 2005 Free Software Foundation, 6 Inc. 7 8 This file is part of the GNU MP Library. 9 10 The GNU MP Library is free software; you can redistribute it and/or modify 11 it under the terms of either: 12 13 * the GNU Lesser General Public License as published by the Free 14 Software Foundation; either version 3 of the License, or (at your 15 option) any later version. 16 17 or 18 19 * the GNU General Public License as published by the Free Software 20 Foundation; either version 2 of the License, or (at your option) any 21 later version. 22 23 or both in parallel, as here. 24 25 The GNU MP Library is distributed in the hope that it will be useful, but 26 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 27 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28 for more details. 29 30 You should have received copies of the GNU General Public License and the 31 GNU Lesser General Public License along with the GNU MP Library. If not, 32 see https://www.gnu.org/licenses/. */ 33 34 #include "gmp.h" 35 #include "gmp-impl.h" 36 #include "longlong.h" 37 38 39 /* This function used to be documented, but is now considered obsolete. It 40 continues to exist for binary compatibility, even when not required 41 internally. */ 42 43 mp_limb_t 44 mpn_preinv_mod_1 (mp_srcptr up, mp_size_t un, mp_limb_t d, mp_limb_t dinv) 45 { 46 mp_size_t i; 47 mp_limb_t n0, r; 48 49 ASSERT (un >= 1); 50 ASSERT (d & GMP_LIMB_HIGHBIT); 51 52 r = up[un - 1]; 53 if (r >= d) 54 r -= d; 55 56 for (i = un - 2; i >= 0; i--) 57 { 58 n0 = up[i]; 59 udiv_rnnd_preinv (r, r, n0, d, dinv); 60 } 61 return r; 62 }