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

     1  /* mpn_mul_1 -- Multiply a limb vector with a single limb and store the
     2     product in a second limb vector.
     3  
     4  Copyright 1991-1994, 1996, 2000-2002 Free Software Foundation, Inc.
     5  
     6  This file is part of the GNU MP Library.
     7  
     8  The GNU MP Library is free software; you can redistribute it and/or modify
     9  it under the terms of either:
    10  
    11    * the GNU Lesser General Public License as published by the Free
    12      Software Foundation; either version 3 of the License, or (at your
    13      option) any later version.
    14  
    15  or
    16  
    17    * the GNU General Public License as published by the Free Software
    18      Foundation; either version 2 of the License, or (at your option) any
    19      later version.
    20  
    21  or both in parallel, as here.
    22  
    23  The GNU MP Library is distributed in the hope that it will be useful, but
    24  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    25  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    26  for more details.
    27  
    28  You should have received copies of the GNU General Public License and the
    29  GNU Lesser General Public License along with the GNU MP Library.  If not,
    30  see https://www.gnu.org/licenses/.  */
    31  
    32  #include "gmp.h"
    33  #include "gmp-impl.h"
    34  #include "longlong.h"
    35  
    36  
    37  #if GMP_NAIL_BITS == 0
    38  
    39  mp_limb_t
    40  mpn_mul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)
    41  {
    42    mp_limb_t ul, cl, hpl, lpl;
    43  
    44    ASSERT (n >= 1);
    45    ASSERT (MPN_SAME_OR_INCR_P (rp, up, n));
    46  
    47    cl = 0;
    48    do
    49      {
    50        ul = *up++;
    51        umul_ppmm (hpl, lpl, ul, vl);
    52  
    53        lpl += cl;
    54        cl = (lpl < cl) + hpl;
    55  
    56        *rp++ = lpl;
    57      }
    58    while (--n != 0);
    59  
    60    return cl;
    61  }
    62  
    63  #endif
    64  
    65  #if GMP_NAIL_BITS >= 1
    66  
    67  mp_limb_t
    68  mpn_mul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)
    69  {
    70    mp_limb_t shifted_vl, ul, lpl, hpl, prev_hpl, xw, cl, xl;
    71  
    72    ASSERT (n >= 1);
    73    ASSERT (MPN_SAME_OR_INCR_P (rp, up, n));
    74    ASSERT_MPN (up, n);
    75    ASSERT_LIMB (vl);
    76  
    77    shifted_vl = vl << GMP_NAIL_BITS;
    78    cl = 0;
    79    prev_hpl = 0;
    80    do
    81      {
    82        ul = *up++;
    83  
    84        umul_ppmm (hpl, lpl, ul, shifted_vl);
    85        lpl >>= GMP_NAIL_BITS;
    86        xw = prev_hpl + lpl + cl;
    87        cl = xw >> GMP_NUMB_BITS;
    88        xl = xw & GMP_NUMB_MASK;
    89        *rp++ = xl;
    90        prev_hpl = hpl;
    91      }
    92    while (--n != 0);
    93  
    94    return prev_hpl + cl;
    95  }
    96  
    97  #endif