From 37da2899f40661e3e9631e497da8dc59b971cbd0 Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Fri, 22 Dec 2006 17:07:39 +0000 Subject: 20060303a --- libmath/FPcontrol-Irix.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 libmath/FPcontrol-Irix.c (limited to 'libmath/FPcontrol-Irix.c') diff --git a/libmath/FPcontrol-Irix.c b/libmath/FPcontrol-Irix.c new file mode 100644 index 00000000..7a215736 --- /dev/null +++ b/libmath/FPcontrol-Irix.c @@ -0,0 +1,102 @@ +/* Load programs with -lfpe. See man pages for fpc and /usr/include/sigfpe.h, sys/fpu.h. */ +#include +#include +#include +typedef unsigned int ulong; +#include "mathi.h" + +/* + * Irix does not permit a use handled SIGFPE since the floating point unit + * cannot be IEEE754 compliant without some software, so we must vector using + * the library + */ +extern void trapFPE(unsigned exception[5], int value[2]); + +void +FPinit(void) +{ + union fpc_csr csr; + int i; + for(i=1; i<=4; i++) { + sigfpe_[i].repls = _USER_DETERMINED; + sigfpe_[i].abort = 2; + } + handle_sigfpes(_ON, + _EN_UNDERFL|_EN_OVERFL|_EN_DIVZERO|_EN_INVALID, + trapFPE, + _ABORT_ON_ERROR, 0); +} + + +ulong +getFPstatus(void) +{ + ulong fsr = 0; + union fpc_csr csr; + csr.fc_word = get_fpc_csr(); + if(csr.fc_struct.se_inexact) fsr |= INEX; + if(csr.fc_struct.se_overflow) fsr |= OVFL; + if(csr.fc_struct.se_underflow) fsr |= UNFL; + if(csr.fc_struct.se_divide0) fsr |= ZDIV; + if(csr.fc_struct.se_invalid) fsr |= INVAL; + return fsr; +} + +ulong +FPstatus(ulong fsr, ulong mask) +{ + ulong old = getFPstatus(); + union fpc_csr csr; + csr.fc_word = get_fpc_csr(); + fsr = (fsr&mask) | (old&~mask); + csr.fc_struct.se_inexact = (fsr&INEX)?1:0; + csr.fc_struct.se_overflow = (fsr&OVFL)?1:0; + csr.fc_struct.se_underflow = (fsr&UNFL)?1:0; + csr.fc_struct.se_divide0 = (fsr&ZDIV)?1:0; + csr.fc_struct.se_invalid = (fsr&INVAL)?1:0; + set_fpc_csr(csr.fc_word); + return(old&mask); +} + +ulong +getFPcontrol(void) +{ + ulong fcr = 0; + union fpc_csr csr; + double junk = fabs(1.); /* avoid bug mentioned in sigfpes man page [ehg] */ + csr.fc_word = get_fpc_csr(); + switch(csr.fc_struct.rounding_mode){ + case ROUND_TO_NEAREST: fcr = RND_NR; break; + case ROUND_TO_MINUS_INFINITY: fcr = RND_NINF; break; + case ROUND_TO_PLUS_INFINITY: fcr = RND_PINF; break; + case ROUND_TO_ZERO: fcr = RND_Z; break; + } + if(csr.fc_struct.en_inexact) fcr |= INEX; + if(csr.fc_struct.en_overflow) fcr |= OVFL; + if(csr.fc_struct.en_underflow) fcr |= UNFL; + if(csr.fc_struct.en_divide0) fcr |= ZDIV; + if(csr.fc_struct.en_invalid) fcr |= INVAL; + return fcr; +} + +ulong +FPcontrol(ulong fcr, ulong mask) +{ + ulong old = getFPcontrol(); + union fpc_csr csr; + csr.fc_word = get_fpc_csr(); + fcr = (fcr&mask) | (old&~mask); + csr.fc_struct.en_inexact = (fcr&INEX)?1:0; + csr.fc_struct.en_overflow = (fcr&OVFL)?1:0; + csr.fc_struct.en_underflow = (fcr&UNFL)?1:0; + csr.fc_struct.en_divide0 = (fcr&ZDIV)?1:0; + csr.fc_struct.en_invalid = (fcr&INVAL)?1:0; + switch(fcr&RND_MASK){ + case RND_NR: csr.fc_struct.rounding_mode = ROUND_TO_NEAREST; break; + case RND_NINF: csr.fc_struct.rounding_mode = ROUND_TO_MINUS_INFINITY; break; + case RND_PINF: csr.fc_struct.rounding_mode = ROUND_TO_PLUS_INFINITY; break; + case RND_Z: csr.fc_struct.rounding_mode = ROUND_TO_ZERO; break; + } + set_fpc_csr(csr.fc_word); + return(old&mask); +} -- cgit v1.2.3