Re: Compiler optimization and floating point operations

Cameron McInally <cameron.mcinally@nyu.edu>
Mon, 28 Oct 2013 20:41:38 -0400

          From comp.compilers

Related articles
[4 earlier articles]
Re: Compiler optimization and floating point operations jm@bourguet.org (Jean-Marc Bourguet) (2013-10-24)
Re: Compiler optimization and floating point operations sgk@troutmask.apl.washington.edu (Steven G. Kargl) (2013-10-24)
Re: Compiler optimization and floating point operations gneuner2@comcast.net (George Neuner) (2013-10-24)
Re: Compiler optimization and floating point operations gah@ugcs.caltech.edu (glen herrmannsfeldt) (2013-10-24)
Re: Compiler optimization and floating point operations christian.bau@cbau.wanadoo.co.uk (2013-10-28)
Re: Compiler optimization and floating point operations christian.bau@cbau.wanadoo.co.uk (2013-10-28)
Re: Compiler optimization and floating point operations cameron.mcinally@nyu.edu (Cameron McInally) (2013-10-28)
| List of all articles for this month |

From: Cameron McInally <cameron.mcinally@nyu.edu>
Newsgroups: comp.compilers
Date: Mon, 28 Oct 2013 20:41:38 -0400
Organization: Compilers Central
References: 13-10-026 13-10-029 13-10-037
Keywords: optimize, arithmetic
Posted-Date: 28 Oct 2013 22:47:25 EDT

On Mon, Oct 28, 2013 at 6:50 PM, <christian.bau@cbau.wanadoo.co.uk> wrote:
>> [I think you mean they're not associative. I don't know any situations
>> where a+b != b+a, but lots where a+(b+c) != (a+b)+c -John]
>
> Take fused multiply-add, and the expression a*b + c*d.
> It can be evaluated either as fma (a, b, c*d) or fma (c, d, a*b).
>
> It would seem natural that the code for a*b + c*d and for c*d + a*b
> would be different, with different results.


Right, that's called reassociation. The order of operations in the
expression tree has changed, so the finite precision rounding occurs
on different intermediate results. The same problem exists in some
floating point parallel reductions and such.


Most compilers will offer a directive, similar to FP_CONTRACT, for
such critical pieces of code. Some compilers [the good ones ;)] even
have flags to disable optimization passes that involve reassociation.


-Cameron


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.