📄 dbl_float.h
字号:
/* * Linux/PA-RISC Project (http://www.parisc-linux.org/) * * Floating-point emulation code * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#ifdef __NO_PA_HDRS PA header file -- do not include this header file for non-PA builds.#endif/* 32-bit word grabing functions */#define Dbl_firstword(value) Dallp1(value)#define Dbl_secondword(value) Dallp2(value)#define Dbl_thirdword(value) dummy_location#define Dbl_fourthword(value) dummy_location#define Dbl_sign(object) Dsign(object)#define Dbl_exponent(object) Dexponent(object)#define Dbl_signexponent(object) Dsignexponent(object)#define Dbl_mantissap1(object) Dmantissap1(object)#define Dbl_mantissap2(object) Dmantissap2(object)#define Dbl_exponentmantissap1(object) Dexponentmantissap1(object)#define Dbl_allp1(object) Dallp1(object)#define Dbl_allp2(object) Dallp2(object)/* dbl_and_signs ands the sign bits of each argument and puts the result * into the first argument. dbl_or_signs ors those same sign bits */#define Dbl_and_signs( src1dst, src2) \ Dallp1(src1dst) = (Dallp1(src2)|~((unsigned int)1<<31)) & Dallp1(src1dst)#define Dbl_or_signs( src1dst, src2) \ Dallp1(src1dst) = (Dallp1(src2)&((unsigned int)1<<31)) | Dallp1(src1dst)/* The hidden bit is always the low bit of the exponent */#define Dbl_clear_exponent_set_hidden(srcdst) Deposit_dexponent(srcdst,1)#define Dbl_clear_signexponent_set_hidden(srcdst) \ Deposit_dsignexponent(srcdst,1)#define Dbl_clear_sign(srcdst) Dallp1(srcdst) &= ~((unsigned int)1<<31)#define Dbl_clear_signexponent(srcdst) \ Dallp1(srcdst) &= Dmantissap1((unsigned int)-1)/* Exponent field for doubles has already been cleared and may be * included in the shift. Here we need to generate two double width * variable shifts. The insignificant bits can be ignored. * MTSAR f(varamount) * VSHD srcdst.high,srcdst.low => srcdst.low * VSHD 0,srcdst.high => srcdst.high * This is very difficult to model with C expressions since the shift amount * could exceed 32. *//* varamount must be less than 64 */#define Dbl_rightshift(srcdstA, srcdstB, varamount) \ {if((varamount) >= 32) { \ Dallp2(srcdstB) = Dallp1(srcdstA) >> (varamount-32); \ Dallp1(srcdstA)=0; \ } \ else if(varamount > 0) { \ Variable_shift_double(Dallp1(srcdstA), Dallp2(srcdstB), \ (varamount), Dallp2(srcdstB)); \ Dallp1(srcdstA) >>= varamount; \ } }/* varamount must be less than 64 */#define Dbl_rightshift_exponentmantissa(srcdstA, srcdstB, varamount) \ {if((varamount) >= 32) { \ Dallp2(srcdstB) = Dexponentmantissap1(srcdstA) >> (varamount-32); \ Dallp1(srcdstA) &= ((unsigned int)1<<31); /* clear expmant field */ \ } \ else if(varamount > 0) { \ Variable_shift_double(Dexponentmantissap1(srcdstA), Dallp2(srcdstB), \ (varamount), Dallp2(srcdstB)); \ Deposit_dexponentmantissap1(srcdstA, \ (Dexponentmantissap1(srcdstA)>>varamount)); \ } }/* varamount must be less than 64 */#define Dbl_leftshift(srcdstA, srcdstB, varamount) \ {if((varamount) >= 32) { \ Dallp1(srcdstA) = Dallp2(srcdstB) << (varamount-32); \ Dallp2(srcdstB)=0; \ } \ else { \ if ((varamount) > 0) { \ Dallp1(srcdstA) = (Dallp1(srcdstA) << (varamount)) | \ (Dallp2(srcdstB) >> (32-(varamount))); \ Dallp2(srcdstB) <<= varamount; \ } \ } }#define Dbl_leftshiftby1_withextent(lefta,leftb,right,resulta,resultb) \ Shiftdouble(Dallp1(lefta), Dallp2(leftb), 31, Dallp1(resulta)); \ Shiftdouble(Dallp2(leftb), Extall(right), 31, Dallp2(resultb)) #define Dbl_rightshiftby1_withextent(leftb,right,dst) \ Extall(dst) = (Dallp2(leftb) << 31) | ((unsigned int)Extall(right) >> 1) | \ Extlow(right)#define Dbl_arithrightshiftby1(srcdstA,srcdstB) \ Shiftdouble(Dallp1(srcdstA),Dallp2(srcdstB),1,Dallp2(srcdstB));\ Dallp1(srcdstA) = (int)Dallp1(srcdstA) >> 1 /* Sign extend the sign bit with an integer destination */#define Dbl_signextendedsign(value) Dsignedsign(value)#define Dbl_isone_hidden(dbl_value) (Is_dhidden(dbl_value)!=0)/* Singles and doubles may include the sign and exponent fields. The * hidden bit and the hidden overflow must be included. */#define Dbl_increment(dbl_valueA,dbl_valueB) \ if( (Dallp2(dbl_valueB) += 1) == 0 ) Dallp1(dbl_valueA) += 1#define Dbl_increment_mantissa(dbl_valueA,dbl_valueB) \ if( (Dmantissap2(dbl_valueB) += 1) == 0 ) \ Deposit_dmantissap1(dbl_valueA,dbl_valueA+1)#define Dbl_decrement(dbl_valueA,dbl_valueB) \ if( Dallp2(dbl_valueB) == 0 ) Dallp1(dbl_valueA) -= 1; \ Dallp2(dbl_valueB) -= 1#define Dbl_isone_sign(dbl_value) (Is_dsign(dbl_value)!=0)#define Dbl_isone_hiddenoverflow(dbl_value) (Is_dhiddenoverflow(dbl_value)!=0)#define Dbl_isone_lowmantissap1(dbl_valueA) (Is_dlowp1(dbl_valueA)!=0)#define Dbl_isone_lowmantissap2(dbl_valueB) (Is_dlowp2(dbl_valueB)!=0)#define Dbl_isone_signaling(dbl_value) (Is_dsignaling(dbl_value)!=0)#define Dbl_is_signalingnan(dbl_value) (Dsignalingnan(dbl_value)==0xfff)#define Dbl_isnotzero(dbl_valueA,dbl_valueB) \ (Dallp1(dbl_valueA) || Dallp2(dbl_valueB))#define Dbl_isnotzero_hiddenhigh7mantissa(dbl_value) \ (Dhiddenhigh7mantissa(dbl_value)!=0)#define Dbl_isnotzero_exponent(dbl_value) (Dexponent(dbl_value)!=0)#define Dbl_isnotzero_mantissa(dbl_valueA,dbl_valueB) \ (Dmantissap1(dbl_valueA) || Dmantissap2(dbl_valueB))#define Dbl_isnotzero_mantissap1(dbl_valueA) (Dmantissap1(dbl_valueA)!=0)#define Dbl_isnotzero_mantissap2(dbl_valueB) (Dmantissap2(dbl_valueB)!=0)#define Dbl_isnotzero_exponentmantissa(dbl_valueA,dbl_valueB) \ (Dexponentmantissap1(dbl_valueA) || Dmantissap2(dbl_valueB))#define Dbl_isnotzero_low4p2(dbl_value) (Dlow4p2(dbl_value)!=0)#define Dbl_iszero(dbl_valueA,dbl_valueB) (Dallp1(dbl_valueA)==0 && \ Dallp2(dbl_valueB)==0)#define Dbl_iszero_allp1(dbl_value) (Dallp1(dbl_value)==0)#define Dbl_iszero_allp2(dbl_value) (Dallp2(dbl_value)==0)#define Dbl_iszero_hidden(dbl_value) (Is_dhidden(dbl_value)==0)#define Dbl_iszero_hiddenoverflow(dbl_value) (Is_dhiddenoverflow(dbl_value)==0)#define Dbl_iszero_hiddenhigh3mantissa(dbl_value) \ (Dhiddenhigh3mantissa(dbl_value)==0)#define Dbl_iszero_hiddenhigh7mantissa(dbl_value) \ (Dhiddenhigh7mantissa(dbl_value)==0)#define Dbl_iszero_sign(dbl_value) (Is_dsign(dbl_value)==0)#define Dbl_iszero_exponent(dbl_value) (Dexponent(dbl_value)==0)#define Dbl_iszero_mantissa(dbl_valueA,dbl_valueB) \ (Dmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0)#define Dbl_iszero_exponentmantissa(dbl_valueA,dbl_valueB) \ (Dexponentmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0)#define Dbl_isinfinity_exponent(dbl_value) \ (Dexponent(dbl_value)==DBL_INFINITY_EXPONENT)#define Dbl_isnotinfinity_exponent(dbl_value) \ (Dexponent(dbl_value)!=DBL_INFINITY_EXPONENT)#define Dbl_isinfinity(dbl_valueA,dbl_valueB) \ (Dexponent(dbl_valueA)==DBL_INFINITY_EXPONENT && \ Dmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0)#define Dbl_isnan(dbl_valueA,dbl_valueB) \ (Dexponent(dbl_valueA)==DBL_INFINITY_EXPONENT && \ (Dmantissap1(dbl_valueA)!=0 || Dmantissap2(dbl_valueB)!=0))#define Dbl_isnotnan(dbl_valueA,dbl_valueB) \ (Dexponent(dbl_valueA)!=DBL_INFINITY_EXPONENT || \ (Dmantissap1(dbl_valueA)==0 && Dmantissap2(dbl_valueB)==0))#define Dbl_islessthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \ (Dallp1(dbl_op1a) < Dallp1(dbl_op2a) || \ (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \ Dallp2(dbl_op1b) < Dallp2(dbl_op2b)))#define Dbl_isgreaterthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \ (Dallp1(dbl_op1a) > Dallp1(dbl_op2a) || \ (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \ Dallp2(dbl_op1b) > Dallp2(dbl_op2b)))#define Dbl_isnotlessthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \ (Dallp1(dbl_op1a) > Dallp1(dbl_op2a) || \ (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \ Dallp2(dbl_op1b) >= Dallp2(dbl_op2b)))#define Dbl_isnotgreaterthan(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \ (Dallp1(dbl_op1a) < Dallp1(dbl_op2a) || \ (Dallp1(dbl_op1a) == Dallp1(dbl_op2a) && \ Dallp2(dbl_op1b) <= Dallp2(dbl_op2b)))#define Dbl_isequal(dbl_op1a,dbl_op1b,dbl_op2a,dbl_op2b) \ ((Dallp1(dbl_op1a) == Dallp1(dbl_op2a)) && \ (Dallp2(dbl_op1b) == Dallp2(dbl_op2b)))#define Dbl_leftshiftby8(dbl_valueA,dbl_valueB) \ Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),24,Dallp1(dbl_valueA)); \ Dallp2(dbl_valueB) <<= 8#define Dbl_leftshiftby7(dbl_valueA,dbl_valueB) \ Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),25,Dallp1(dbl_valueA)); \ Dallp2(dbl_valueB) <<= 7#define Dbl_leftshiftby4(dbl_valueA,dbl_valueB) \ Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),28,Dallp1(dbl_valueA)); \ Dallp2(dbl_valueB) <<= 4#define Dbl_leftshiftby3(dbl_valueA,dbl_valueB) \ Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),29,Dallp1(dbl_valueA)); \ Dallp2(dbl_valueB) <<= 3#define Dbl_leftshiftby2(dbl_valueA,dbl_valueB) \ Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),30,Dallp1(dbl_valueA)); \ Dallp2(dbl_valueB) <<= 2#define Dbl_leftshiftby1(dbl_valueA,dbl_valueB) \ Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),31,Dallp1(dbl_valueA)); \ Dallp2(dbl_valueB) <<= 1#define Dbl_rightshiftby8(dbl_valueA,dbl_valueB) \ Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),8,Dallp2(dbl_valueB)); \ Dallp1(dbl_valueA) >>= 8#define Dbl_rightshiftby4(dbl_valueA,dbl_valueB) \ Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),4,Dallp2(dbl_valueB)); \ Dallp1(dbl_valueA) >>= 4#define Dbl_rightshiftby2(dbl_valueA,dbl_valueB) \ Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),2,Dallp2(dbl_valueB)); \ Dallp1(dbl_valueA) >>= 2#define Dbl_rightshiftby1(dbl_valueA,dbl_valueB) \ Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),1,Dallp2(dbl_valueB)); \ Dallp1(dbl_valueA) >>= 1 /* This magnitude comparison uses the signless first words and * the regular part2 words. The comparison is graphically: * * 1st greater? ------------- * | * 1st less?-----------------+--------- * | | * 2nd greater or equal----->| | * False True */#define Dbl_ismagnitudeless(leftB,rightB,signlessleft,signlessright) \ ((signlessleft <= signlessright) && \ ( (signlessleft < signlessright) || (Dallp2(leftB)<Dallp2(rightB)) )) #define Dbl_copytoint_exponentmantissap1(src,dest) \ dest = Dexponentmantissap1(src)/* A quiet NaN has the high mantissa bit clear and at least on other (in this * case the adjacent bit) bit set. */#define Dbl_set_quiet(dbl_value) Deposit_dhigh2mantissa(dbl_value,1)#define Dbl_set_exponent(dbl_value, exp) Deposit_dexponent(dbl_value,exp)#define Dbl_set_mantissa(desta,destb,valuea,valueb) \ Deposit_dmantissap1(desta,valuea); \ Dmantissap2(destb) = Dmantissap2(valueb)#define Dbl_set_mantissap1(desta,valuea) \ Deposit_dmantissap1(desta,valuea)#define Dbl_set_mantissap2(destb,valueb) \ Dmantissap2(destb) = Dmantissap2(valueb)#define Dbl_set_exponentmantissa(desta,destb,valuea,valueb) \ Deposit_dexponentmantissap1(desta,valuea); \ Dmantissap2(destb) = Dmantissap2(valueb)#define Dbl_set_exponentmantissap1(dest,value) \ Deposit_dexponentmantissap1(dest,value)#define Dbl_copyfromptr(src,desta,destb) \ Dallp1(desta) = src->wd0; \ Dallp2(destb) = src->wd1 #define Dbl_copytoptr(srca,srcb,dest) \ dest->wd0 = Dallp1(srca); \ dest->wd1 = Dallp2(srcb)/* An infinity is represented with the max exponent and a zero mantissa */#define Dbl_setinfinity_exponent(dbl_value) \ Deposit_dexponent(dbl_value,DBL_INFINITY_EXPONENT)#define Dbl_setinfinity_exponentmantissa(dbl_valueA,dbl_valueB) \ Deposit_dexponentmantissap1(dbl_valueA, \ (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH)))); \ Dmantissap2(dbl_valueB) = 0#define Dbl_setinfinitypositive(dbl_valueA,dbl_valueB) \ Dallp1(dbl_valueA) \ = (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH))); \ Dmantissap2(dbl_valueB) = 0#define Dbl_setinfinitynegative(dbl_valueA,dbl_valueB) \ Dallp1(dbl_valueA) = ((unsigned int)1<<31) | \ (DBL_INFINITY_EXPONENT << (32-(1+DBL_EXP_LENGTH))); \ Dmantissap2(dbl_valueB) = 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -