This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran,patch] Add option to raise FPE


Hi all,

Attached patch adds support for an interesting feature present in many
commercial compilers: raising a floating-point exception (FPE) when a
IEEE exception is encountered (invalid operation, such as sqrt(-1.0),
overflow, underflow, division by zero, loss of precision and denormal
numbers). This is very interesting for debugging, since it enables one to
know where a numerical computation have gone wrong, when you do not
expect NaN to creep into your results, for example.

Commercial compilers allow to do this with a compile-time option, which I
added to gfortran: I called it -ffpe-trap, though -ffpe-raise might be a
better name (any other ideas welcome). It is to be used in the following
way:
    gfortran fpe-test.f90 -ffpe-trap=invalid,overflow
where -ffpe-trap accepts a comma-separated list of IEEE exceptions
(invalid,overflow,underflow,zero,precision,denormal).

I completed the support for runtime selection of the cases when a FPE
should be raised. The library already read environment variables
GFORTRAN_FPU_* but did not use them. They are now used, and override
values specified at compile-time in case of a conflict.

The gory target-dependent assembler code (necessary since there is not
portable way to do these things) is in a new libgfortran/config
directory, following the way it is done for libstdc++-v3. For now, only
code for i?86 processors is included; I will provide code for other
platforms after proper testing (ppc, sparc, alpha). A fallback generic
configuration is provided, which warns the user that the option is not
(yet) supported on his FPU.

I gladly welcome any comment on this patch. Can someone review it?

FX

PS: two diffs are attached to this mail, one with the regenerated
files and one without them.

Attachment: fpe3.no_regenerated_files.diff
Description: Binary data

Attachment: fpe3.ChangeLog
Description: Binary data

Attachment: fpe3.diff
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]