11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Linux/PA-RISC Project (http://www.parisc-linux.org/) 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Floating-point emulation code 51da177e4SLinus Torvalds * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org> 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 81da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 91da177e4SLinus Torvalds * the Free Software Foundation; either version 2, or (at your option) 101da177e4SLinus Torvalds * any later version. 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 131da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 141da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 151da177e4SLinus Torvalds * GNU General Public License for more details. 161da177e4SLinus Torvalds * 171da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 181da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 191da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 201da177e4SLinus Torvalds */ 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds #ifdef __NO_PA_HDRS 231da177e4SLinus Torvalds PA header file -- do not include this header file for non-PA builds. 241da177e4SLinus Torvalds #endif 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds /* 271da177e4SLinus Torvalds * Some more constants 281da177e4SLinus Torvalds */ 291da177e4SLinus Torvalds #define SGL_FX_MAX_EXP 30 301da177e4SLinus Torvalds #define DBL_FX_MAX_EXP 62 311da177e4SLinus Torvalds #define QUAD_FX_MAX_EXP 126 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds #define Dintp1(object) (object) 341da177e4SLinus Torvalds #define Dintp2(object) (object) 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds #define Duintp1(object) (object) 371da177e4SLinus Torvalds #define Duintp2(object) (object) 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds #define Qintp0(object) (object) 401da177e4SLinus Torvalds #define Qintp1(object) (object) 411da177e4SLinus Torvalds #define Qintp2(object) (object) 421da177e4SLinus Torvalds #define Qintp3(object) (object) 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds /* 461da177e4SLinus Torvalds * These macros will be used specifically by the convert instructions. 471da177e4SLinus Torvalds * 481da177e4SLinus Torvalds * 491da177e4SLinus Torvalds * Single format macros 501da177e4SLinus Torvalds */ 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds #define Sgl_to_dbl_exponent(src_exponent,dest) \ 531da177e4SLinus Torvalds Deposit_dexponent(dest,src_exponent+(DBL_BIAS-SGL_BIAS)) 541da177e4SLinus Torvalds 551da177e4SLinus Torvalds #define Sgl_to_dbl_mantissa(src_mantissa,destA,destB) \ 561da177e4SLinus Torvalds Deposit_dmantissap1(destA,src_mantissa>>3); \ 571da177e4SLinus Torvalds Dmantissap2(destB) = src_mantissa << 29 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds #define Sgl_isinexact_to_fix(sgl_value,exponent) \ 601da177e4SLinus Torvalds ((exponent < (SGL_P - 1)) ? \ 611da177e4SLinus Torvalds (Sall(sgl_value) << (SGL_EXP_LENGTH + 1 + exponent)) : FALSE) 621da177e4SLinus Torvalds 63*6b98d913SHelge Deller #define Int_isinexact_to_sgl(int_value) ((int_value << 33 - SGL_EXP_LENGTH) != 0) 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds #define Sgl_roundnearest_from_int(int_value,sgl_value) \ 661da177e4SLinus Torvalds if (int_value & 1<<(SGL_EXP_LENGTH - 2)) /* round bit */ \ 67*6b98d913SHelge Deller if (((int_value << 34 - SGL_EXP_LENGTH) != 0) || Slow(sgl_value)) \ 681da177e4SLinus Torvalds Sall(sgl_value)++ 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds #define Dint_isinexact_to_sgl(dint_valueA,dint_valueB) \ 71*6b98d913SHelge Deller (((Dintp1(dint_valueA) << 33 - SGL_EXP_LENGTH) != 0) || Dintp2(dint_valueB)) 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds #define Sgl_roundnearest_from_dint(dint_valueA,dint_valueB,sgl_value) \ 741da177e4SLinus Torvalds if (Dintp1(dint_valueA) & 1<<(SGL_EXP_LENGTH - 2)) \ 75*6b98d913SHelge Deller if (((Dintp1(dint_valueA) << 34 - SGL_EXP_LENGTH) != 0) || \ 761da177e4SLinus Torvalds Dintp2(dint_valueB) || Slow(sgl_value)) Sall(sgl_value)++ 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds #define Dint_isinexact_to_dbl(dint_value) \ 791da177e4SLinus Torvalds (Dintp2(dint_value) << 33 - DBL_EXP_LENGTH) 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds #define Dbl_roundnearest_from_dint(dint_opndB,dbl_opndA,dbl_opndB) \ 821da177e4SLinus Torvalds if (Dintp2(dint_opndB) & 1<<(DBL_EXP_LENGTH - 2)) \ 831da177e4SLinus Torvalds if ((Dintp2(dint_opndB) << 34 - DBL_EXP_LENGTH) || Dlowp2(dbl_opndB)) \ 841da177e4SLinus Torvalds if ((++Dallp2(dbl_opndB))==0) Dallp1(dbl_opndA)++ 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds #define Sgl_isone_roundbit(sgl_value,exponent) \ 871da177e4SLinus Torvalds ((Sall(sgl_value) << (SGL_EXP_LENGTH + 1 + exponent)) >> 31) 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds #define Sgl_isone_stickybit(sgl_value,exponent) \ 901da177e4SLinus Torvalds (exponent < (SGL_P - 2) ? \ 911da177e4SLinus Torvalds Sall(sgl_value) << (SGL_EXP_LENGTH + 2 + exponent) : FALSE) 921da177e4SLinus Torvalds 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds /* 951da177e4SLinus Torvalds * Double format macros 961da177e4SLinus Torvalds */ 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds #define Dbl_to_sgl_exponent(src_exponent,dest) \ 991da177e4SLinus Torvalds dest = src_exponent + (SGL_BIAS - DBL_BIAS) 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds #define Dbl_to_sgl_mantissa(srcA,srcB,dest,inexact,guard,sticky,odd) \ 1021da177e4SLinus Torvalds Shiftdouble(Dmantissap1(srcA),Dmantissap2(srcB),29,dest); \ 1031da177e4SLinus Torvalds guard = Dbit3p2(srcB); \ 1041da177e4SLinus Torvalds sticky = Dallp2(srcB)<<4; \ 1051da177e4SLinus Torvalds inexact = guard | sticky; \ 1061da177e4SLinus Torvalds odd = Dbit2p2(srcB) 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds #define Dbl_to_sgl_denormalized(srcA,srcB,exp,dest,inexact,guard,sticky,odd,tiny) \ 1091da177e4SLinus Torvalds Deposit_dexponent(srcA,1); \ 1101da177e4SLinus Torvalds tiny = TRUE; \ 1111da177e4SLinus Torvalds if (exp >= -2) { \ 1121da177e4SLinus Torvalds if (exp == 0) { \ 1131da177e4SLinus Torvalds inexact = Dallp2(srcB) << 3; \ 1141da177e4SLinus Torvalds guard = inexact >> 31; \ 1151da177e4SLinus Torvalds sticky = inexact << 1; \ 1161da177e4SLinus Torvalds Shiftdouble(Dmantissap1(srcA),Dmantissap2(srcB),29,dest); \ 1171da177e4SLinus Torvalds odd = dest << 31; \ 1181da177e4SLinus Torvalds if (inexact) { \ 1191da177e4SLinus Torvalds switch(Rounding_mode()) { \ 1201da177e4SLinus Torvalds case ROUNDPLUS: \ 1211da177e4SLinus Torvalds if (Dbl_iszero_sign(srcA)) { \ 1221da177e4SLinus Torvalds dest++; \ 1231da177e4SLinus Torvalds if (Sgl_isone_hidden(dest)) \ 1241da177e4SLinus Torvalds tiny = FALSE; \ 1251da177e4SLinus Torvalds dest--; \ 1261da177e4SLinus Torvalds } \ 1271da177e4SLinus Torvalds break; \ 1281da177e4SLinus Torvalds case ROUNDMINUS: \ 1291da177e4SLinus Torvalds if (Dbl_isone_sign(srcA)) { \ 1301da177e4SLinus Torvalds dest++; \ 1311da177e4SLinus Torvalds if (Sgl_isone_hidden(dest)) \ 1321da177e4SLinus Torvalds tiny = FALSE; \ 1331da177e4SLinus Torvalds dest--; \ 1341da177e4SLinus Torvalds } \ 1351da177e4SLinus Torvalds break; \ 1361da177e4SLinus Torvalds case ROUNDNEAREST: \ 1371da177e4SLinus Torvalds if (guard && (sticky || odd)) { \ 1381da177e4SLinus Torvalds dest++; \ 1391da177e4SLinus Torvalds if (Sgl_isone_hidden(dest)) \ 1401da177e4SLinus Torvalds tiny = FALSE; \ 1411da177e4SLinus Torvalds dest--; \ 1421da177e4SLinus Torvalds } \ 1431da177e4SLinus Torvalds break; \ 1441da177e4SLinus Torvalds } \ 1451da177e4SLinus Torvalds } \ 1461da177e4SLinus Torvalds /* shift right by one to get correct result */ \ 1471da177e4SLinus Torvalds guard = odd; \ 1481da177e4SLinus Torvalds sticky = inexact; \ 1491da177e4SLinus Torvalds inexact |= guard; \ 1501da177e4SLinus Torvalds dest >>= 1; \ 1511da177e4SLinus Torvalds Deposit_dsign(srcA,0); \ 1521da177e4SLinus Torvalds Shiftdouble(Dallp1(srcA),Dallp2(srcB),30,dest); \ 1531da177e4SLinus Torvalds odd = dest << 31; \ 1541da177e4SLinus Torvalds } \ 1551da177e4SLinus Torvalds else { \ 1561da177e4SLinus Torvalds inexact = Dallp2(srcB) << (2 + exp); \ 1571da177e4SLinus Torvalds guard = inexact >> 31; \ 1581da177e4SLinus Torvalds sticky = inexact << 1; \ 1591da177e4SLinus Torvalds Deposit_dsign(srcA,0); \ 1601da177e4SLinus Torvalds if (exp == -2) dest = Dallp1(srcA); \ 1611da177e4SLinus Torvalds else Variable_shift_double(Dallp1(srcA),Dallp2(srcB),30-exp,dest); \ 1621da177e4SLinus Torvalds odd = dest << 31; \ 1631da177e4SLinus Torvalds } \ 1641da177e4SLinus Torvalds } \ 1651da177e4SLinus Torvalds else { \ 1661da177e4SLinus Torvalds Deposit_dsign(srcA,0); \ 1671da177e4SLinus Torvalds if (exp > (1 - SGL_P)) { \ 1681da177e4SLinus Torvalds dest = Dallp1(srcA) >> (- 2 - exp); \ 1691da177e4SLinus Torvalds inexact = Dallp1(srcA) << (34 + exp); \ 1701da177e4SLinus Torvalds guard = inexact >> 31; \ 1711da177e4SLinus Torvalds sticky = (inexact << 1) | Dallp2(srcB); \ 1721da177e4SLinus Torvalds inexact |= Dallp2(srcB); \ 1731da177e4SLinus Torvalds odd = dest << 31; \ 1741da177e4SLinus Torvalds } \ 1751da177e4SLinus Torvalds else { \ 1761da177e4SLinus Torvalds dest = 0; \ 1771da177e4SLinus Torvalds inexact = Dallp1(srcA) | Dallp2(srcB); \ 1781da177e4SLinus Torvalds if (exp == (1 - SGL_P)) { \ 1791da177e4SLinus Torvalds guard = Dhidden(srcA); \ 1801da177e4SLinus Torvalds sticky = Dmantissap1(srcA) | Dallp2(srcB); \ 1811da177e4SLinus Torvalds } \ 1821da177e4SLinus Torvalds else { \ 1831da177e4SLinus Torvalds guard = 0; \ 1841da177e4SLinus Torvalds sticky = inexact; \ 1851da177e4SLinus Torvalds } \ 1861da177e4SLinus Torvalds odd = 0; \ 1871da177e4SLinus Torvalds } \ 1881da177e4SLinus Torvalds } \ 1891da177e4SLinus Torvalds exp = 0 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds #define Dbl_isinexact_to_fix(dbl_valueA,dbl_valueB,exponent) \ 1921da177e4SLinus Torvalds (exponent < (DBL_P-33) ? \ 1931da177e4SLinus Torvalds Dallp2(dbl_valueB) || Dallp1(dbl_valueA) << (DBL_EXP_LENGTH+1+exponent) : \ 1941da177e4SLinus Torvalds (exponent < (DBL_P-1) ? Dallp2(dbl_valueB) << (exponent + (33-DBL_P)) : \ 1951da177e4SLinus Torvalds FALSE)) 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds #define Dbl_isoverflow_to_int(exponent,dbl_valueA,dbl_valueB) \ 1981da177e4SLinus Torvalds ((exponent > SGL_FX_MAX_EXP + 1) || Dsign(dbl_valueA)==0 || \ 1991da177e4SLinus Torvalds Dmantissap1(dbl_valueA)!=0 || (Dallp2(dbl_valueB)>>21)!=0 ) 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds #define Dbl_isone_roundbit(dbl_valueA,dbl_valueB,exponent) \ 2021da177e4SLinus Torvalds ((exponent < (DBL_P - 33) ? \ 2031da177e4SLinus Torvalds Dallp1(dbl_valueA) >> ((30 - DBL_EXP_LENGTH) - exponent) : \ 2041da177e4SLinus Torvalds Dallp2(dbl_valueB) >> ((DBL_P - 2) - exponent)) & 1) 2051da177e4SLinus Torvalds 2061da177e4SLinus Torvalds #define Dbl_isone_stickybit(dbl_valueA,dbl_valueB,exponent) \ 2071da177e4SLinus Torvalds (exponent < (DBL_P-34) ? \ 2081da177e4SLinus Torvalds (Dallp2(dbl_valueB) || Dallp1(dbl_valueA)<<(DBL_EXP_LENGTH+2+exponent)) : \ 2091da177e4SLinus Torvalds (exponent<(DBL_P-2) ? (Dallp2(dbl_valueB) << (exponent + (34-DBL_P))) : \ 2101da177e4SLinus Torvalds FALSE)) 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds /* Int macros */ 2141da177e4SLinus Torvalds 2151da177e4SLinus Torvalds #define Int_from_sgl_mantissa(sgl_value,exponent) \ 2161da177e4SLinus Torvalds Sall(sgl_value) = \ 2171da177e4SLinus Torvalds (unsigned)(Sall(sgl_value) << SGL_EXP_LENGTH)>>(31 - exponent) 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds #define Int_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent) \ 2201da177e4SLinus Torvalds Shiftdouble(Dallp1(dbl_valueA),Dallp2(dbl_valueB),22,Dallp1(dbl_valueA)); \ 2211da177e4SLinus Torvalds if (exponent < 31) Dallp1(dbl_valueA) >>= 30 - exponent; \ 2221da177e4SLinus Torvalds else Dallp1(dbl_valueA) <<= 1 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds #define Int_negate(int_value) int_value = -int_value 2251da177e4SLinus Torvalds 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds /* Dint macros */ 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds #define Dint_from_sgl_mantissa(sgl_value,exponent,dresultA,dresultB) \ 2301da177e4SLinus Torvalds {Sall(sgl_value) <<= SGL_EXP_LENGTH; /* left-justify */ \ 2311da177e4SLinus Torvalds if (exponent <= 31) { \ 2321da177e4SLinus Torvalds Dintp1(dresultA) = 0; \ 2331da177e4SLinus Torvalds Dintp2(dresultB) = (unsigned)Sall(sgl_value) >> (31 - exponent); \ 2341da177e4SLinus Torvalds } \ 2351da177e4SLinus Torvalds else { \ 2361da177e4SLinus Torvalds Dintp1(dresultA) = Sall(sgl_value) >> (63 - exponent); \ 2371da177e4SLinus Torvalds Dintp2(dresultB) = Sall(sgl_value) << (exponent - 31); \ 2381da177e4SLinus Torvalds }} 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds 2411da177e4SLinus Torvalds #define Dint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB) \ 2421da177e4SLinus Torvalds {if (exponent < 32) { \ 2431da177e4SLinus Torvalds Dintp1(destA) = 0; \ 2441da177e4SLinus Torvalds if (exponent <= 20) \ 2451da177e4SLinus Torvalds Dintp2(destB) = Dallp1(dbl_valueA) >> 20-exponent; \ 2461da177e4SLinus Torvalds else Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \ 2471da177e4SLinus Torvalds 52-exponent,Dintp2(destB)); \ 2481da177e4SLinus Torvalds } \ 2491da177e4SLinus Torvalds else { \ 2501da177e4SLinus Torvalds if (exponent <= 52) { \ 2511da177e4SLinus Torvalds Dintp1(destA) = Dallp1(dbl_valueA) >> 52-exponent; \ 2521da177e4SLinus Torvalds if (exponent == 52) Dintp2(destB) = Dallp2(dbl_valueB); \ 2531da177e4SLinus Torvalds else Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \ 2541da177e4SLinus Torvalds 52-exponent,Dintp2(destB)); \ 2551da177e4SLinus Torvalds } \ 2561da177e4SLinus Torvalds else { \ 2571da177e4SLinus Torvalds Variable_shift_double(Dallp1(dbl_valueA),Dallp2(dbl_valueB), \ 2581da177e4SLinus Torvalds 84-exponent,Dintp1(destA)); \ 2591da177e4SLinus Torvalds Dintp2(destB) = Dallp2(dbl_valueB) << exponent-52; \ 2601da177e4SLinus Torvalds } \ 2611da177e4SLinus Torvalds }} 2621da177e4SLinus Torvalds 2631da177e4SLinus Torvalds #define Dint_setzero(dresultA,dresultB) \ 2641da177e4SLinus Torvalds Dintp1(dresultA) = 0; \ 2651da177e4SLinus Torvalds Dintp2(dresultB) = 0 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds #define Dint_setone_sign(dresultA,dresultB) \ 2681da177e4SLinus Torvalds Dintp1(dresultA) = ~Dintp1(dresultA); \ 2691da177e4SLinus Torvalds if ((Dintp2(dresultB) = -Dintp2(dresultB)) == 0) Dintp1(dresultA)++ 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds #define Dint_set_minint(dresultA,dresultB) \ 2721da177e4SLinus Torvalds Dintp1(dresultA) = (unsigned int)1<<31; \ 2731da177e4SLinus Torvalds Dintp2(dresultB) = 0 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvalds #define Dint_isone_lowp2(dresultB) (Dintp2(dresultB) & 01) 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds #define Dint_increment(dresultA,dresultB) \ 2781da177e4SLinus Torvalds if ((++Dintp2(dresultB))==0) Dintp1(dresultA)++ 2791da177e4SLinus Torvalds 2801da177e4SLinus Torvalds #define Dint_decrement(dresultA,dresultB) \ 2811da177e4SLinus Torvalds if ((Dintp2(dresultB)--)==0) Dintp1(dresultA)-- 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds #define Dint_negate(dresultA,dresultB) \ 2841da177e4SLinus Torvalds Dintp1(dresultA) = ~Dintp1(dresultA); \ 2851da177e4SLinus Torvalds if ((Dintp2(dresultB) = -Dintp2(dresultB))==0) Dintp1(dresultA)++ 2861da177e4SLinus Torvalds 2871da177e4SLinus Torvalds #define Dint_copyfromptr(src,destA,destB) \ 2881da177e4SLinus Torvalds Dintp1(destA) = src->wd0; \ 2891da177e4SLinus Torvalds Dintp2(destB) = src->wd1 2901da177e4SLinus Torvalds #define Dint_copytoptr(srcA,srcB,dest) \ 2911da177e4SLinus Torvalds dest->wd0 = Dintp1(srcA); \ 2921da177e4SLinus Torvalds dest->wd1 = Dintp2(srcB) 2931da177e4SLinus Torvalds 2941da177e4SLinus Torvalds 2951da177e4SLinus Torvalds /* other macros */ 2961da177e4SLinus Torvalds 2971da177e4SLinus Torvalds #define Find_ms_one_bit(value, position) \ 2981da177e4SLinus Torvalds { \ 2991da177e4SLinus Torvalds int var; \ 3001da177e4SLinus Torvalds for (var=8; var >=1; var >>= 1) { \ 3011da177e4SLinus Torvalds if (value >> 32 - position) \ 3021da177e4SLinus Torvalds position -= var; \ 3031da177e4SLinus Torvalds else position += var; \ 3041da177e4SLinus Torvalds } \ 3051da177e4SLinus Torvalds if ((value >> 32 - position) == 0) \ 3061da177e4SLinus Torvalds position--; \ 3071da177e4SLinus Torvalds else position -= 2; \ 3081da177e4SLinus Torvalds } 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds 3111da177e4SLinus Torvalds /* 3121da177e4SLinus Torvalds * Unsigned int macros 3131da177e4SLinus Torvalds */ 3141da177e4SLinus Torvalds #define Duint_copyfromptr(src,destA,destB) \ 3151da177e4SLinus Torvalds Dint_copyfromptr(src,destA,destB) 3161da177e4SLinus Torvalds #define Duint_copytoptr(srcA,srcB,dest) \ 3171da177e4SLinus Torvalds Dint_copytoptr(srcA,srcB,dest) 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds #define Suint_isinexact_to_sgl(int_value) \ 3201da177e4SLinus Torvalds (int_value << 32 - SGL_EXP_LENGTH) 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds #define Sgl_roundnearest_from_suint(suint_value,sgl_value) \ 3231da177e4SLinus Torvalds if (suint_value & 1<<(SGL_EXP_LENGTH - 1)) /* round bit */ \ 3241da177e4SLinus Torvalds if ((suint_value << 33 - SGL_EXP_LENGTH) || Slow(sgl_value)) \ 3251da177e4SLinus Torvalds Sall(sgl_value)++ 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds #define Duint_isinexact_to_sgl(duint_valueA,duint_valueB) \ 3281da177e4SLinus Torvalds ((Duintp1(duint_valueA) << 32 - SGL_EXP_LENGTH) || Duintp2(duint_valueB)) 3291da177e4SLinus Torvalds 3301da177e4SLinus Torvalds #define Sgl_roundnearest_from_duint(duint_valueA,duint_valueB,sgl_value) \ 3311da177e4SLinus Torvalds if (Duintp1(duint_valueA) & 1<<(SGL_EXP_LENGTH - 1)) \ 3321da177e4SLinus Torvalds if ((Duintp1(duint_valueA) << 33 - SGL_EXP_LENGTH) || \ 3331da177e4SLinus Torvalds Duintp2(duint_valueB) || Slow(sgl_value)) Sall(sgl_value)++ 3341da177e4SLinus Torvalds 3351da177e4SLinus Torvalds #define Duint_isinexact_to_dbl(duint_value) \ 3361da177e4SLinus Torvalds (Duintp2(duint_value) << 32 - DBL_EXP_LENGTH) 3371da177e4SLinus Torvalds 3381da177e4SLinus Torvalds #define Dbl_roundnearest_from_duint(duint_opndB,dbl_opndA,dbl_opndB) \ 3391da177e4SLinus Torvalds if (Duintp2(duint_opndB) & 1<<(DBL_EXP_LENGTH - 1)) \ 3401da177e4SLinus Torvalds if ((Duintp2(duint_opndB) << 33 - DBL_EXP_LENGTH) || Dlowp2(dbl_opndB)) \ 3411da177e4SLinus Torvalds if ((++Dallp2(dbl_opndB))==0) Dallp1(dbl_opndA)++ 3421da177e4SLinus Torvalds 3431da177e4SLinus Torvalds #define Suint_from_sgl_mantissa(src,exponent,result) \ 3441da177e4SLinus Torvalds Sall(result) = (unsigned)(Sall(src) << SGL_EXP_LENGTH)>>(31 - exponent) 3451da177e4SLinus Torvalds 3461da177e4SLinus Torvalds #define Sgl_isinexact_to_unsigned(sgl_value,exponent) \ 3471da177e4SLinus Torvalds Sgl_isinexact_to_fix(sgl_value,exponent) 3481da177e4SLinus Torvalds 3491da177e4SLinus Torvalds #define Duint_from_sgl_mantissa(sgl_value,exponent,dresultA,dresultB) \ 350cabd91c3SJohn David Anglin {unsigned int val = Sall(sgl_value) << SGL_EXP_LENGTH; \ 3511da177e4SLinus Torvalds if (exponent <= 31) { \ 3521da177e4SLinus Torvalds Dintp1(dresultA) = 0; \ 353cabd91c3SJohn David Anglin Dintp2(dresultB) = val >> (31 - exponent); \ 3541da177e4SLinus Torvalds } \ 3551da177e4SLinus Torvalds else { \ 356cabd91c3SJohn David Anglin Dintp1(dresultA) = val >> (63 - exponent); \ 357cabd91c3SJohn David Anglin Dintp2(dresultB) = exponent <= 62 ? val << (exponent - 31) : 0; \ 3581da177e4SLinus Torvalds } \ 3591da177e4SLinus Torvalds } 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds #define Duint_setzero(dresultA,dresultB) \ 3621da177e4SLinus Torvalds Dint_setzero(dresultA,dresultB) 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds #define Duint_increment(dresultA,dresultB) Dint_increment(dresultA,dresultB) 3651da177e4SLinus Torvalds 3661da177e4SLinus Torvalds #define Duint_isone_lowp2(dresultB) Dint_isone_lowp2(dresultB) 3671da177e4SLinus Torvalds 3681da177e4SLinus Torvalds #define Suint_from_dbl_mantissa(srcA,srcB,exponent,dest) \ 3691da177e4SLinus Torvalds Shiftdouble(Dallp1(srcA),Dallp2(srcB),21,dest); \ 3701da177e4SLinus Torvalds dest = (unsigned)dest >> 31 - exponent 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvalds #define Dbl_isinexact_to_unsigned(dbl_valueA,dbl_valueB,exponent) \ 3731da177e4SLinus Torvalds Dbl_isinexact_to_fix(dbl_valueA,dbl_valueB,exponent) 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds #define Duint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB) \ 3761da177e4SLinus Torvalds Dint_from_dbl_mantissa(dbl_valueA,dbl_valueB,exponent,destA,destB) 377