Question about mpn_add_n underlying generic implementation

Grzegorz Szpetkowski gszpetkowski at gmail.com
Sat Jan 18 00:15:15 UTC 2014


Hi all,

I have read manual (mostly) and I am trying to understand following code
within mpn/generic/add_n.c:

  mp_limb_t ul, vl, sl, rl, cy, cy1, cy2;

  ASSERT (n >= 1);
  ASSERT (MPN_SAME_OR_INCR_P (rp, up, n));
  ASSERT (MPN_SAME_OR_INCR_P (rp, vp, n));

  cy = 0;
  do
    {
      ul = *up++;
      vl = *vp++;
      sl = ul + vl;
      cy1 = sl < ul;
      rl = sl + cy;
      cy2 = rl < sl;
      cy = cy1 | cy2;
      *rp++ = rl;
    }
  while (--n != 0);

There is some preprocessor condition for GMP_NAIL_BITS, but as I found it's
disabled in configuration by default and I am sure that my build does not
have it enabled. Essentially what is the purpose of these cy1 and cy2
variables ? What I already understand is that examined limbs (in reversed
order) are just effectively primitive integers like unsigned int, for
example::

#ifdef __GMP_SHORT_LIMB
typedef unsigned int            mp_limb_t;

G. Sz.


More information about the gmp-discuss mailing list