Optimizing a+b-a-b etc.

uunet!cwi.nl!Dik.Winter uunet!cwi.nl!Dik.Winter
Sun May 10 12:34:15 PDT 1992


 > These sorts of expressions appear in code which simulates double precision,
 > and are an essential part of least one current LAPACK routine, and I plan
 > to use it more widely in an IEEE arithmetic version of LAPACK currently
 > under development. A typical code sequence is the following, which returns
 > A and B representing the exact sum of C and D, where B is precisely the
 > roundoff committed while computing A.
 >   A = C+D
 >   if (abs(C)<abs(D)) swap C and D
 >   B = (A-C)-D
 > Parentheses must be respected. It would break the code to replace B by 0.
 > For more details, see, for example, the paper by Doug Priest in the 
 > Proceedings of the 10th Symposium on Computer Arithmetic (IEEE, 1991). Jim Demmel

I want to note that when Dekker devised this algorithm (and its friends) to
simulate double precision on the Electrologica X8 he stated also the
conditions under which those operations hold.  One of the conditions was
faithful arithmetic (which IEEE has), but another is that C+D should not
overflow (even if only by rounding).  So this algorithm should only be used
under stringent regulated circumstances and can not be used to simulate
general double precision.  Similar with the algorithms used in MACHAR etc.

I do *not* say that compilers in *all* circumstances should not optimize
such expressions, nor that compilers in *all* circumstances should optimize.

A much better solution in my opinion is the provision of something like a
pragma which tells the compiler not to optimize the following expression.



More information about the Numeric-interest mailing list