redc_1_sec.c
Upload User: qaz666999
Upload Date: 2022-08-06
Package Size: 2570k
Code Size: 1k
Category:

Algorithm

Development Platform:

Unix_Linux

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