1 /* mpn_add -- Add two low-level integers.
3 Copyright (C) 1991 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 The GNU MP Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with the GNU MP Library; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 /* Add ADD1_PTR/ADD1_SIZE and ADD2_PTR/ADD2_SIZE and store the first
25 ADD1_SIZE words of the result at SUM_PTR.
27 Return 1 if carry out was generated, return 0 otherwise.
29 Argument constraint: ADD1_SIZE >= ADD2_SIZE.
31 The size of SUM can be calculated as ADD1_SIZE + the return value. */
35 mpn_add (mp_ptr sum_ptr,
36 mp_srcptr add1_ptr, mp_size add1_size,
37 mp_srcptr add2_ptr, mp_size add2_size)
39 mpn_add (sum_ptr, add1_ptr, add1_size, add2_ptr, add2_size)
50 /* The loop counter and index J goes from some negative value to zero.
51 This way the loops become faster. Need to offset the base pointers
52 to take care of the negative indices. */
62 /* There are two do-loops, marked NON-CARRY LOOP and CARRY LOOP that
63 jump between each other. The first loop is for when the previous
64 addition didn't produce a carry-out; the second is for the
65 complementary case. */
81 /* We have exhausted ADD2. Just copy ADD1 to SUM, and return
82 0 as an indication of no carry-out. */
85 /* Immediate return if the copy would be a no-op. */
86 if (sum_ptr == add1_ptr)
89 j = add2_size - add1_size;
95 sum_ptr[j] = add1_ptr[j];
114 j = add2_size - add1_size;
130 if (sum_ptr == add1_ptr)
136 sum_ptr[j] = add1_ptr[j];