new beta-0.90.0
[luatex.git] / source / libs / gmp / gmp-src / mpn / generic / addmul_1.c
blobd76b4ad135066f56bdbed5b07001f662e8e5b18a
1 /* mpn_addmul_1 -- multiply the N long limb vector pointed to by UP by VL,
2 add the N least significant limbs of the product to the limb vector
3 pointed to by RP. Return the most significant limb of the product,
4 adjusted for carry-out from the addition.
6 Copyright 1992-1994, 1996, 2000, 2002, 2004 Free Software Foundation, Inc.
8 This file is part of the GNU MP Library.
10 The GNU MP Library is free software; you can redistribute it and/or modify
11 it under the terms of either:
13 * the GNU Lesser General Public License as published by the Free
14 Software Foundation; either version 3 of the License, or (at your
15 option) any later version.
19 * the GNU General Public License as published by the Free Software
20 Foundation; either version 2 of the License, or (at your option) any
21 later version.
23 or both in parallel, as here.
25 The GNU MP Library is distributed in the hope that it will be useful, but
26 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
27 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 for more details.
30 You should have received copies of the GNU General Public License and the
31 GNU Lesser General Public License along with the GNU MP Library. If not,
32 see https://www.gnu.org/licenses/. */
34 #include "gmp.h"
35 #include "gmp-impl.h"
36 #include "longlong.h"
39 #if GMP_NAIL_BITS == 0
41 mp_limb_t
42 mpn_addmul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)
44 mp_limb_t ul, cl, hpl, lpl, rl;
46 ASSERT (n >= 1);
47 ASSERT (MPN_SAME_OR_SEPARATE_P (rp, up, n));
49 cl = 0;
52 ul = *up++;
53 umul_ppmm (hpl, lpl, ul, vl);
55 lpl += cl;
56 cl = (lpl < cl) + hpl;
58 rl = *rp;
59 lpl = rl + lpl;
60 cl += lpl < rl;
61 *rp++ = lpl;
63 while (--n != 0);
65 return cl;
68 #endif
70 #if GMP_NAIL_BITS == 1
72 mp_limb_t
73 mpn_addmul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)
75 mp_limb_t shifted_vl, ul, rl, lpl, hpl, prev_hpl, cl, xl, c1, c2, c3;
77 ASSERT (n >= 1);
78 ASSERT (MPN_SAME_OR_SEPARATE_P (rp, up, n));
79 ASSERT_MPN (rp, n);
80 ASSERT_MPN (up, n);
81 ASSERT_LIMB (vl);
83 shifted_vl = vl << GMP_NAIL_BITS;
84 cl = 0;
85 prev_hpl = 0;
88 ul = *up++;
89 rl = *rp;
90 umul_ppmm (hpl, lpl, ul, shifted_vl);
91 lpl >>= GMP_NAIL_BITS;
92 ADDC_LIMB (c1, xl, prev_hpl, lpl);
93 ADDC_LIMB (c2, xl, xl, rl);
94 ADDC_LIMB (c3, xl, xl, cl);
95 cl = c1 + c2 + c3;
96 *rp++ = xl;
97 prev_hpl = hpl;
99 while (--n != 0);
101 return prev_hpl + cl;
104 #endif
106 #if GMP_NAIL_BITS >= 2
108 mp_limb_t
109 mpn_addmul_1 (mp_ptr rp, mp_srcptr up, mp_size_t n, mp_limb_t vl)
111 mp_limb_t shifted_vl, ul, rl, lpl, hpl, prev_hpl, xw, cl, xl;
113 ASSERT (n >= 1);
114 ASSERT (MPN_SAME_OR_SEPARATE_P (rp, up, n));
115 ASSERT_MPN (rp, n);
116 ASSERT_MPN (up, n);
117 ASSERT_LIMB (vl);
119 shifted_vl = vl << GMP_NAIL_BITS;
120 cl = 0;
121 prev_hpl = 0;
124 ul = *up++;
125 rl = *rp;
126 umul_ppmm (hpl, lpl, ul, shifted_vl);
127 lpl >>= GMP_NAIL_BITS;
128 xw = prev_hpl + lpl + rl + cl;
129 cl = xw >> GMP_NUMB_BITS;
130 xl = xw & GMP_NUMB_MASK;
131 *rp++ = xl;
132 prev_hpl = hpl;
134 while (--n != 0);
136 return prev_hpl + cl;
139 #endif