1/* mpn_add_n -- Add equal length limb vectors. 2 3Copyright 1992, 1993, 1994, 1996, 2000, 2002, 2009 Free Software Foundation, 4Inc. 5 6This file is part of the GNU MP Library. 7 8The GNU MP Library is free software; you can redistribute it and/or modify 9it under the terms of the GNU Lesser General Public License as published by 10the Free Software Foundation; either version 3 of the License, or (at your 11option) any later version. 12 13The GNU MP Library is distributed in the hope that it will be useful, but 14WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16License for more details. 17 18You should have received a copy of the GNU Lesser General Public License 19along 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 27mp_limb_t 28mpn_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 57mp_limb_t 58mpn_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 81