Back to index

glibc  2.9
Functions
add_n.c File Reference
#include <gmp.h>
#include "gmp-impl.h"

Go to the source code of this file.

Functions

mp_limb_t mpn_add_n (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size)

Function Documentation

mp_limb_t mpn_add_n ( mp_ptr  res_ptr,
mp_srcptr  s1_ptr,
mp_srcptr  s2_ptr,
mp_size_t  size 
)

Definition at line 29 of file add_n.c.

{
  register mp_limb_t x, y, cy;
  register mp_size_t j;

  /* The loop counter and index J goes from -SIZE to -1.  This way
     the loop becomes faster.  */
  j = -size;

  /* Offset the base pointers to compensate for the negative indices.  */
  s1_ptr -= j;
  s2_ptr -= j;
  res_ptr -= j;

  cy = 0;
  do
    {
      y = s2_ptr[j];
      x = s1_ptr[j];
      y += cy;                     /* add previous carry to one addend */
      cy = (y < cy);        /* get out carry from that addition */
      y = x + y;            /* add other addend */
      cy = (y < x) + cy;    /* get out carry from that add, combine */
      res_ptr[j] = y;
    }
  while (++j != 0);

  return cy;
}

Here is the caller graph for this function: