Bug 36821 - Flush denormals to Zero Flag
Summary: Flush denormals to Zero Flag
Status: UNCONFIRMED
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
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-14 04:56 UTC by Jonathan Hogg
Modified: 2010-04-09 10:00 UTC (History)
2 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Hogg 2008-07-14 04:56: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:
   _MM_SET_FLUSH_ZERO_MODE (_MM_FLUSH_ZERO_ON);

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 05:51: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 06:04:55 UTC
-ffast-math also enables other (even more unsafe?) optimizations which may not be desirable.
Comment 3 Nick 2010-04-08 22:12: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

_MM_SET_FLUSH_ZERO_MODE (_MM_FLUSH_ZERO_ON); 
-ffast-math

The tradeoff of "either FTZ or Optimized" I think will not work for me.
Comment 4 Uroš Bizjak 2010-04-09 00:56: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 10:00: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