-
+ B5713900ED6F31370C3136B3BEBC4A96603A0F319D1E75ABD706219BD6FDD5C5105F9E33275DF06ABD1321552FFC342DCF41C15CC28873FAEE616A0D62974467
smg_comms/mpi/mpih-add1.c
(0 . 0)(1 . 59)
5770 /* mpihelp-add_1.c - MPI helper functions
5771 * Modified by No Such Labs. (C) 2015. See README.
5772 *
5773 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
5774 * SHA256(gnupg-1.4.10.tar.gz):
5775 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
5776 * (C) 1994-2005 Free Software Foundation, Inc.
5777 *
5778 * This program is free software: you can redistribute it and/or modify
5779 * it under the terms of the GNU General Public License as published by
5780 * the Free Software Foundation, either version 3 of the License, or
5781 * (at your option) any later version.
5782 *
5783 * This program is distributed in the hope that it will be useful,
5784 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5785 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5786 * GNU General Public License for more details.
5787 *
5788 * You should have received a copy of the GNU General Public License
5789 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5790 */
5791
5792 #include <stdio.h>
5793 #include <stdlib.h>
5794
5795 #include "knobs.h"
5796 #include "mpi-internal.h"
5797 #include "longlong.h"
5798
5799 mpi_limb_t
5800 mpihelp_add_n( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
5801 mpi_ptr_t s2_ptr, mpi_size_t size)
5802 {
5803 mpi_limb_t x, y, cy;
5804 mpi_size_t j;
5805
5806 /* The loop counter and index J goes from -SIZE to -1. This way
5807 the loop becomes faster. */
5808 j = -size;
5809
5810 /* Offset the base pointers to compensate for the negative indices. */
5811 s1_ptr -= j;
5812 s2_ptr -= j;
5813 res_ptr -= j;
5814
5815 cy = 0;
5816 do {
5817 y = s2_ptr[j];
5818 x = s1_ptr[j];
5819 y += cy; /* add previous carry to one addend */
5820 cy = y < cy; /* get out carry from that addition */
5821 y += x; /* add other addend */
5822 cy += y < x; /* get out carry from that add, combine */
5823 res_ptr[j] = y;
5824 } while( ++j );
5825
5826 return cy;
5827 }
5828