[MPFR] multiplications vs. subtractions: which one is faster?

Michael comtech.usa at gmail.com
Sun Jul 15 16:27:55 CEST 2007


Very interesting. Thank you very much folks.

Based on your info, I was able to conjecture that for my program,

(1) Multiplication would be slightly faster, since I am going to use a
little bit less precision, probably around 128-384, based on the
following statement:

"If you reduce the precision, the multiplication version should be
faster,"

However, if 128 is enough for subtraction, I probably would need 256
precision for multiplication to avoid overflow. Similarly, if 384 is
enough for subtraction, I probably would need 768 precision for
multiplication. Does anybody consider this aspect?

(2) Subtraction is even slower because indeed I am subtracting two
numbers that are close, based on the following statement: ( In fact,
that's the reason why I use MPFR. )
"in particular mpfr_sub
might be slower when subtracting numbers that are very close".

(3) Subtraction will be faster on my P4.

Considering the above facts, it is still a close call I guess.

On 7/15/07, Patrick Pelissier <patrick.pelissier at gmail.com> wrote:
> > Thank you Patrick. However I'd like to point out that those figures (I mean
> > the ratio of the number of cycles for both variants) might vary from one
> > platform to the other, maybe by more than a factor of two. They might also
> > depend on the version of mpfr, on the fact that GMP and/or MPFR were tuned
> > for that platform, and on the actual operand values (in particular mpfr_sub
> > might be slower when subtracting numbers that are very close).
>
> Yes.
> Moreover, I expect the subtraction version to be faster on Pentium 4,
> whereas the multiplication version should be faster on opteron/amd64.
>
> --
>   Patrick Pélissier
>


More information about the gmp-discuss mailing list