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
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
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/. */
39 #if GMP_NAIL_BITS == 0
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
;
47 ASSERT (MPN_SAME_OR_SEPARATE_P (rp
, up
, n
));
53 umul_ppmm (hpl
, lpl
, ul
, vl
);
56 cl
= (lpl
< cl
) + hpl
;
70 #if GMP_NAIL_BITS == 1
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
;
78 ASSERT (MPN_SAME_OR_SEPARATE_P (rp
, up
, n
));
83 shifted_vl
= vl
<< GMP_NAIL_BITS
;
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
);
101 return prev_hpl
+ cl
;
106 #if GMP_NAIL_BITS >= 2
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
;
114 ASSERT (MPN_SAME_OR_SEPARATE_P (rp
, up
, n
));
119 shifted_vl
= vl
<< GMP_NAIL_BITS
;
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
;
136 return prev_hpl
+ cl
;