186d7f5d3SJohn Marino /* mpn_mul_1 -- Multiply a limb vector with a single limb and store the
286d7f5d3SJohn Marino product in a second limb vector.
386d7f5d3SJohn Marino
486d7f5d3SJohn Marino Copyright 1991, 1992, 1993, 1994, 1996, 2000, 2001, 2002 Free Software
586d7f5d3SJohn Marino Foundation, Inc.
686d7f5d3SJohn Marino
786d7f5d3SJohn Marino This file is part of the GNU MP Library.
886d7f5d3SJohn Marino
986d7f5d3SJohn Marino The GNU MP Library is free software; you can redistribute it and/or modify
1086d7f5d3SJohn Marino it under the terms of the GNU Lesser General Public License as published by
1186d7f5d3SJohn Marino the Free Software Foundation; either version 3 of the License, or (at your
1286d7f5d3SJohn Marino option) any later version.
1386d7f5d3SJohn Marino
1486d7f5d3SJohn Marino The GNU MP Library is distributed in the hope that it will be useful, but
1586d7f5d3SJohn Marino WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1686d7f5d3SJohn Marino or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
1786d7f5d3SJohn Marino License for more details.
1886d7f5d3SJohn Marino
1986d7f5d3SJohn Marino You should have received a copy of the GNU Lesser General Public License
2086d7f5d3SJohn Marino along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
2186d7f5d3SJohn Marino
2286d7f5d3SJohn Marino #include "gmp.h"
2386d7f5d3SJohn Marino #include "gmp-impl.h"
2486d7f5d3SJohn Marino #include "longlong.h"
2586d7f5d3SJohn Marino
2686d7f5d3SJohn Marino
2786d7f5d3SJohn Marino #if GMP_NAIL_BITS == 0
2886d7f5d3SJohn Marino
2986d7f5d3SJohn Marino mp_limb_t
mpn_mul_1(mp_ptr rp,mp_srcptr up,mp_size_t n,mp_limb_t vl)3086d7f5d3SJohn Marino mpn_mul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)
3186d7f5d3SJohn Marino {
3286d7f5d3SJohn Marino mp_limb_t ul, cl, hpl, lpl;
3386d7f5d3SJohn Marino
3486d7f5d3SJohn Marino ASSERT (n >= 1);
3586d7f5d3SJohn Marino ASSERT (MPN_SAME_OR_INCR_P (rp, up, n));
3686d7f5d3SJohn Marino
3786d7f5d3SJohn Marino cl = 0;
3886d7f5d3SJohn Marino do
3986d7f5d3SJohn Marino {
4086d7f5d3SJohn Marino ul = *up++;
4186d7f5d3SJohn Marino umul_ppmm (hpl, lpl, ul, vl);
4286d7f5d3SJohn Marino
4386d7f5d3SJohn Marino lpl += cl;
4486d7f5d3SJohn Marino cl = (lpl < cl) + hpl;
4586d7f5d3SJohn Marino
4686d7f5d3SJohn Marino *rp++ = lpl;
4786d7f5d3SJohn Marino }
4886d7f5d3SJohn Marino while (--n != 0);
4986d7f5d3SJohn Marino
5086d7f5d3SJohn Marino return cl;
5186d7f5d3SJohn Marino }
5286d7f5d3SJohn Marino
5386d7f5d3SJohn Marino #endif
5486d7f5d3SJohn Marino
5586d7f5d3SJohn Marino #if GMP_NAIL_BITS >= 1
5686d7f5d3SJohn Marino
5786d7f5d3SJohn Marino mp_limb_t
mpn_mul_1(mp_ptr rp,mp_srcptr up,mp_size_t n,mp_limb_t vl)5886d7f5d3SJohn Marino mpn_mul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)
5986d7f5d3SJohn Marino {
6086d7f5d3SJohn Marino mp_limb_t shifted_vl, ul, lpl, hpl, prev_hpl, xw, cl, xl;
6186d7f5d3SJohn Marino
6286d7f5d3SJohn Marino ASSERT (n >= 1);
6386d7f5d3SJohn Marino ASSERT (MPN_SAME_OR_INCR_P (rp, up, n));
6486d7f5d3SJohn Marino ASSERT_MPN (up, n);
6586d7f5d3SJohn Marino ASSERT_LIMB (vl);
6686d7f5d3SJohn Marino
6786d7f5d3SJohn Marino shifted_vl = vl << GMP_NAIL_BITS;
6886d7f5d3SJohn Marino cl = 0;
6986d7f5d3SJohn Marino prev_hpl = 0;
7086d7f5d3SJohn Marino do
7186d7f5d3SJohn Marino {
7286d7f5d3SJohn Marino ul = *up++;
7386d7f5d3SJohn Marino
7486d7f5d3SJohn Marino umul_ppmm (hpl, lpl, ul, shifted_vl);
7586d7f5d3SJohn Marino lpl >>= GMP_NAIL_BITS;
7686d7f5d3SJohn Marino xw = prev_hpl + lpl + cl;
7786d7f5d3SJohn Marino cl = xw >> GMP_NUMB_BITS;
7886d7f5d3SJohn Marino xl = xw & GMP_NUMB_MASK;
7986d7f5d3SJohn Marino *rp++ = xl;
8086d7f5d3SJohn Marino prev_hpl = hpl;
8186d7f5d3SJohn Marino }
8286d7f5d3SJohn Marino while (--n != 0);
8386d7f5d3SJohn Marino
8486d7f5d3SJohn Marino return prev_hpl + cl;
8586d7f5d3SJohn Marino }
8686d7f5d3SJohn Marino
8786d7f5d3SJohn Marino #endif
88