sqrt algorithm

Torbjörn Granlund tg at gmplib.org
Fri Aug 14 20:01:26 UTC 2015


"Marco Bodrato" <bodrato at mail.dm.unipi.it> writes:

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

  > 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 ;-)
  
I recall to have attempted that, but I didn't want to extend the live
range of a critical variable...

  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
  B.
  
I suppose it used to suggest a bad order, while now it suggests a good
eval order.  (While the initial separate statements means there was a
"sequence point" in C parlance, the compiler may reorder things as the
call can not modify the local expression's result.)

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

A truly good mullo_basecase is written in assembly, of course  :-)

-- 
Torbjörn
Please encrypt, key id 0xC8601622


More information about the gmp-devel mailing list