This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: What is acceptable for -ffast-math? (Was: associative law incombine)
- To: <dewar at gnat dot com>
- Subject: Re: What is acceptable for -ffast-math? (Was: associative law incombine)
- From: Linus Torvalds <torvalds at transmeta dot com>
- Date: Mon, 30 Jul 2001 10:00:43 -0700 (PDT)
- cc: <gcc at gcc dot gnu dot org>, <moshier at moshier dot ne dot mediaone dot net>, <tprince at computer dot org>
On Mon, 30 Jul 2001 dewar@gnat.com wrote:
>
> But if you look at real Fortran codes, they are full of parentheses to stop
> the compiler from messing around, and in fact most Fortran compilers do only
> very limited mucking even when no parens are present. I would be shocked
> to find a FOrtraqn compiler that changed
>
> a*c + b*c
>
> into
>
> (a+b)*c
>
> a totally diffrerent expression!
You'd be shocked?
What if I told you that it's actually legal? Go check it out.
Note that the mark of a language that generates fast code is that it both
(a) allows the compiler the maximum possible flexibility to do the best
job it can, and (b) allows the programmer to specify what the limits are.
Fortran, while being a pretty horrible language for anything else, does
exactly this for FP math. It doesn't do it for much anything else, of
course.
Now, the problem here is that what is permissible in Fortran is not
permissible in C, but I think we should _allow_ it to happen.
Note that I'm not really advocating breaking standards, like so many
people seem to think. If you actually go back and read my emails instead
of just reacting to them by gut feel, you'll notice that what I really
suggested was to make it _easy_ for the non-math programmer to tell the
compiler "do the best you can with this".
I argue _against_ a lot of magic compiler flags that are version-
dependent and hard to use, and I argue _for_ "-ffast-math" being very
strong.
I also argue that since we already have more standards than we can shake a
stick at (traditional, c89, gnu89, c99, etc), and C traditionally has not
been very strict about what optimizations are permissible, the argument of
"conforms to C99 by default" is not a very strong one. But I also noted
that it _is_ a very valid argument, although not as absolute as some
people seem to think it is (exactly because we do have multiple standards,
and gcc already defaults to a standard of its own rather than anything
else).
Linus