📄 sgl_float.h
字号:
#define Sgl_addition(sgl_left,sgl_right,sgl_result) \ Sall(sgl_result) = Sall(sgl_left) + Sall(sgl_right)#define Sgl_xortointp1(left,right,result) \ result = Sall(left) XOR Sall(right);#define Sgl_xorfromintp1(left,right,result) \ Sall(result) = left XOR Sall(right)/* Need to Initialize */#define Sgl_makequietnan(dest) \ Sall(dest) = ((SGL_EMAX+SGL_BIAS)+1)<< (32-(1+SGL_EXP_LENGTH)) \ | (1<<(32-(1+SGL_EXP_LENGTH+2)))#define Sgl_makesignalingnan(dest) \ Sall(dest) = ((SGL_EMAX+SGL_BIAS)+1)<< (32-(1+SGL_EXP_LENGTH)) \ | (1<<(32-(1+SGL_EXP_LENGTH+1)))#define Sgl_normalize(sgl_opnd,exponent) \ while(Sgl_iszero_hiddenhigh7mantissa(sgl_opnd)) { \ Sgl_leftshiftby8(sgl_opnd); \ exponent -= 8; \ } \ if(Sgl_iszero_hiddenhigh3mantissa(sgl_opnd)) { \ Sgl_leftshiftby4(sgl_opnd); \ exponent -= 4; \ } \ while(Sgl_iszero_hidden(sgl_opnd)) { \ Sgl_leftshiftby1(sgl_opnd); \ exponent -= 1; \ }#define Sgl_setoverflow(sgl_opnd) \ /* set result to infinity or largest number */ \ switch (Rounding_mode()) { \ case ROUNDPLUS: \ if (Sgl_isone_sign(sgl_opnd)) { \ Sgl_setlargestnegative(sgl_opnd); \ } \ else { \ Sgl_setinfinitypositive(sgl_opnd); \ } \ break; \ case ROUNDMINUS: \ if (Sgl_iszero_sign(sgl_opnd)) { \ Sgl_setlargestpositive(sgl_opnd); \ } \ else { \ Sgl_setinfinitynegative(sgl_opnd); \ } \ break; \ case ROUNDNEAREST: \ Sgl_setinfinity_exponentmantissa(sgl_opnd); \ break; \ case ROUNDZERO: \ Sgl_setlargest_exponentmantissa(sgl_opnd); \ }#define Sgl_denormalize(opnd,exponent,guard,sticky,inexact) \ Sgl_clear_signexponent_set_hidden(opnd); \ if (exponent >= (1 - SGL_P)) { \ guard = (Sall(opnd) >> -exponent) & 1; \ if (exponent < 0) sticky |= Sall(opnd) << (32+exponent); \ inexact = guard | sticky; \ Sall(opnd) >>= (1-exponent); \ } \ else { \ guard = 0; \ sticky |= Sall(opnd); \ inexact = sticky; \ Sgl_setzero(opnd); \ }/* * The fused multiply add instructions requires a single extended format, * with 48 bits of mantissa. */#define SGLEXT_THRESHOLD 48#define Sglext_setzero(valA,valB) \ Sextallp1(valA) = 0; Sextallp2(valB) = 0#define Sglext_isnotzero_mantissap2(valB) (Sextallp2(valB)!=0)#define Sglext_isone_lowp1(val) (Sextlowp1(val)!=0)#define Sglext_isone_highp2(val) (Sexthighp2(val)!=0)#define Sglext_isnotzero_low31p2(val) (Sextlow31p2(val)!=0)#define Sglext_iszero(valA,valB) (Sextallp1(valA)==0 && Sextallp2(valB)==0)#define Sgl_copytoptr(src,destptr) *destptr = src#define Sgl_copyfromptr(srcptr,dest) dest = *srcptr#define Sglext_copy(srca,srcb,desta,destb) \ Sextallp1(desta) = Sextallp1(srca); \ Sextallp2(destb) = Sextallp2(srcb)#define Sgl_copyto_sglext(src1,dest1,dest2) \ Sextallp1(dest1) = Sall(src1); Sextallp2(dest2) = 0#define Sglext_swap_lower(leftp2,rightp2) \ Sextallp2(leftp2) = Sextallp2(leftp2) XOR Sextallp2(rightp2); \ Sextallp2(rightp2) = Sextallp2(leftp2) XOR Sextallp2(rightp2); \ Sextallp2(leftp2) = Sextallp2(leftp2) XOR Sextallp2(rightp2)#define Sglext_setone_lowmantissap2(value) Deposit_dlowp2(value,1)/* The high bit is always zero so arithmetic or logical shifts will work. */#define Sglext_right_align(srcdstA,srcdstB,shift) \ {int shiftamt, sticky; \ shiftamt = shift % 32; \ sticky = 0; \ switch (shift/32) { \ case 0: if (shiftamt > 0) { \ sticky = Sextallp2(srcdstB) << 32 - (shiftamt); \ Variable_shift_double(Sextallp1(srcdstA), \ Sextallp2(srcdstB),shiftamt,Sextallp2(srcdstB)); \ Sextallp1(srcdstA) >>= shiftamt; \ } \ break; \ case 1: if (shiftamt > 0) { \ sticky = (Sextallp1(srcdstA) << 32 - (shiftamt)) | \ Sextallp2(srcdstB); \ } \ else { \ sticky = Sextallp2(srcdstB); \ } \ Sextallp2(srcdstB) = Sextallp1(srcdstA) >> shiftamt; \ Sextallp1(srcdstA) = 0; \ break; \ } \ if (sticky) Sglext_setone_lowmantissap2(srcdstB); \ }/* The left argument is never smaller than the right argument */#define Sglext_subtract(lefta,leftb,righta,rightb,resulta,resultb) \ if( Sextallp2(rightb) > Sextallp2(leftb) ) Sextallp1(lefta)--; \ Sextallp2(resultb) = Sextallp2(leftb) - Sextallp2(rightb); \ Sextallp1(resulta) = Sextallp1(lefta) - Sextallp1(righta)#define Sglext_addition(lefta,leftb,righta,rightb,resulta,resultb) \ /* If the sum of the low words is less than either source, then \ * an overflow into the next word occurred. */ \ if ((Sextallp2(resultb) = Sextallp2(leftb)+Sextallp2(rightb)) < \ Sextallp2(rightb)) \ Sextallp1(resulta) = Sextallp1(lefta)+Sextallp1(righta)+1; \ else Sextallp1(resulta) = Sextallp1(lefta)+Sextallp1(righta)#define Sglext_arithrightshiftby1(srcdstA,srcdstB) \ Shiftdouble(Sextallp1(srcdstA),Sextallp2(srcdstB),1,Sextallp2(srcdstB)); \ Sextallp1(srcdstA) = (int)Sextallp1(srcdstA) >> 1 #define Sglext_leftshiftby8(valA,valB) \ Shiftdouble(Sextallp1(valA),Sextallp2(valB),24,Sextallp1(valA)); \ Sextallp2(valB) <<= 8#define Sglext_leftshiftby4(valA,valB) \ Shiftdouble(Sextallp1(valA),Sextallp2(valB),28,Sextallp1(valA)); \ Sextallp2(valB) <<= 4#define Sglext_leftshiftby3(valA,valB) \ Shiftdouble(Sextallp1(valA),Sextallp2(valB),29,Sextallp1(valA)); \ Sextallp2(valB) <<= 3#define Sglext_leftshiftby2(valA,valB) \ Shiftdouble(Sextallp1(valA),Sextallp2(valB),30,Sextallp1(valA)); \ Sextallp2(valB) <<= 2#define Sglext_leftshiftby1(valA,valB) \ Shiftdouble(Sextallp1(valA),Sextallp2(valB),31,Sextallp1(valA)); \ Sextallp2(valB) <<= 1#define Sglext_rightshiftby4(valueA,valueB) \ Shiftdouble(Sextallp1(valueA),Sextallp2(valueB),4,Sextallp2(valueB)); \ Sextallp1(valueA) >>= 4#define Sglext_rightshiftby3(valueA,valueB) \ Shiftdouble(Sextallp1(valueA),Sextallp2(valueB),3,Sextallp2(valueB)); \ Sextallp1(valueA) >>= 3#define Sglext_rightshiftby1(valueA,valueB) \ Shiftdouble(Sextallp1(valueA),Sextallp2(valueB),1,Sextallp2(valueB)); \ Sextallp1(valueA) >>= 1#define Sglext_xortointp1(left,right,result) Sgl_xortointp1(left,right,result)#define Sglext_xorfromintp1(left,right,result) \ Sgl_xorfromintp1(left,right,result)#define Sglext_copytoint_exponentmantissa(src,dest) \ Sgl_copytoint_exponentmantissa(src,dest)#define Sglext_ismagnitudeless(signlessleft,signlessright) \ Sgl_ismagnitudeless(signlessleft,signlessright)#define Sglext_set_sign(dbl_value,sign) Sgl_set_sign(dbl_value,sign) #define Sglext_clear_signexponent_set_hidden(srcdst) \ Sgl_clear_signexponent_set_hidden(srcdst) #define Sglext_clear_signexponent(srcdst) Sgl_clear_signexponent(srcdst) #define Sglext_clear_sign(srcdst) Sgl_clear_sign(srcdst) #define Sglext_isone_hidden(dbl_value) Sgl_isone_hidden(dbl_value) #define Sglext_denormalize(opndp1,opndp2,exponent,is_tiny) \ {int sticky; \ is_tiny = TRUE; \ if (exponent == 0 && Sextallp2(opndp2)) { \ switch (Rounding_mode()) { \ case ROUNDPLUS: \ if (Sgl_iszero_sign(opndp1)) \ if (Sgl_isone_hiddenoverflow(opndp1 + 1)) \ is_tiny = FALSE; \ break; \ case ROUNDMINUS: \ if (Sgl_isone_sign(opndp1)) { \ if (Sgl_isone_hiddenoverflow(opndp1 + 1)) \ is_tiny = FALSE; \ } \ break; \ case ROUNDNEAREST: \ if (Sglext_isone_highp2(opndp2) && \ (Sglext_isone_lowp1(opndp1) || \ Sglext_isnotzero_low31p2(opndp2))) \ if (Sgl_isone_hiddenoverflow(opndp1 + 1)) \ is_tiny = FALSE; \ break; \ } \ } \ Sglext_clear_signexponent_set_hidden(opndp1); \ if (exponent >= (1-DBL_P)) { \ if (exponent >= -31) { \ if (exponent > -31) { \ sticky = Sextallp2(opndp2) << 31+exponent; \ Variable_shift_double(opndp1,opndp2,1-exponent,opndp2); \ Sextallp1(opndp1) >>= 1-exponent; \ } \ else { \ sticky = Sextallp2(opndp2); \ Sextallp2(opndp2) = Sextallp1(opndp1); \ Sextallp1(opndp1) = 0; \ } \ } \ else { \ sticky = (Sextallp1(opndp1) << 31+exponent) | \ Sextallp2(opndp2); \ Sextallp2(opndp2) = Sextallp1(opndp1) >> -31-exponent; \ Sextallp1(opndp1) = 0; \ } \ } \ else { \ sticky = Sextallp1(opndp1) | Sextallp2(opndp2); \ Sglext_setzero(opndp1,opndp2); \ } \ if (sticky) Sglext_setone_lowmantissap2(opndp2); \ exponent = 0; \ }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -