User account creation filtered due to spam.

Bug 36821 - Flush denormals to Zero Flag
Summary: Flush denormals to Zero Flag
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.1
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2008-07-14 10:26 UTC by Jonathan Hogg
Modified: 2010-04-09 15:30 UTC (History)
2 users (show)

See Also:
Target: i?86-*-* x86_64-*-*
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Hogg 2008-07-14 10:26:38 UTC
On current x86 and x86_64 processors denormal numbers are handled as a special case and very slowly. This can have a detrimental impact on the performance of numerical programs. A common fix for this problem, at the cost of some numerical stability, is to set the processor flag to flush denormals to zero.

This can be achieved in C with the following on SSE machines:

However it is not desirable to include C in a fortran program or library. Other compiler tackle this by adding flags (ifort, NAG f95) or environment variables (g95) which set this flush mode during program initialization. It would be good if gfortran offered a similar facility (I have not been able to locate any reference to one at the moment).
Comment 1 Richard Biener 2008-07-14 11:21:03 UTC
Compiling with -ffast-math will automatically do that at program startup time
via linking against crtfastmath.o.
Comment 2 Jonathan Hogg 2008-07-14 11:34:55 UTC
-ffast-math also enables other (even more unsafe?) optimizations which may not be desirable.
Comment 3 Nick 2010-04-09 03:42:59 UTC
I am looking for both Optimized like O2 and FTZ.  I have a large Fortran program.  Without FTZ it gets weird crashes that should not be happening (no problems on any other compilers!)  Without optimization it runs way too slow.

Any optimization overrides any attempts at FTZ, such as


The tradeoff of "either FTZ or Optimized" I think will not work for me.
Comment 4 Uroš Bizjak 2010-04-09 06:26:18 UTC
(In reply to comment #3)

> The tradeoff of "either FTZ or Optimized" I think will not work for me.

Find crtfastmath.o in gcc build directory and link it to your final executable.
Comment 5 Nick 2010-04-09 15:30:54 UTC
I'm still not getting FTZ ... unless I misunderstood your suggestion, here's what I did after compiling with -O2:

root@nick-desktop:/home/test408# gfortran -o test4f /usr/lib/gcc/i486-linux-gnu/4.4.0/crtfastmath.o TEST4SRC1.o TEST4SRC2.o TEST4SRCU.o