|
Packit |
67cb25 |
/* ieee-utils/fp-tru64.c
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Tim Mooney
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
67cb25 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
67cb25 |
* the Free Software Foundation; either version 3 of the License, or (at
|
|
Packit |
67cb25 |
* your option) any later version.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is distributed in the hope that it will be useful, but
|
|
Packit |
67cb25 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
67cb25 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
67cb25 |
* General Public License for more details.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
67cb25 |
* along with this program; if not, write to the Free Software
|
|
Packit |
67cb25 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/*
|
|
Packit |
67cb25 |
* Under Compaq's Unix with the silly name, read the man pages for read_rnd,
|
|
Packit |
67cb25 |
* write_rnd, and ieee(3) for more information on the functions used here.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* Note that enabling control of dynamic rounding mode (via write_rnd) requires
|
|
Packit |
67cb25 |
* that you pass a special flag to your C compiler. For Compaq's C compiler
|
|
Packit |
67cb25 |
* the flag is `-fprm d', for gcc it's `-mfp-rounding-mode=d'.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* Enabling the trap control (via ieee_set_fp_control) also requires a
|
|
Packit |
67cb25 |
* flag be passed to the C compiler. The flag for Compaq's C compiler
|
|
Packit |
67cb25 |
* is `-ieee' and for gcc it's `-mieee'.
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
* We have not implemented the `inexact' case, since it is rarely used
|
|
Packit |
67cb25 |
* and requires the library being built with an additional compiler
|
|
Packit |
67cb25 |
* flag that can degrade performance for everything else. If you need
|
|
Packit |
67cb25 |
* to add support for `inexact' the relevant flag for Compaq's
|
|
Packit |
67cb25 |
* compiler is `-ieee_with_inexact', and the flag for gcc is
|
|
Packit |
67cb25 |
* `-mieee-with-inexact'.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* Problem have been reported with the "fixed" float.h installed with
|
|
Packit |
67cb25 |
* gcc-2.95 lacking some of the definitions in the system float.h (the
|
|
Packit |
67cb25 |
* symptoms are errors like: `FP_RND_RN' undeclared). To work around
|
|
Packit |
67cb25 |
* this we can include the system float.h before the gcc version, e.g.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* #include "/usr/include/float.h"
|
|
Packit |
67cb25 |
* #include <float.h>
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#include <float.h>
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#ifndef FP_RND_RN
|
|
Packit |
67cb25 |
# undef _FLOAT_H_
|
|
Packit |
67cb25 |
# include "/usr/include/float.h"
|
|
Packit |
67cb25 |
# undef _FLOAT_H_
|
|
Packit |
67cb25 |
# include <float.h>
|
|
Packit |
67cb25 |
#endif
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#include <machine/fpu.h>
|
|
Packit |
67cb25 |
#include <stdio.h>
|
|
Packit |
67cb25 |
#include <gsl/gsl_ieee_utils.h>
|
|
Packit |
67cb25 |
#include <gsl/gsl_errno.h>
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
int
|
|
Packit |
67cb25 |
gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
unsigned long int mode = 0 ;
|
|
Packit |
67cb25 |
unsigned int rnd = 0 ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* I'm actually not completely sure that the alpha only supports default
|
|
Packit |
67cb25 |
* precisions rounding, but I couldn't find any information regarding this, so
|
|
Packit |
67cb25 |
* it seems safe to assume this for now until it's proven otherwise.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
switch (precision)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
case GSL_IEEE_SINGLE_PRECISION:
|
|
Packit |
67cb25 |
GSL_ERROR ("Tru64 Unix on the alpha only supports default precision rounding",
|
|
Packit |
67cb25 |
GSL_EUNSUP) ;
|
|
Packit |
67cb25 |
break ;
|
|
Packit |
67cb25 |
case GSL_IEEE_DOUBLE_PRECISION:
|
|
Packit |
67cb25 |
GSL_ERROR ("Tru64 Unix on the alpha only supports default precision rounding",
|
|
Packit |
67cb25 |
GSL_EUNSUP) ;
|
|
Packit |
67cb25 |
break ;
|
|
Packit |
67cb25 |
case GSL_IEEE_EXTENDED_PRECISION:
|
|
Packit |
67cb25 |
GSL_ERROR ("Tru64 Unix on the alpha only supports default precision rounding",
|
|
Packit |
67cb25 |
GSL_EUNSUP) ;
|
|
Packit |
67cb25 |
break ;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
switch (rounding)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
case GSL_IEEE_ROUND_TO_NEAREST:
|
|
Packit |
67cb25 |
rnd = FP_RND_RN ;
|
|
Packit |
67cb25 |
write_rnd (rnd) ;
|
|
Packit |
67cb25 |
break ;
|
|
Packit |
67cb25 |
case GSL_IEEE_ROUND_DOWN:
|
|
Packit |
67cb25 |
rnd = FP_RND_RM ;
|
|
Packit |
67cb25 |
write_rnd (rnd) ;
|
|
Packit |
67cb25 |
break ;
|
|
Packit |
67cb25 |
case GSL_IEEE_ROUND_UP:
|
|
Packit |
67cb25 |
rnd = FP_RND_RP ;
|
|
Packit |
67cb25 |
write_rnd (rnd) ;
|
|
Packit |
67cb25 |
break ;
|
|
Packit |
67cb25 |
case GSL_IEEE_ROUND_TO_ZERO:
|
|
Packit |
67cb25 |
rnd = FP_RND_RZ ;
|
|
Packit |
67cb25 |
write_rnd (rnd) ;
|
|
Packit |
67cb25 |
break ;
|
|
Packit |
67cb25 |
default:
|
|
Packit |
67cb25 |
rnd = FP_RND_RN ;
|
|
Packit |
67cb25 |
write_rnd (rnd) ;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* Turn on all the exceptions apart from 'inexact' */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* from the ieee(3) man page:
|
|
Packit |
67cb25 |
* IEEE_TRAP_ENABLE_INV -> Invalid operation
|
|
Packit |
67cb25 |
* IEEE_TRAP_ENABLE_DZE -> Divide by 0
|
|
Packit |
67cb25 |
* IEEE_TRAP_ENABLE_OVF -> Overflow
|
|
Packit |
67cb25 |
* IEEE_TRAP_ENABLE_UNF -> Underflow
|
|
Packit |
67cb25 |
* IEEE_TRAP_ENABLE_INE -> Inexact (requires special option to C compiler)
|
|
Packit |
67cb25 |
* IEEE_TRAP_ENABLE_DNO -> denormal operand
|
|
Packit |
67cb25 |
* Note: IEEE_TRAP_ENABLE_DNO is not supported on OSF 3.x or Digital Unix
|
|
Packit |
67cb25 |
* 4.0 - 4.0d(?).
|
|
Packit |
67cb25 |
* IEEE_TRAP_ENABLE_MASK -> mask of all the trap enables
|
|
Packit |
67cb25 |
* IEEE_MAP_DMZ -> map denormal inputs to zero
|
|
Packit |
67cb25 |
* IEEE_MAP_UMZ -> map underflow results to zero
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
mode = IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE | IEEE_TRAP_ENABLE_OVF
|
|
Packit |
67cb25 |
| IEEE_TRAP_ENABLE_UNF ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
if (exception_mask & GSL_IEEE_MASK_INVALID)
|
|
Packit |
67cb25 |
mode &= ~ IEEE_TRAP_ENABLE_INV ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
#ifdef IEEE_TRAP_ENABLE_DNO
|
|
Packit |
67cb25 |
mode &= ~ IEEE_TRAP_ENABLE_DNO ;
|
|
Packit |
67cb25 |
#else
|
|
Packit |
67cb25 |
GSL_ERROR ("Sorry, this version of Digital Unix does not support denormalized operands", GSL_EUNSUP) ;
|
|
Packit |
67cb25 |
#endif
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
|
|
Packit |
67cb25 |
mode &= ~ IEEE_TRAP_ENABLE_DZE ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
|
|
Packit |
67cb25 |
mode &= ~ IEEE_TRAP_ENABLE_OVF ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
|
|
Packit |
67cb25 |
mode &= ~ IEEE_TRAP_ENABLE_UNF ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
if (exception_mask & GSL_IEEE_TRAP_INEXACT)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
/* To implement this would require a special flag to the C
|
|
Packit |
67cb25 |
compiler which can cause degraded performance */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
GSL_ERROR ("Sorry, GSL does not implement trap-inexact for Tru64 Unix on the alpha - see fp-tru64.c for details", GSL_EUNSUP) ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* In case you need to add it, the appropriate line would be
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* mode |= IEEE_TRAP_ENABLE_INE ;
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
else
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
mode &= ~ IEEE_TRAP_ENABLE_INE ;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
ieee_set_fp_control (mode) ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
return GSL_SUCCESS ;
|
|
Packit |
67cb25 |
}
|