Upgrade GMP from 4.3.2 to 5.0.2 on the vendor branch
[dragonfly.git] / contrib / gmp / mpn / generic / add_n.c
1 /* mpn_add_n -- Add equal length limb vectors.
2
3 Copyright 1992, 1993, 1994, 1996, 2000, 2002, 2009 Free Software Foundation,
4 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 the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12
13 The GNU MP Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16 License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
20
21 #include "gmp.h"
22 #include "gmp-impl.h"
23
24
25 #if GMP_NAIL_BITS == 0
26
27 mp_limb_t
28 mpn_add_n (mp_ptr rp, mp_srcptr up, mp_srcptr vp, mp_size_t n)
29 {
30   mp_limb_t ul, vl, sl, rl, cy, cy1, cy2;
31
32   ASSERT (n >= 1);
33   ASSERT (MPN_SAME_OR_INCR_P (rp, up, n));
34   ASSERT (MPN_SAME_OR_INCR_P (rp, vp, n));
35
36   cy = 0;
37   do
38     {
39       ul = *up++;
40       vl = *vp++;
41       sl = ul + vl;
42       cy1 = sl < ul;
43       rl = sl + cy;
44       cy2 = rl < sl;
45       cy = cy1 | cy2;
46       *rp++ = rl;
47     }
48   while (--n != 0);
49
50   return cy;
51 }
52
53 #endif
54
55 #if GMP_NAIL_BITS >= 1
56
57 mp_limb_t
58 mpn_add_n (mp_ptr rp, mp_srcptr up, mp_srcptr vp, mp_size_t n)
59 {
60   mp_limb_t ul, vl, rl, cy;
61
62   ASSERT (n >= 1);
63   ASSERT (MPN_SAME_OR_INCR_P (rp, up, n));
64   ASSERT (MPN_SAME_OR_INCR_P (rp, vp, n));
65
66   cy = 0;
67   do
68     {
69       ul = *up++;
70       vl = *vp++;
71       rl = ul + vl + cy;
72       cy = rl >> GMP_NUMB_BITS;
73       *rp++ = rl & GMP_NUMB_MASK;
74     }
75   while (--n != 0);
76
77   return cy;
78 }
79
80 #endif