fast inversion

bodrato at mail.dm.unipi.it bodrato at mail.dm.unipi.it
Wed Apr 29 15:41:06 UTC 2015


Ciao,

Il Mer, 29 Aprile 2015 10:49 am, tg at gmplib.org ha scritto:
> nisse at lysator.liu.se (Niels Möller) writes:

  mp_limb_t
  mpn_neg (mp_ptr rp, mp_srcptr up, mp_size_t n)
  {
    /* Low zero limbs are unchanged by negation. */
    while (*up == 0)
      {
        *rp = 0;
        if (!--n)
          /* All zero */
          return 0;
        ++up; ++rp;
      }

    /* First non-zero limb is negated. */
    *rp = - *up;

    /* Higher limbs get complemented. */
    if (--n)
      mpn_com (++rp, ++up, n);

    return 1;
  }

Looks much better than mine!
(I micro-optimised increments, moving them after the possibly returning
branches)

Regards,
m

-- 
http://bodrato.it/






More information about the gmp-devel mailing list