This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Parentheses not honored when using FMA
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: Marcin Krotkiewski <marcin dot krotkiewski at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 12 Aug 2015 13:03:03 +0200 (CEST)
- Subject: Re: Parentheses not honored when using FMA
- Authentication-results: sourceware.org; auth=none
- References: <55CB21EF dot 90908 at gmail dot com>
- Reply-to: gcc-help at gcc dot gnu dot org
On Wed, 12 Aug 2015, Marcin Krotkiewski wrote:
Hello, all,
I have doubts about asm generated for the following code that performs
orientation test for a point and a segment:
double orient_test_2d(const double m[2], const double a[2], const double
b[2])
{
double am1 = a[0]-m[0];
double bm1 = b[1]-m[1];
double am2 = a[1]-m[1];
double bm2 = b[0]-m[0];
return ((am1)*(bm1)) - ((am2)*(bm2));
}
In the return statement the operands are all in parentheses. gcc optimizes
Parentheses don't have the meaning you believe they have in C. All those
in your return statement are useless.
the statement and introduces a FMA instruction. I think this is wrong because
FMA causes the subtraction and multiplication to be effectively executed at
the same time, while the source specifies that the multiplications should be
performed before the subtraction.
-ffp-contract=off
--
Marc Glisse