[gfortran,patch] Add option to raise FPE
François-Xavier Coudert
fxcoudert@gmail.com
Sat Aug 20 08:45:00 GMT 2005
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fpe3.no_regenerated_files.diff
Type: application/octet-stream
Size: 21386 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20050820/179f741a/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fpe3.ChangeLog
Type: application/octet-stream
Size: 1730 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20050820/179f741a/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fpe3.diff
Type: application/octet-stream
Size: 76706 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20050820/179f741a/attachment-0002.obj>
More information about the Fortran
mailing list