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

     1  /* mpn_mulmid_n -- balanced middle product
     2  
     3     Contributed by David Harvey.
     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'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
     8  
     9  Copyright 2011 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  
    42  void
    43  mpn_mulmid_n (mp_ptr rp, mp_srcptr ap, mp_srcptr bp, mp_size_t n)
    44  {
    45    ASSERT (n >= 1);
    46    ASSERT (! MPN_OVERLAP_P (rp, n + 2, ap, 2*n - 1));
    47    ASSERT (! MPN_OVERLAP_P (rp, n + 2, bp, n));
    48  
    49    if (n < MULMID_TOOM42_THRESHOLD)
    50      {
    51        mpn_mulmid_basecase (rp, ap, 2*n - 1, bp, n);
    52      }
    53    else
    54      {
    55        mp_ptr scratch;
    56        TMP_DECL;
    57        TMP_MARK;
    58        scratch = TMP_ALLOC_LIMBS (mpn_toom42_mulmid_itch (n));
    59        mpn_toom42_mulmid (rp, ap, bp, n, scratch);
    60        TMP_FREE;
    61      }
    62  }