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