sqrt algorithm

Marco Bodrato bodrato at mail.dm.unipi.it
Fri Aug 14 05:54:59 UTC 2015


On Thu, August 13, 2015 10:09 pm, Torbjörn Granlund wrote:
> I know you like 'while', but I like 'for'...

I prefer 'do while', whenever the initial branch can be saved.

> I agree with saving variables which are simultaneously alive.  In this
> code, n and i are not simultaneously alive.

I like symmetry, eg:
  h += up[n] * v0 +    mpn_mul_1 (rp, up, n, v0);
  h += up[n] * v0 + mpn_addmul_1 (rp, up, n, v0);
but you are right, we have to please compilers, not aesthetic ;-)

> The variant below makes an important change: It makes one quantity less
> live across calls.

Interesting observation, by writing "h += A + B" we suggest to the
compiler that A and B can be computed in any order; when we write "h += A;
h += B;" we warn the compiler: computing A may have effects on computing

A better mullo_basecase will improve the overall speed of sqrlo_dc, then
maybe the speed of sqrt...


More information about the gmp-devel mailing list