1*1da177e4SLinus Torvalds /* 2*1da177e4SLinus Torvalds * Linux/PA-RISC Project (http://www.parisc-linux.org/) 3*1da177e4SLinus Torvalds * 4*1da177e4SLinus Torvalds * Floating-point emulation code 5*1da177e4SLinus Torvalds * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org> 6*1da177e4SLinus Torvalds * 7*1da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 8*1da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 9*1da177e4SLinus Torvalds * the Free Software Foundation; either version 2, or (at your option) 10*1da177e4SLinus Torvalds * any later version. 11*1da177e4SLinus Torvalds * 12*1da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 13*1da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 14*1da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*1da177e4SLinus Torvalds * GNU General Public License for more details. 16*1da177e4SLinus Torvalds * 17*1da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 18*1da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 19*1da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20*1da177e4SLinus Torvalds */ 21*1da177e4SLinus Torvalds 22*1da177e4SLinus Torvalds #ifdef __NO_PA_HDRS 23*1da177e4SLinus Torvalds PA header file -- do not include this header file for non-PA builds. 24*1da177e4SLinus Torvalds #endif 25*1da177e4SLinus Torvalds 26*1da177e4SLinus Torvalds /* 27*1da177e4SLinus Torvalds * Some more constants 28*1da177e4SLinus Torvalds */ 29*1da177e4SLinus Torvalds #define SGL_FX_MAX_EXP 30 30*1da177e4SLinus Torvalds #define DBL_FX_MAX_EXP 62 31*1da177e4SLinus Torvalds #define QUAD_FX_MAX_EXP 126 32*1da177e4SLinus Torvalds 33*1da177e4SLinus Torvalds #define Dintp1(object) (object) 34*1da177e4SLinus Torvalds #define Dintp2(object) (object) 35*1da177e4SLinus Torvalds 36*1da177e4SLinus Torvalds #define Duintp1(object) (object) 37*1da177e4SLinus Torvalds #define Duintp2(object) (object) 38*1da177e4SLinus Torvalds 39*1da177e4SLinus Torvalds #define Qintp0(object) (object) 40*1da177e4SLinus Torvalds #define Qintp1(object) (object) 41*1da177e4SLinus Torvalds #define Qintp2(object) (object) 42*1da177e4SLinus Torvalds #define Qintp3(object) (object) 43*1da177e4SLinus Torvalds 44*1da177e4SLinus Torvalds 45*1da177e4SLinus Torvalds /* 46*1da177e4SLinus Torvalds * These macros will be used specifically by the convert instructions. 47*1da177e4SLinus Torvalds * 48*1da177e4SLinus Torvalds * 49*1da177e4SLinus Torvalds * Single format macros 50*1da177e4SLinus Torvalds */ 51*1da177e4SLinus Torvalds 52*1da177e4SLinus Torvalds #define Sgl_to_dbl_exponent(src_exponent,dest) \ 53*1da177e4SLinus Torvalds Deposit_dexponent(dest,src_exponent+(DBL_BIAS-SGL_BIAS)) 54*1da177e4SLinus Torvalds 55*1da177e4SLinus Torvalds #define Sgl_to_dbl_mantissa(src_mantissa,destA,destB) \ 56*1da177e4SLinus Torvalds Deposit_dmantissap1(destA,src_mantissa>>3); \ 57*1da177e4SLinus Torvalds Dmantissap2(destB) = src_mantissa << 29 58*1da177e4SLinus Torvalds 59*1da177e4SLinus Torvalds #define Sgl_isinexact_to_fix(sgl_value,exponent) \ 60*1da177e4SLinus Torvalds ((exponent < (SGL_P - 1)) ? \ 61*1da177e4SLinus Torvalds (Sall(sgl_value) << (SGL_EXP_LENGTH + 1 + exponent)) : FALSE) 62*1da177e4SLinus Torvalds 63*1da177e4SLinus Torvalds #define Int_isinexact_to_sgl(int_value) (int_value << 33 - SGL_EXP_LENGTH) 64*1da177e4SLinus Torvalds 65*1da177e4SLinus Torvalds #define Sgl_roundnearest_from_int(int_value,sgl_value) \ 66*1da177e4SLinus Torvalds if (int_value & 1<<(SGL_EXP_LENGTH - 2)) /* round bit */ \ 67*1da177e4SLinus Torvalds if ((int_value << 34 - SGL_EXP_LENGTH) || Slow(sgl_value)) \ 68*1da177e4SLinus Torvalds Sall(sgl_value)++ 69*1da177e4SLinus Torvalds 70*1da177e4SLinus Torvalds #define Dint_isinexact_to_sgl(dint_valueA,dint_valueB) \ 71*1da177e4SLinus Torvalds ((Dintp1(dint_valueA) << 33 - SGL_EXP_LENGTH) || Dintp2(dint_valueB)) 72*1da177e4SLinus Torvalds 73*1da177e4SLinus Torvalds #define Sgl_roundnearest_from_dint(dint_valueA,dint_valueB,sgl_value) \ 74*1da177e4SLinus Torvalds if (Dintp1(dint_valueA) & 1<<(SGL_EXP_LENGTH - 2)) \ 75*1da177e4SLinus Torvalds if ((Dintp1(dint_valueA) << 34 - SGL_EXP_LENGTH) || \ 76*1da177e4SLinus Torvalds Dintp2(dint_valueB) || Slow(sgl_value)) Sall(sgl_value)++ 77*1da177e4SLinus Torvalds 78*1da177e4SLinus Torvalds #define Dint_isinexact_to_dbl(dint_value) \ 79*1da177e4SLinus Torvalds (Dintp2(dint_value) << 33 - DBL_EXP_LENGTH) 80*1da177e4SLinus Torvalds 81*1da177e4SLinus Torvalds #define Dbl_roundnearest_from_dint(dint_opndB,dbl_opndA,dbl_opndB) \ 82*1da177e4SLinus Torvalds if (Dintp2(dint_opndB) & 1<<(DBL_EXP_LENGTH - 2)) \ 83*1da177e4SLinus Torvalds if ((Dintp2(dint_opndB) << 34 - DBL_EXP_LENGTH) || Dlowp2(dbl_opndB)) \ 84*1da177e4SLinus Torvalds if ((++Dallp2(dbl_opndB))==0) Dallp1(dbl_opndA)++ 85*1da177e4SLinus Torvalds 86*1da177e4SLinus Torvalds #define Sgl_isone_roundbit(sgl_value,exponent) \ 87*1da177e4SLinus Torvalds ((Sall(sgl_value) << (SGL_EXP_LENGTH + 1 + exponent)) >> 31) 88*1da177e4SLinus Torvalds 89*1da177e4SLinus Torvalds #define Sgl_isone_stickybit(sgl_value,exponent) \ 90*1da177e4SLinus Torvalds (exponent < (SGL_P - 2) ? \ 91*1da177e4SLinus Torvalds Sall(sgl_value) << (SGL_EXP_LENGTH + 2 + exponent) : FALSE) 92*1da177e4SLinus Torvalds 93*1da177e4SLinus Torvalds 94*1da177e4SLinus Torvalds /* 95*1da177e4SLinus Torvalds * Double format macros 96*1da177e4SLinus Torvalds */ 97*1da177e4SLinus Torvalds 98*1da177e4SLinus Torvalds #define Dbl_to_sgl_exponent(src_exponent,dest) \ 99*1da177e4SLinus Torvalds dest = src_exponent + (SGL_BIAS - DBL_BIAS) 100*1da177e4SLinus Torvalds 101*1da177e4SLinus Torvalds #define Dbl_to_sgl_mantissa(srcA,srcB,dest,inexact,guard,sticky,odd) \ 102*1da177e4SLinus Torvalds Shiftdouble(Dmantissap1(srcA),Dmantissap2(srcB),29,dest); \ 103*1da177e4SLinus Torvalds guard = Dbit3p2(srcB); \ 104*1da177e4SLinus Torvalds sticky = Dallp2(srcB)<<4; \ 105*1da177e4SLinus Torvalds inexact = guard | sticky; \ 106*1da177e4SLinus Torvalds odd = Dbit2p2(srcB) 107*1da177e4SLinus Torvalds 108*1da177e4SLinus Torvalds #define Dbl_to_sgl_denormalized(srcA,srcB,exp,dest,inexact,guard,sticky,odd,tiny) \ 109*1da177e4SLinus Torvalds Deposit_dexponent(srcA,1); \ 110*1da177e4SLinus Torvalds tiny = TRUE; \ 111*1da177e4SLinus Torvalds if (exp >= -2) { \ 112*1da177e4SLinus Torvalds if (exp == 0) { \ 113*1da177e4SLinus Torvalds inexact = Dallp2(srcB) << 3; \ 114*1da177e4SLinus Torvalds guard = inexact >> 31; \ 115*1da177e4SLinus Torvalds sticky = inexact << 1; \ 116*1da177e4SLinus Torvalds Shiftdouble(Dmantissap1(srcA),Dmantissap2(srcB),29,dest); \ 117*1da177e4SLinus Torvalds odd = dest << 31; \ 118*1da177e4SLinus Torvalds if (inexact) { \ 119*1da177e4SLinus Torvalds switch(Rounding_mode()) { \ 120*1da177e4SLinus Torvalds case ROUNDPLUS: \ 121*1da177e4SLinus Torvalds if (Dbl_iszero_sign(srcA)) { \ 122*1da177e4SLinus Torvalds dest++; \ 123*1da177e4SLinus Torvalds if (Sgl_isone_hidden(dest)) \ 124*1da177e4SLinus Torvalds tiny = FALSE; \ 125*1da177e4SLinus Torvalds dest--; \ 126*1da177e4SLinus Torvalds } \ 127*1da177e4SLinus Torvalds break; \ 128*1da177e4SLinus Torvalds case ROUNDMINUS: \ 129*1da177e4SLinus Torvalds if (Dbl_isone_sign(srcA)) { \ 130*1da177e4SLinus Torvalds dest++; \ 131*1da177e4SLinus Torvalds if (Sgl_isone_hidden(dest)) \ 132*1da177e4SLinus Torvalds tiny = FALSE; \ 133*1da177e4SLinus Torvalds dest--; \ 134*1da177e4SLinus Torvalds } \ 135*1da177e4SLinus Torvalds break; \ 136*1da177e4SLinus Torvalds case ROUNDNEAREST: \ 137*1da177e4SLinus Torvalds if (guard && (sticky || odd)) { \ 138*1da177e4SLinus Torvalds dest++; \ 139*1da177e4SLinus Torvalds if (Sgl_isone_hidden(dest)) \ 140*1da177e4SLinus Torvalds tiny = FALSE; \ 141*1da177e4SLinus Torvalds dest--; \ 142*1da177e4SLinus Torvalds } \ 143*1da177e4SLinus Torvalds break; \ 144*1da177e4SLinus Torvalds } \ 145*1da177e4SLinus Torvalds } \ 146*1da177e4SLinus Torvalds /* shift right by one to get correct result */ \ 147*1da177e4SLinus Torvalds guard = odd; \ 148*1da177e4SLinus Torvalds sticky = inexact; \ 149*1da177e4SLinus Torvalds inexact |= guard; \ 150*1da177e4SLinus Torvalds dest >>= 1; \ 151*1da177e4SLinus Torvalds Deposit_dsign(srcA,0); \ 152*1da177e4SLinus Torvalds Shiftdouble(Dallp1(srcA),Dallp2(srcB),30,dest); \ 153*1da177e4SLinus Torvalds odd = dest << 31; \ 154*1da177e4SLinus Torvalds } \ 155*1da177e4SLinus Torvalds else { \ 156*1da177e4SLinus Torvalds inexact = Dallp2(srcB) << (2 + exp); \ 157*1da177e4SLinus Torvalds guard = inexact >> 31; \ 158*1da177e4SLinus Torvalds sticky = inexact << 1; \ 159*1da177e4SLinus Torvalds Deposit_dsign(srcA,0); \ 160*1da177e4SLinus Torvalds if (exp == -2) dest = Dallp1(srcA); \ 161*1da177e4SLinus Torvalds else Variable_shift_double(Dallp1(srcA),Dallp2(srcB),30-exp,dest); \ 162*1da177e4SLinus Torvalds odd = dest << 31; \ 163*1da177e4SLinus Torvalds } \ 164*1da177e4SLinus Torvalds } \ 165*1da177e4SLinus Torvalds else { \ 166*1da177e4SLinus Torvalds Deposit_dsign(srcA,0); \ 167*1da177e4SLinus Torvalds if (exp > (1 - SGL_P)) { \ 168*1da177e4SLinus Torvalds dest = Dallp1(srcA) >> (- 2 - exp); \ 169*1da177e4SLinus Torvalds inexact = Dallp1(srcA) << (34 + exp); \ 170*1da177e4SLinus Torvalds guard = inexact >> 31; \ 171*1da177e4SLinus Torvalds sticky = (inexact << 1) | Dallp2(srcB); \ 172*1da177e4SLinus Torvalds inexact |= Dallp2(srcB); \ 173*1da177e4SLinus Torvalds odd = dest << 31; \ 174*1da177e4SLinus Torvalds } \ 175*1da177e4SLinus Torvalds else { \ 176*1da177e4SLinus Torvalds dest = 0; \ 177*1da177e4SLinus Torvalds inexact = Dallp1(srcA) | Dallp2(srcB); \ 178*1da177e4SLinus Torvalds if (exp == (1 - SGL_P)) { \ 179*1da177e4SLinus Torvalds guard = Dhidden(srcA); \ 180*1da177e4SLinus Torvalds sticky = Dmantissap1(srcA) | Dallp2(srcB); \ 181*1da177e4SLinus Torvalds } \ 182*1da177e4SLinus Torvalds else { \ 183*1da177e4SLinus Torvalds guard = 0; \ 184*1da177e4SLinus Torvalds sticky = inexact; \ 185*1da177e4SLinus Torvalds } \ 186*1da177e4SLinus Torvalds odd = 0; \ 187*1da177e4SLinus Torvalds } \ 188*1da177e4SLinus Torvalds } \ 189*1da177e4SLinus Torvalds exp = 0 190*1da177e4SLinus Torvalds 191*1da177e4SLinus Torvalds #define Dbl_isinexact_to_fix(dbl_valueA,dbl_valueB,exponent) \ 192*1da177e4SLinus Torvalds (exponent < (DBL_P-33) ? \ 193*1da177e4SLinus Torvalds Dallp2(dbl_valueB) || Dallp1(dbl_valueA) << (DBL_EXP_LENGTH+1+exponent) : \ 194*1da177e4SLinus Torvalds (exponent < (DBL_P-1) ? Dallp2(dbl_valueB) << (exponent + (33-DBL_P)) : \ 195*1da177e4SLinus Torvalds FALSE)) 196*1da177e4SLinus Torvalds 197*1da177e4SLinus Torvalds #define Dbl_isoverflow_to_int(exponent,dbl_valueA,dbl_valueB) \ 198*1da177e4SLinus Torvalds ((exponent > SGL_FX_MAX_EXP + 1) || Dsign(dbl_valueA)==0 || \ 199*1da177e4SLinus Torvalds Dmantissap1(dbl_valueA)!=0 || (Dallp2(dbl_valueB)>>21)!=0 ) 200*1da177e4SLinus Torvalds 201*1da177e4SLinus Torvalds #define Dbl_isone_roundbit(dbl_valueA,dbl_valueB,exponent) \ 202*1da177e4SLinus Torvalds ((exponent < (DBL_P - 33) ? \ 203*1da177e4SLinus Torvalds Dallp1(dbl_valueA) >> ((30 - DBL_EXP_LENGTH) - exponent) : \ 204*1da177e4SLinus Torvalds Dallp2(dbl_valueB) >> ((DBL_P - 2) - exponent)) & 1) 205*1da177e4SLinus Torvalds 206*1da177e4SLinus Torvalds #define Dbl_isone_stickybit(dbl_valueA,dbl_valueB,exponent) \ 207*1da177e4SLinus Torvalds (exponent < (DBL_P-34) ? \ 208*1da177e4SLinus Torvalds (Dallp2(dbl_valueB) || Dallp1(dbl_valueA)<<(DBL_EXP_LENGTH+2+exponent)) : \ 209*1da177e4SLinus Torvalds (exponent<(DBL_P-2) ? (Dallp2(dbl_valueB) << (exponent + (34-DBL_P))) : \ 210*1da177e4SLinus Torvalds FALSE)) 211*1da177e4SLinus Torvalds 212*1da177e4SLinus Torvalds 213*1da177e4SLinus Torvalds /* Int macros */ 214*1da177e4SLinus Torvalds 215*1da177e4SLinus Torvalds #define Int_from_sgl_mantissa(sgl_value,exponent) \ 216*1da177e4SLinus Torvalds Sall(sgl_value) = \ 217*1da177e4SLinus Torvalds (unsigned)(Sall(sgl_value) << SGL_EXP_LENGTH)>>(31 - exponent) 218*1da177e4SLinus Torvalds 219*1da177e4SLinus Torvalds #define Int_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent) \ 220*1da177e4SLinus Torvalds Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),22,Dallp1(dbl_valueA)); \ 221*1da177e4SLinus Torvalds if (exponent < 31) Dallp1(dbl_valueA) >>= 30 - exponent; \ 222*1da177e4SLinus Torvalds else Dallp1(dbl_valueA) <<= 1 223*1da177e4SLinus Torvalds 224*1da177e4SLinus Torvalds #define Int_negate(int_value) int_value = -int_value 225*1da177e4SLinus Torvalds 226*1da177e4SLinus Torvalds 227*1da177e4SLinus Torvalds /* Dint macros */ 228*1da177e4SLinus Torvalds 229*1da177e4SLinus Torvalds #define Dint_from_sgl_mantissa(sgl_value,exponent,dresultA,dresultB) \ 230*1da177e4SLinus Torvalds {Sall(sgl_value) <<= SGL_EXP_LENGTH; /* left-justify */ \ 231*1da177e4SLinus Torvalds if (exponent <= 31) { \ 232*1da177e4SLinus Torvalds Dintp1(dresultA) = 0; \ 233*1da177e4SLinus Torvalds Dintp2(dresultB) = (unsigned)Sall(sgl_value) >> (31 - exponent); \ 234*1da177e4SLinus Torvalds } \ 235*1da177e4SLinus Torvalds else { \ 236*1da177e4SLinus Torvalds Dintp1(dresultA) = Sall(sgl_value) >> (63 - exponent); \ 237*1da177e4SLinus Torvalds Dintp2(dresultB) = Sall(sgl_value) << (exponent - 31); \ 238*1da177e4SLinus Torvalds }} 239*1da177e4SLinus Torvalds 240*1da177e4SLinus Torvalds 241*1da177e4SLinus Torvalds #define Dint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB) \ 242*1da177e4SLinus Torvalds {if (exponent < 32) { \ 243*1da177e4SLinus Torvalds Dintp1(destA) = 0; \ 244*1da177e4SLinus Torvalds if (exponent <= 20) \ 245*1da177e4SLinus Torvalds Dintp2(destB) = Dallp1(dbl_valueA) >> 20-exponent; \ 246*1da177e4SLinus Torvalds else Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \ 247*1da177e4SLinus Torvalds 52-exponent,Dintp2(destB)); \ 248*1da177e4SLinus Torvalds } \ 249*1da177e4SLinus Torvalds else { \ 250*1da177e4SLinus Torvalds if (exponent <= 52) { \ 251*1da177e4SLinus Torvalds Dintp1(destA) = Dallp1(dbl_valueA) >> 52-exponent; \ 252*1da177e4SLinus Torvalds if (exponent == 52) Dintp2(destB) = Dallp2(dbl_valueB); \ 253*1da177e4SLinus Torvalds else Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \ 254*1da177e4SLinus Torvalds 52-exponent,Dintp2(destB)); \ 255*1da177e4SLinus Torvalds } \ 256*1da177e4SLinus Torvalds else { \ 257*1da177e4SLinus Torvalds Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \ 258*1da177e4SLinus Torvalds 84-exponent,Dintp1(destA)); \ 259*1da177e4SLinus Torvalds Dintp2(destB) = Dallp2(dbl_valueB) << exponent-52; \ 260*1da177e4SLinus Torvalds } \ 261*1da177e4SLinus Torvalds }} 262*1da177e4SLinus Torvalds 263*1da177e4SLinus Torvalds #define Dint_setzero(dresultA,dresultB) \ 264*1da177e4SLinus Torvalds Dintp1(dresultA) = 0; \ 265*1da177e4SLinus Torvalds Dintp2(dresultB) = 0 266*1da177e4SLinus Torvalds 267*1da177e4SLinus Torvalds #define Dint_setone_sign(dresultA,dresultB) \ 268*1da177e4SLinus Torvalds Dintp1(dresultA) = ~Dintp1(dresultA); \ 269*1da177e4SLinus Torvalds if ((Dintp2(dresultB) = -Dintp2(dresultB)) == 0) Dintp1(dresultA)++ 270*1da177e4SLinus Torvalds 271*1da177e4SLinus Torvalds #define Dint_set_minint(dresultA,dresultB) \ 272*1da177e4SLinus Torvalds Dintp1(dresultA) = (unsigned int)1<<31; \ 273*1da177e4SLinus Torvalds Dintp2(dresultB) = 0 274*1da177e4SLinus Torvalds 275*1da177e4SLinus Torvalds #define Dint_isone_lowp2(dresultB) (Dintp2(dresultB) & 01) 276*1da177e4SLinus Torvalds 277*1da177e4SLinus Torvalds #define Dint_increment(dresultA,dresultB) \ 278*1da177e4SLinus Torvalds if ((++Dintp2(dresultB))==0) Dintp1(dresultA)++ 279*1da177e4SLinus Torvalds 280*1da177e4SLinus Torvalds #define Dint_decrement(dresultA,dresultB) \ 281*1da177e4SLinus Torvalds if ((Dintp2(dresultB)--)==0) Dintp1(dresultA)-- 282*1da177e4SLinus Torvalds 283*1da177e4SLinus Torvalds #define Dint_negate(dresultA,dresultB) \ 284*1da177e4SLinus Torvalds Dintp1(dresultA) = ~Dintp1(dresultA); \ 285*1da177e4SLinus Torvalds if ((Dintp2(dresultB) = -Dintp2(dresultB))==0) Dintp1(dresultA)++ 286*1da177e4SLinus Torvalds 287*1da177e4SLinus Torvalds #define Dint_copyfromptr(src,destA,destB) \ 288*1da177e4SLinus Torvalds Dintp1(destA) = src->wd0; \ 289*1da177e4SLinus Torvalds Dintp2(destB) = src->wd1 290*1da177e4SLinus Torvalds #define Dint_copytoptr(srcA,srcB,dest) \ 291*1da177e4SLinus Torvalds dest->wd0 = Dintp1(srcA); \ 292*1da177e4SLinus Torvalds dest->wd1 = Dintp2(srcB) 293*1da177e4SLinus Torvalds 294*1da177e4SLinus Torvalds 295*1da177e4SLinus Torvalds /* other macros */ 296*1da177e4SLinus Torvalds 297*1da177e4SLinus Torvalds #define Find_ms_one_bit(value, position) \ 298*1da177e4SLinus Torvalds { \ 299*1da177e4SLinus Torvalds int var; \ 300*1da177e4SLinus Torvalds for (var=8; var >=1; var >>= 1) { \ 301*1da177e4SLinus Torvalds if (value >> 32 - position) \ 302*1da177e4SLinus Torvalds position -= var; \ 303*1da177e4SLinus Torvalds else position += var; \ 304*1da177e4SLinus Torvalds } \ 305*1da177e4SLinus Torvalds if ((value >> 32 - position) == 0) \ 306*1da177e4SLinus Torvalds position--; \ 307*1da177e4SLinus Torvalds else position -= 2; \ 308*1da177e4SLinus Torvalds } 309*1da177e4SLinus Torvalds 310*1da177e4SLinus Torvalds 311*1da177e4SLinus Torvalds /* 312*1da177e4SLinus Torvalds * Unsigned int macros 313*1da177e4SLinus Torvalds */ 314*1da177e4SLinus Torvalds #define Duint_copyfromptr(src,destA,destB) \ 315*1da177e4SLinus Torvalds Dint_copyfromptr(src,destA,destB) 316*1da177e4SLinus Torvalds #define Duint_copytoptr(srcA,srcB,dest) \ 317*1da177e4SLinus Torvalds Dint_copytoptr(srcA,srcB,dest) 318*1da177e4SLinus Torvalds 319*1da177e4SLinus Torvalds #define Suint_isinexact_to_sgl(int_value) \ 320*1da177e4SLinus Torvalds (int_value << 32 - SGL_EXP_LENGTH) 321*1da177e4SLinus Torvalds 322*1da177e4SLinus Torvalds #define Sgl_roundnearest_from_suint(suint_value,sgl_value) \ 323*1da177e4SLinus Torvalds if (suint_value & 1<<(SGL_EXP_LENGTH - 1)) /* round bit */ \ 324*1da177e4SLinus Torvalds if ((suint_value << 33 - SGL_EXP_LENGTH) || Slow(sgl_value)) \ 325*1da177e4SLinus Torvalds Sall(sgl_value)++ 326*1da177e4SLinus Torvalds 327*1da177e4SLinus Torvalds #define Duint_isinexact_to_sgl(duint_valueA,duint_valueB) \ 328*1da177e4SLinus Torvalds ((Duintp1(duint_valueA) << 32 - SGL_EXP_LENGTH) || Duintp2(duint_valueB)) 329*1da177e4SLinus Torvalds 330*1da177e4SLinus Torvalds #define Sgl_roundnearest_from_duint(duint_valueA,duint_valueB,sgl_value) \ 331*1da177e4SLinus Torvalds if (Duintp1(duint_valueA) & 1<<(SGL_EXP_LENGTH - 1)) \ 332*1da177e4SLinus Torvalds if ((Duintp1(duint_valueA) << 33 - SGL_EXP_LENGTH) || \ 333*1da177e4SLinus Torvalds Duintp2(duint_valueB) || Slow(sgl_value)) Sall(sgl_value)++ 334*1da177e4SLinus Torvalds 335*1da177e4SLinus Torvalds #define Duint_isinexact_to_dbl(duint_value) \ 336*1da177e4SLinus Torvalds (Duintp2(duint_value) << 32 - DBL_EXP_LENGTH) 337*1da177e4SLinus Torvalds 338*1da177e4SLinus Torvalds #define Dbl_roundnearest_from_duint(duint_opndB,dbl_opndA,dbl_opndB) \ 339*1da177e4SLinus Torvalds if (Duintp2(duint_opndB) & 1<<(DBL_EXP_LENGTH - 1)) \ 340*1da177e4SLinus Torvalds if ((Duintp2(duint_opndB) << 33 - DBL_EXP_LENGTH) || Dlowp2(dbl_opndB)) \ 341*1da177e4SLinus Torvalds if ((++Dallp2(dbl_opndB))==0) Dallp1(dbl_opndA)++ 342*1da177e4SLinus Torvalds 343*1da177e4SLinus Torvalds #define Suint_from_sgl_mantissa(src,exponent,result) \ 344*1da177e4SLinus Torvalds Sall(result) = (unsigned)(Sall(src) << SGL_EXP_LENGTH)>>(31 - exponent) 345*1da177e4SLinus Torvalds 346*1da177e4SLinus Torvalds #define Sgl_isinexact_to_unsigned(sgl_value,exponent) \ 347*1da177e4SLinus Torvalds Sgl_isinexact_to_fix(sgl_value,exponent) 348*1da177e4SLinus Torvalds 349*1da177e4SLinus Torvalds #define Duint_from_sgl_mantissa(sgl_value,exponent,dresultA,dresultB) \ 350*1da177e4SLinus Torvalds {Sall(sgl_value) <<= SGL_EXP_LENGTH; /* left-justify */ \ 351*1da177e4SLinus Torvalds if (exponent <= 31) { \ 352*1da177e4SLinus Torvalds Dintp1(dresultA) = 0; \ 353*1da177e4SLinus Torvalds Dintp2(dresultB) = (unsigned)Sall(sgl_value) >> (31 - exponent); \ 354*1da177e4SLinus Torvalds } \ 355*1da177e4SLinus Torvalds else { \ 356*1da177e4SLinus Torvalds Dintp1(dresultA) = Sall(sgl_value) >> (63 - exponent); \ 357*1da177e4SLinus Torvalds Dintp2(dresultB) = Sall(sgl_value) << (exponent - 31); \ 358*1da177e4SLinus Torvalds } \ 359*1da177e4SLinus Torvalds Sall(sgl_value) >>= SGL_EXP_LENGTH; /* return to original */ \ 360*1da177e4SLinus Torvalds } 361*1da177e4SLinus Torvalds 362*1da177e4SLinus Torvalds #define Duint_setzero(dresultA,dresultB) \ 363*1da177e4SLinus Torvalds Dint_setzero(dresultA,dresultB) 364*1da177e4SLinus Torvalds 365*1da177e4SLinus Torvalds #define Duint_increment(dresultA,dresultB) Dint_increment(dresultA,dresultB) 366*1da177e4SLinus Torvalds 367*1da177e4SLinus Torvalds #define Duint_isone_lowp2(dresultB) Dint_isone_lowp2(dresultB) 368*1da177e4SLinus Torvalds 369*1da177e4SLinus Torvalds #define Suint_from_dbl_mantissa(srcA,srcB,exponent,dest) \ 370*1da177e4SLinus Torvalds Shiftdouble(Dallp1(srcA),Dallp2(srcB),21,dest); \ 371*1da177e4SLinus Torvalds dest = (unsigned)dest >> 31 - exponent 372*1da177e4SLinus Torvalds 373*1da177e4SLinus Torvalds #define Dbl_isinexact_to_unsigned(dbl_valueA,dbl_valueB,exponent) \ 374*1da177e4SLinus Torvalds Dbl_isinexact_to_fix(dbl_valueA,dbl_valueB,exponent) 375*1da177e4SLinus Torvalds 376*1da177e4SLinus Torvalds #define Duint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB) \ 377*1da177e4SLinus Torvalds Dint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB) 378