On Sat, Nov 29, 2008 at 09:41:30PM +0100, Tobias Burnus wrote:
>
> I'm thinking about how to implement Fortran 2003's IEEE support in
> gfortran. The IEEE allow
> a) To set an IEEE value (NaN, INF, etc.)
> b) Check whether a value is NaN, etc.
> c) To query for IEEE capabilities (IEEE_SUPPORT_NAN, IEEE_SUPPORT_SQRT
> (a sqrt() which has IEEE exception support), etc.)
> d) To query/set haltmodes for DIVIDE_BY_ZERO, INVALID etc.
> e) Getting/setting an exception flag, etc.
>
> While (a) and (b) can be easily handled in the front end, I don't see
> how I can handle the rest efficiently. Most parts are provided by
> fenv.h, for which I seemingly have to write a wrapper function (in
> libgfortran) as the typedefs and constants cannot be made available in
> the front end - or have I missed something?
>
> My biggest issue is that I don't see how I can compile-time evaluate the
> following - or how to evaluate it at all:
>
> if (IEEE_SUPPORT_NAN(x)) & ! should be always true (or false) on a
> given system
> x = IEEE_VALUE(IEEE_QUIET_NAN, x) ! x = qNaN (trivial in the front end).
>
> The Fortran standard lists: IEEE_SUPPORT_DENORMAL, _DIVIDE (by zero),
> _INF, _NAN, _SQRT (a sqrt which follows IEEE), _ROUNDING, (and _IO). Is
> there some possibility to query the target whether e.g. NaN is supported?
>
> For querying/setting the halting mode, I would work with the data in
> libgfortran/config/*.h.
>
I suspect we'll need to ping Richard Henderson and Kaveh Ghazi to
answer some these questions (ie., how to query a target). We may
be able to leverage some of builtin.defs. A quick 'grep fenv *'
in gcc/ shows
2007-05-19 Uros Bizjak <[EMAIL PROTECTED]>
* config/i386/sfp-machine.h (FP_EX_INVALID, FP_EX_DENORM,
FP_EXP_DIVZERO, FP_EX_OVERFLOW, FP_EX_UNDERFLOW, FP_EX_INEXACT):
New constants.
(struct fenv): New structure.
(FP_HANDLE_EXCEPTIONS): New define.
(FP_RND_NEAREST, FP_RND_ZERO, FP_RND_PINF, FP_RND_MINF): New constants.
(_FP_DECL_EXP): New define.
(FP_INIT_ROUNDMODE): New define.
(FP_ROUNDMODE): New define.
Perhaps, Uros might have a pointer.
There is an f) to include in the list. Currently, constant folding
always uses GFC_RND_MODE, which is GMP_RNDN (round-to-nearest).
We'll need to change the define to a static variable variable and set
it to an appropriate GMP_RNDx mode.
--
Steve