[PPL-devel] mpz_addmul_ui with ui = 1

Paul Zimmermann Paul.Zimmermann at loria.fr
Tue Feb 3 08:06:44 CET 2009


       Dear Roberto,

> 	// FIXME(0.10.1): the test seems to speed up the GMP computation.
> 	if (tableau_ij != 0) {
> 	  scalar_value = tableau_ij * norm_factor[i];
> 	  add_mul_assign(challenger_den, scalar_value, scalar_value);
> 	}
>
> inline void
> add_mul_assign(GMP_Integer& x, const GMP_Integer& y, const GMP_Integer& z) {
>    mpz_addmul(x.get_mpz_t(), y.get_mpz_t(), z.get_mpz_t());
> }

I'm ignorant about C++, but maybe the speedup you observe is due to the
scalar_value = tableau_ij * norm_factor[i] instruction which is not done
any more (which types have scalar_value, tableau_ij and norm_factor[i] ?),
or maybe to some init/clear/conversion due to that instruction, or even to
the xxx.get_mpz_t() calls.

Indeed, the code of mpz_aorsmul (which implements mpz_addmul) starts with:

mpz_aorsmul (mpz_ptr w, mpz_srcptr x, mpz_srcptr y, mp_size_t sub)
{
 ...

  xsize = SIZ(x);
  ysize = SIZ(y);
  if (xsize == 0 || ysize == 0)
    return;

My advice is to convert this part of the code to plain C calling directly the
GMP routines, and/or moving scalar_value = tableau_ij * norm_factor[i] before
the test.

Paul Zimmermann


More information about the gmp-discuss mailing list