1 /* mpn_redc_1. Set rp[] <- up[]/R^n mod mp[]. Clobber up[]. 2 mp[] is n limbs; up[] is 2n limbs. 3 4 THIS IS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE. IT IS ONLY 5 SAFE TO REACH THIS FUNCTION THROUGH DOCUMENTED INTERFACES. 6 7 Copyright (C) 2000, 2001, 2002, 2004, 2008, 2009, 2012 Free Software 8 Foundation, Inc. 9 10 This file is part of the GNU MP Library. 11 12 The GNU MP Library is free software; you can redistribute it and/or modify 13 it under the terms of the GNU Lesser General Public License as published by 14 the Free Software Foundation; either version 3 of the License, or (at your 15 option) any later version. 16 17 The GNU MP Library is distributed in the hope that it will be useful, but 18 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 License for more details. 21 22 You should have received a copy of the GNU Lesser General Public License 23 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ 24 25 #include "gmp.h" 26 #include "gmp-impl.h" 27 28 mp_limb_t 29 mpn_redc_1 (mp_ptr rp, mp_ptr up, mp_srcptr mp, mp_size_t n, mp_limb_t invm) 30 { 31 mp_size_t j; 32 mp_limb_t cy; 33 34 ASSERT (n > 0); 35 ASSERT_MPN (up, 2*n); 36 37 for (j = n - 1; j >= 0; j--) 38 { 39 cy = mpn_addmul_1 (up, mp, n, (up[0] * invm) & GMP_NUMB_MASK); 40 ASSERT (up[0] == 0); 41 up[0] = cy; 42 up++; 43 } 44 45 cy = mpn_add_n (rp, up, up - n, n); 46 return cy; 47 } 48