diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
| commit | 37da2899f40661e3e9631e497da8dc59b971cbd0 (patch) | |
| tree | cbc6d4680e347d906f5fa7fca73214418741df72 /libmath/FPcontrol-Irix.c | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'libmath/FPcontrol-Irix.c')
| -rw-r--r-- | libmath/FPcontrol-Irix.c | 102 |
1 files changed, 102 insertions, 0 deletions
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 <stdlib.h> +#include <sigfpe.h> +#include <sys/fpu.h> +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); +} |
