github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/mpn/generic/toom_couple_handling.c (about)

     1  /* Helper function for high degree Toom-Cook algorithms.
     2  
     3     Contributed to the GNU project by Marco Bodrato.
     4  
     5     THE FUNCTION IN THIS FILE IS INTERNAL WITH A MUTABLE INTERFACE.  IT IS ONLY
     6     SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
     7     GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
     8  
     9  Copyright 2009, 2010 Free Software Foundation, Inc.
    10  
    11  This file is part of the GNU MP Library.
    12  
    13  The GNU MP Library is free software; you can redistribute it and/or modify
    14  it under the terms of either:
    15  
    16    * the GNU Lesser General Public License as published by the Free
    17      Software Foundation; either version 3 of the License, or (at your
    18      option) any later version.
    19  
    20  or
    21  
    22    * the GNU General Public License as published by the Free Software
    23      Foundation; either version 2 of the License, or (at your option) any
    24      later version.
    25  
    26  or both in parallel, as here.
    27  
    28  The GNU MP Library is distributed in the hope that it will be useful, but
    29  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    30  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    31  for more details.
    32  
    33  You should have received copies of the GNU General Public License and the
    34  GNU Lesser General Public License along with the GNU MP Library.  If not,
    35  see https://www.gnu.org/licenses/.  */
    36  
    37  
    38  #include "gmp.h"
    39  #include "gmp-impl.h"
    40  
    41  /* Gets {pp,n} and (sign?-1:1)*{np,n}. Computes at once:
    42       {pp,n} <- ({pp,n}+{np,n})/2^{ps+1}
    43       {pn,n} <- ({pp,n}-{np,n})/2^{ns+1}
    44     Finally recompose them obtaining:
    45       {pp,n+off} <- {pp,n}+{np,n}*2^{off*GMP_NUMB_BITS}
    46  */
    47  void
    48  mpn_toom_couple_handling (mp_ptr pp, mp_size_t n, mp_ptr np,
    49  			  int nsign, mp_size_t off, int ps, int ns)
    50  {
    51    if (nsign) {
    52  #ifdef HAVE_NATIVE_mpn_rsh1sub_n
    53      mpn_rsh1sub_n (np, pp, np, n);
    54  #else
    55      mpn_sub_n (np, pp, np, n);
    56      mpn_rshift (np, np, n, 1);
    57  #endif
    58    } else {
    59  #ifdef HAVE_NATIVE_mpn_rsh1add_n
    60      mpn_rsh1add_n (np, pp, np, n);
    61  #else
    62      mpn_add_n (np, pp, np, n);
    63      mpn_rshift (np, np, n, 1);
    64  #endif
    65    }
    66  
    67  #ifdef HAVE_NATIVE_mpn_rsh1sub_n
    68    if (ps == 1)
    69      mpn_rsh1sub_n (pp, pp, np, n);
    70    else
    71  #endif
    72    {
    73      mpn_sub_n (pp, pp, np, n);
    74      if (ps > 0)
    75        mpn_rshift (pp, pp, n, ps);
    76    }
    77    if (ns > 0)
    78      mpn_rshift (np, np, n, ns);
    79    pp[n] = mpn_add_n (pp+off, pp+off, np, n-off);
    80    ASSERT_NOCARRY (mpn_add_1(pp+n, np+n-off, off, pp[n]) );
    81  }