Mail Archives: djgpp/1998/01/29/06:45:30
Thomas Demmer wrote:
> Simple optimization: Common Subexpression Evaluation (CSE):
> double dx2,dy2, dxy;
> dx2= (x1-x2)*(x1-x2);
> dy2= (y1-y2)*(y1-y2);
> dxy= (x1-x2)*(y1-y2);
> a dumb compiler does exactly what you want. A smart one, too, but
> in a different way. The expressions in parantheses are evaluated
> only once, stored in a register, or a unnamed variable, and used.
> Makes code faster, and slightly shorter.
> Next lines:
> R = dx2+dy2+dxy;
> return R;
i am not very proficient in the intricacies of floating point
arithmetic, and this is probably off-topic but both CSE and keeping
interim values in registers can cause subtle but serious problems when
dealing with floting point.
see
http://www.wam.umd.edu/whats_new/workshop3.0/common-tools/numerical_comp_guide/goldberg1.doc.html
for more information.
--
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA
mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/
- Raw text -