1*07f684ffSforsyth #include "lib9.h" 2*07f684ffSforsyth #include "mathi.h" 3*07f684ffSforsyth 4*07f684ffSforsyth void FPinit(void)5*07f684ffSforsythFPinit(void) 6*07f684ffSforsyth { 7*07f684ffSforsyth setfsr(0); /* Clear pending exceptions */ 8*07f684ffSforsyth setfcr(FPPDBL|FPRNR|FPINVAL|FPZDIV|FPUNFL|FPOVFL); 9*07f684ffSforsyth } 10*07f684ffSforsyth 11*07f684ffSforsyth ulong getFPstatus(void)12*07f684ffSforsythgetFPstatus(void) 13*07f684ffSforsyth { 14*07f684ffSforsyth ulong fsr = 0, fsr9 = getfsr(); 15*07f684ffSforsyth /* on specific machines, could be table lookup */ 16*07f684ffSforsyth if(fsr9&FPAINEX) fsr |= INEX; 17*07f684ffSforsyth if(fsr9&FPAOVFL) fsr |= OVFL; 18*07f684ffSforsyth if(fsr9&FPAUNFL) fsr |= UNFL; 19*07f684ffSforsyth if(fsr9&FPAZDIV) fsr |= ZDIV; 20*07f684ffSforsyth if(fsr9&FPAINVAL) fsr |= INVAL; 21*07f684ffSforsyth return fsr; 22*07f684ffSforsyth } 23*07f684ffSforsyth 24*07f684ffSforsyth ulong FPstatus(ulong fsr,ulong mask)25*07f684ffSforsythFPstatus(ulong fsr, ulong mask) 26*07f684ffSforsyth { 27*07f684ffSforsyth ulong fsr9 = 0; 28*07f684ffSforsyth ulong old = getFPstatus(); 29*07f684ffSforsyth fsr = (fsr&mask) | (old&~mask); 30*07f684ffSforsyth if(fsr&INEX) fsr9 |= FPAINEX; 31*07f684ffSforsyth if(fsr&OVFL) fsr9 |= FPAOVFL; 32*07f684ffSforsyth if(fsr&UNFL) fsr9 |= FPAUNFL; 33*07f684ffSforsyth if(fsr&ZDIV) fsr9 |= FPAZDIV; 34*07f684ffSforsyth if(fsr&INVAL) fsr9 |= FPAINVAL; 35*07f684ffSforsyth setfsr(fsr9); 36*07f684ffSforsyth return(old&mask); 37*07f684ffSforsyth } 38*07f684ffSforsyth 39*07f684ffSforsyth ulong getFPcontrol(void)40*07f684ffSforsythgetFPcontrol(void) 41*07f684ffSforsyth { 42*07f684ffSforsyth ulong fcr = 0, fcr9 = getfcr(); 43*07f684ffSforsyth switch(fcr9&FPRMASK){ 44*07f684ffSforsyth case FPRNR: fcr = RND_NR; break; 45*07f684ffSforsyth case FPRNINF: fcr = RND_NINF; break; 46*07f684ffSforsyth case FPRPINF: fcr = RND_PINF; break; 47*07f684ffSforsyth case FPRZ: fcr = RND_Z; break; 48*07f684ffSforsyth } 49*07f684ffSforsyth if(fcr9&FPINEX) fcr |= INEX; 50*07f684ffSforsyth if(fcr9&FPOVFL) fcr |= OVFL; 51*07f684ffSforsyth if(fcr9&FPUNFL) fcr |= UNFL; 52*07f684ffSforsyth if(fcr9&FPZDIV) fcr |= ZDIV; 53*07f684ffSforsyth if(fcr9&FPINVAL) fcr |= INVAL; 54*07f684ffSforsyth return fcr; 55*07f684ffSforsyth } 56*07f684ffSforsyth 57*07f684ffSforsyth ulong FPcontrol(ulong fcr,ulong mask)58*07f684ffSforsythFPcontrol(ulong fcr, ulong mask) 59*07f684ffSforsyth { 60*07f684ffSforsyth ulong fcr9 = FPPDBL; 61*07f684ffSforsyth ulong old = getFPcontrol(); 62*07f684ffSforsyth fcr = (fcr&mask) | (old&~mask); 63*07f684ffSforsyth if(fcr&INEX) fcr9 |= FPINEX; 64*07f684ffSforsyth if(fcr&OVFL) fcr9 |= FPOVFL; 65*07f684ffSforsyth if(fcr&UNFL) fcr9 |= FPUNFL; 66*07f684ffSforsyth if(fcr&ZDIV) fcr9 |= FPZDIV; 67*07f684ffSforsyth if(fcr&INVAL) fcr9 |= FPINVAL; 68*07f684ffSforsyth switch(fcr&RND_MASK){ 69*07f684ffSforsyth case RND_NR: fcr9 |= FPRNR; break; 70*07f684ffSforsyth case RND_NINF: fcr9 |= FPRNINF; break; 71*07f684ffSforsyth case RND_PINF: fcr9 |= FPRPINF; break; 72*07f684ffSforsyth case RND_Z: fcr9 |= FPRZ; break; 73*07f684ffSforsyth } 74*07f684ffSforsyth setfcr(fcr9); 75*07f684ffSforsyth return(old&mask); 76*07f684ffSforsyth } 77*07f684ffSforsyth 78