2005-10-28 22:13:20 +02:00
|
|
|
/* SysV FPU-related code (for systems not otherwise supported).
|
2013-01-14 19:20:58 +01:00
|
|
|
Copyright (C) 2005-2013 Free Software Foundation, Inc.
|
2005-10-28 22:13:20 +02:00
|
|
|
Contributed by Francois-Xavier Coudert <coudert@clipper.ens.fr>
|
|
|
|
|
2011-05-14 09:55:51 +02:00
|
|
|
This file is part of the GNU Fortran runtime library (libgfortran).
|
2005-10-28 22:13:20 +02:00
|
|
|
|
|
|
|
Libgfortran is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
2009-04-09 17:00:19 +02:00
|
|
|
version 3 of the License, or (at your option) any later version.
|
2005-10-28 22:13:20 +02:00
|
|
|
|
|
|
|
Libgfortran is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
|
|
3.1, as published by the Free Software Foundation.
|
2005-10-28 22:13:20 +02:00
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
You should have received a copy of the GNU General Public License and
|
|
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2005-10-28 22:13:20 +02:00
|
|
|
|
|
|
|
/* FPU-related code for SysV platforms with fpsetmask(). */
|
|
|
|
|
|
|
|
void
|
|
|
|
set_fpu (void)
|
|
|
|
{
|
|
|
|
int cw = 0;
|
|
|
|
|
|
|
|
if (options.fpe & GFC_FPE_INVALID)
|
|
|
|
#ifdef FP_X_INV
|
|
|
|
cw |= FP_X_INV;
|
|
|
|
#else
|
2011-05-14 09:55:51 +02:00
|
|
|
estr_write ("Fortran runtime warning: IEEE 'invalid operation' "
|
|
|
|
"exception not supported.\n");
|
2005-10-28 22:13:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (options.fpe & GFC_FPE_DENORMAL)
|
|
|
|
#ifdef FP_X_DNML
|
|
|
|
cw |= FP_X_DNML;
|
|
|
|
#else
|
2011-05-20 14:55:45 +02:00
|
|
|
estr_write ("Fortran runtime warning: Floating point 'denormal operand' "
|
2011-05-14 09:55:51 +02:00
|
|
|
"exception not supported.\n");
|
2005-10-28 22:13:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (options.fpe & GFC_FPE_ZERO)
|
|
|
|
#ifdef FP_X_DZ
|
|
|
|
cw |= FP_X_DZ;
|
|
|
|
#else
|
2011-05-14 09:55:51 +02:00
|
|
|
estr_write ("Fortran runtime warning: IEEE 'division by zero' "
|
|
|
|
"exception not supported.\n");
|
2005-10-28 22:13:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (options.fpe & GFC_FPE_OVERFLOW)
|
|
|
|
#ifdef FP_X_OFL
|
|
|
|
cw |= FP_X_OFL;
|
|
|
|
#else
|
2011-05-14 09:55:51 +02:00
|
|
|
estr_write ("Fortran runtime warning: IEEE 'overflow' "
|
|
|
|
"exception not supported.\n");
|
2005-10-28 22:13:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (options.fpe & GFC_FPE_UNDERFLOW)
|
|
|
|
#ifdef FP_X_UFL
|
|
|
|
cw |= FP_X_UFL;
|
|
|
|
#else
|
2011-05-14 09:55:51 +02:00
|
|
|
estr_write ("Fortran runtime warning: IEEE 'underflow' "
|
|
|
|
"exception not supported.\n");
|
2005-10-28 22:13:20 +02:00
|
|
|
#endif
|
|
|
|
|
2011-05-20 14:55:45 +02:00
|
|
|
if (options.fpe & GFC_FPE_INEXACT)
|
2005-10-28 22:13:20 +02:00
|
|
|
#ifdef FP_X_IMP
|
|
|
|
cw |= FP_X_IMP;
|
|
|
|
#else
|
2011-05-20 14:55:45 +02:00
|
|
|
estr_write ("Fortran runtime warning: IEEE 'inexact' "
|
2011-05-14 09:55:51 +02:00
|
|
|
"exception not supported.\n");
|
2005-10-28 22:13:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
fpsetmask(cw);
|
|
|
|
}
|
2013-06-17 09:48:21 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
get_fpu_except_flags (void)
|
|
|
|
{
|
|
|
|
int result;
|
2013-06-24 10:34:05 +02:00
|
|
|
#if HAVE_FP_EXCEPT
|
2013-06-21 15:16:57 +02:00
|
|
|
fp_except set_excepts;
|
2013-06-24 10:34:05 +02:00
|
|
|
#elif HAVE_FP_EXCEPT_T
|
|
|
|
fp_except_t set_excepts;
|
|
|
|
#else
|
|
|
|
choke me
|
|
|
|
#endif
|
2013-06-17 09:48:21 +02:00
|
|
|
|
|
|
|
result = 0;
|
|
|
|
set_excepts = fpgetsticky ();
|
|
|
|
|
|
|
|
#ifdef FP_X_INV
|
|
|
|
if (set_excepts & FP_X_INV)
|
|
|
|
result |= GFC_FPE_INVALID;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FP_X_DZ
|
|
|
|
if (set_excepts & FP_X_DZ)
|
|
|
|
result |= GFC_FPE_ZERO;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FP_X_OFL
|
|
|
|
if (set_excepts & FP_X_OFL)
|
|
|
|
result |= GFC_FPE_OVERFLOW;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FP_X_UFL
|
|
|
|
if (set_excepts & FP_X_UFL)
|
|
|
|
result |= GFC_FPE_UNDERFLOW;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FP_X_DNML
|
|
|
|
if (set_excepts & FP_X_DNML)
|
|
|
|
result |= GFC_FPE_DENORMAL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FP_X_IMP
|
|
|
|
if (set_excepts & FP_X_IMP)
|
|
|
|
result |= GFC_FPE_INEXACT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2013-07-21 13:54:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
get_fpu_rounding_mode (void)
|
|
|
|
{
|
|
|
|
switch (fpgetround ())
|
|
|
|
{
|
|
|
|
#ifdef FP_RN
|
|
|
|
case FP_RN:
|
|
|
|
return GFC_FPE_TONEAREST;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FP_RP
|
|
|
|
case FP_RP:
|
|
|
|
return GFC_FPE_UPWARD;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FP_RM
|
|
|
|
case FP_RM:
|
|
|
|
return GFC_FPE_DOWNWARD;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FP_RZ
|
|
|
|
case FP_RZ:
|
|
|
|
return GFC_FPE_TOWARDZERO;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return GFC_FPE_INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
set_fpu_rounding_mode (int mode)
|
|
|
|
{
|
|
|
|
#if HAVE_FP_RND
|
|
|
|
fp_rnd rnd_mode;
|
|
|
|
#elif HAVE_FP_RND_T
|
|
|
|
fp_rnd_t rnd_mode;
|
|
|
|
#else
|
|
|
|
choke me
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
#ifdef FP_RN
|
|
|
|
case GFC_FPE_TONEAREST:
|
|
|
|
rnd_mode = FP_RN;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FP_RP
|
|
|
|
case GFC_FPE_UPWARD:
|
|
|
|
rnd_mode = FP_RP;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FP_RM
|
|
|
|
case GFC_FPE_DOWNWARD:
|
|
|
|
rnd_mode = FP_RM;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FP_RZ
|
|
|
|
case GFC_FPE_TOWARDZERO:
|
|
|
|
rnd_mode = FP_RZ;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fpsetround (rnd_mode);
|
|
|
|
}
|