18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Linux/PA-RISC Project (http://www.parisc-linux.org/) 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Floating-point emulation code 68c2ecf20Sopenharmony_ci * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifdef __NO_PA_HDRS 108c2ecf20Sopenharmony_ci PA header file -- do not include this header file for non-PA builds. 118c2ecf20Sopenharmony_ci#endif 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci/* 32-bit word grabbing functions */ 148c2ecf20Sopenharmony_ci#define Sgl_firstword(value) Sall(value) 158c2ecf20Sopenharmony_ci#define Sgl_secondword(value) dummy_location 168c2ecf20Sopenharmony_ci#define Sgl_thirdword(value) dummy_location 178c2ecf20Sopenharmony_ci#define Sgl_fourthword(value) dummy_location 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define Sgl_sign(object) Ssign(object) 208c2ecf20Sopenharmony_ci#define Sgl_exponent(object) Sexponent(object) 218c2ecf20Sopenharmony_ci#define Sgl_signexponent(object) Ssignexponent(object) 228c2ecf20Sopenharmony_ci#define Sgl_mantissa(object) Smantissa(object) 238c2ecf20Sopenharmony_ci#define Sgl_exponentmantissa(object) Sexponentmantissa(object) 248c2ecf20Sopenharmony_ci#define Sgl_all(object) Sall(object) 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/* sgl_and_signs ANDs the sign bits of each argument and puts the result 278c2ecf20Sopenharmony_ci * into the first argument. sgl_or_signs ors those same sign bits */ 288c2ecf20Sopenharmony_ci#define Sgl_and_signs( src1dst, src2) \ 298c2ecf20Sopenharmony_ci Sall(src1dst) = (Sall(src2)|~((unsigned int)1<<31)) & Sall(src1dst) 308c2ecf20Sopenharmony_ci#define Sgl_or_signs( src1dst, src2) \ 318c2ecf20Sopenharmony_ci Sall(src1dst) = (Sall(src2)&((unsigned int)1<<31)) | Sall(src1dst) 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/* The hidden bit is always the low bit of the exponent */ 348c2ecf20Sopenharmony_ci#define Sgl_clear_exponent_set_hidden(srcdst) Deposit_sexponent(srcdst,1) 358c2ecf20Sopenharmony_ci#define Sgl_clear_signexponent_set_hidden(srcdst) \ 368c2ecf20Sopenharmony_ci Deposit_ssignexponent(srcdst,1) 378c2ecf20Sopenharmony_ci#define Sgl_clear_sign(srcdst) Sall(srcdst) &= ~((unsigned int)1<<31) 388c2ecf20Sopenharmony_ci#define Sgl_clear_signexponent(srcdst) Sall(srcdst) &= 0x007fffff 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* varamount must be less than 32 for the next three functions */ 418c2ecf20Sopenharmony_ci#define Sgl_rightshift(srcdst, varamount) \ 428c2ecf20Sopenharmony_ci Sall(srcdst) >>= varamount 438c2ecf20Sopenharmony_ci#define Sgl_leftshift(srcdst, varamount) \ 448c2ecf20Sopenharmony_ci Sall(srcdst) <<= varamount 458c2ecf20Sopenharmony_ci#define Sgl_rightshift_exponentmantissa(srcdst, varamount) \ 468c2ecf20Sopenharmony_ci Sall(srcdst) = \ 478c2ecf20Sopenharmony_ci (Sexponentmantissa(srcdst) >> varamount) | \ 488c2ecf20Sopenharmony_ci (Sall(srcdst) & ((unsigned int)1<<31)) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define Sgl_leftshiftby1_withextent(left,right,result) \ 518c2ecf20Sopenharmony_ci Shiftdouble(Sall(left),Extall(right),31,Sall(result)) 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define Sgl_rightshiftby1_withextent(left,right,dst) \ 548c2ecf20Sopenharmony_ci Shiftdouble(Sall(left),Extall(right),1,Extall(right)) 558c2ecf20Sopenharmony_ci#define Sgl_arithrightshiftby1(srcdst) \ 568c2ecf20Sopenharmony_ci Sall(srcdst) = (int)Sall(srcdst) >> 1 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* Sign extend the sign bit with an integer destination */ 598c2ecf20Sopenharmony_ci#define Sgl_signextendedsign(value) Ssignedsign(value) 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#define Sgl_isone_hidden(sgl_value) (Shidden(sgl_value)) 628c2ecf20Sopenharmony_ci#define Sgl_increment(sgl_value) Sall(sgl_value) += 1 638c2ecf20Sopenharmony_ci#define Sgl_increment_mantissa(sgl_value) \ 648c2ecf20Sopenharmony_ci Deposit_smantissa(sgl_value,sgl_value+1) 658c2ecf20Sopenharmony_ci#define Sgl_decrement(sgl_value) Sall(sgl_value) -= 1 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define Sgl_isone_sign(sgl_value) (Is_ssign(sgl_value)!=0) 688c2ecf20Sopenharmony_ci#define Sgl_isone_hiddenoverflow(sgl_value) \ 698c2ecf20Sopenharmony_ci (Is_shiddenoverflow(sgl_value)!=0) 708c2ecf20Sopenharmony_ci#define Sgl_isone_lowmantissa(sgl_value) (Is_slow(sgl_value)!=0) 718c2ecf20Sopenharmony_ci#define Sgl_isone_signaling(sgl_value) (Is_ssignaling(sgl_value)!=0) 728c2ecf20Sopenharmony_ci#define Sgl_is_signalingnan(sgl_value) (Ssignalingnan(sgl_value)==0x1ff) 738c2ecf20Sopenharmony_ci#define Sgl_isnotzero(sgl_value) (Sall(sgl_value)!=0) 748c2ecf20Sopenharmony_ci#define Sgl_isnotzero_hiddenhigh7mantissa(sgl_value) \ 758c2ecf20Sopenharmony_ci (Shiddenhigh7mantissa(sgl_value)!=0) 768c2ecf20Sopenharmony_ci#define Sgl_isnotzero_low4(sgl_value) (Slow4(sgl_value)!=0) 778c2ecf20Sopenharmony_ci#define Sgl_isnotzero_exponent(sgl_value) (Sexponent(sgl_value)!=0) 788c2ecf20Sopenharmony_ci#define Sgl_isnotzero_mantissa(sgl_value) (Smantissa(sgl_value)!=0) 798c2ecf20Sopenharmony_ci#define Sgl_isnotzero_exponentmantissa(sgl_value) \ 808c2ecf20Sopenharmony_ci (Sexponentmantissa(sgl_value)!=0) 818c2ecf20Sopenharmony_ci#define Sgl_iszero(sgl_value) (Sall(sgl_value)==0) 828c2ecf20Sopenharmony_ci#define Sgl_iszero_signaling(sgl_value) (Is_ssignaling(sgl_value)==0) 838c2ecf20Sopenharmony_ci#define Sgl_iszero_hidden(sgl_value) (Is_shidden(sgl_value)==0) 848c2ecf20Sopenharmony_ci#define Sgl_iszero_hiddenoverflow(sgl_value) \ 858c2ecf20Sopenharmony_ci (Is_shiddenoverflow(sgl_value)==0) 868c2ecf20Sopenharmony_ci#define Sgl_iszero_hiddenhigh3mantissa(sgl_value) \ 878c2ecf20Sopenharmony_ci (Shiddenhigh3mantissa(sgl_value)==0) 888c2ecf20Sopenharmony_ci#define Sgl_iszero_hiddenhigh7mantissa(sgl_value) \ 898c2ecf20Sopenharmony_ci (Shiddenhigh7mantissa(sgl_value)==0) 908c2ecf20Sopenharmony_ci#define Sgl_iszero_sign(sgl_value) (Is_ssign(sgl_value)==0) 918c2ecf20Sopenharmony_ci#define Sgl_iszero_exponent(sgl_value) (Sexponent(sgl_value)==0) 928c2ecf20Sopenharmony_ci#define Sgl_iszero_mantissa(sgl_value) (Smantissa(sgl_value)==0) 938c2ecf20Sopenharmony_ci#define Sgl_iszero_exponentmantissa(sgl_value) \ 948c2ecf20Sopenharmony_ci (Sexponentmantissa(sgl_value)==0) 958c2ecf20Sopenharmony_ci#define Sgl_isinfinity_exponent(sgl_value) \ 968c2ecf20Sopenharmony_ci (Sgl_exponent(sgl_value)==SGL_INFINITY_EXPONENT) 978c2ecf20Sopenharmony_ci#define Sgl_isnotinfinity_exponent(sgl_value) \ 988c2ecf20Sopenharmony_ci (Sgl_exponent(sgl_value)!=SGL_INFINITY_EXPONENT) 998c2ecf20Sopenharmony_ci#define Sgl_isinfinity(sgl_value) \ 1008c2ecf20Sopenharmony_ci (Sgl_exponent(sgl_value)==SGL_INFINITY_EXPONENT && \ 1018c2ecf20Sopenharmony_ci Sgl_mantissa(sgl_value)==0) 1028c2ecf20Sopenharmony_ci#define Sgl_isnan(sgl_value) \ 1038c2ecf20Sopenharmony_ci (Sgl_exponent(sgl_value)==SGL_INFINITY_EXPONENT && \ 1048c2ecf20Sopenharmony_ci Sgl_mantissa(sgl_value)!=0) 1058c2ecf20Sopenharmony_ci#define Sgl_isnotnan(sgl_value) \ 1068c2ecf20Sopenharmony_ci (Sgl_exponent(sgl_value)!=SGL_INFINITY_EXPONENT || \ 1078c2ecf20Sopenharmony_ci Sgl_mantissa(sgl_value)==0) 1088c2ecf20Sopenharmony_ci#define Sgl_islessthan(sgl_op1,sgl_op2) \ 1098c2ecf20Sopenharmony_ci (Sall(sgl_op1) < Sall(sgl_op2)) 1108c2ecf20Sopenharmony_ci#define Sgl_isgreaterthan(sgl_op1,sgl_op2) \ 1118c2ecf20Sopenharmony_ci (Sall(sgl_op1) > Sall(sgl_op2)) 1128c2ecf20Sopenharmony_ci#define Sgl_isnotlessthan(sgl_op1,sgl_op2) \ 1138c2ecf20Sopenharmony_ci (Sall(sgl_op1) >= Sall(sgl_op2)) 1148c2ecf20Sopenharmony_ci#define Sgl_isequal(sgl_op1,sgl_op2) \ 1158c2ecf20Sopenharmony_ci (Sall(sgl_op1) == Sall(sgl_op2)) 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#define Sgl_leftshiftby8(sgl_value) \ 1188c2ecf20Sopenharmony_ci Sall(sgl_value) <<= 8 1198c2ecf20Sopenharmony_ci#define Sgl_leftshiftby4(sgl_value) \ 1208c2ecf20Sopenharmony_ci Sall(sgl_value) <<= 4 1218c2ecf20Sopenharmony_ci#define Sgl_leftshiftby3(sgl_value) \ 1228c2ecf20Sopenharmony_ci Sall(sgl_value) <<= 3 1238c2ecf20Sopenharmony_ci#define Sgl_leftshiftby2(sgl_value) \ 1248c2ecf20Sopenharmony_ci Sall(sgl_value) <<= 2 1258c2ecf20Sopenharmony_ci#define Sgl_leftshiftby1(sgl_value) \ 1268c2ecf20Sopenharmony_ci Sall(sgl_value) <<= 1 1278c2ecf20Sopenharmony_ci#define Sgl_rightshiftby1(sgl_value) \ 1288c2ecf20Sopenharmony_ci Sall(sgl_value) >>= 1 1298c2ecf20Sopenharmony_ci#define Sgl_rightshiftby4(sgl_value) \ 1308c2ecf20Sopenharmony_ci Sall(sgl_value) >>= 4 1318c2ecf20Sopenharmony_ci#define Sgl_rightshiftby8(sgl_value) \ 1328c2ecf20Sopenharmony_ci Sall(sgl_value) >>= 8 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci#define Sgl_ismagnitudeless(signlessleft,signlessright) \ 1358c2ecf20Sopenharmony_ci/* unsigned int signlessleft, signlessright; */ \ 1368c2ecf20Sopenharmony_ci (signlessleft < signlessright) 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci#define Sgl_copytoint_exponentmantissa(source,dest) \ 1408c2ecf20Sopenharmony_ci dest = Sexponentmantissa(source) 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci/* A quiet NaN has the high mantissa bit clear and at least on other (in this 1438c2ecf20Sopenharmony_ci * case the adjacent bit) bit set. */ 1448c2ecf20Sopenharmony_ci#define Sgl_set_quiet(sgl_value) Deposit_shigh2mantissa(sgl_value,1) 1458c2ecf20Sopenharmony_ci#define Sgl_set_exponent(sgl_value,exp) Deposit_sexponent(sgl_value,exp) 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci#define Sgl_set_mantissa(dest,value) Deposit_smantissa(dest,value) 1488c2ecf20Sopenharmony_ci#define Sgl_set_exponentmantissa(dest,value) \ 1498c2ecf20Sopenharmony_ci Deposit_sexponentmantissa(dest,value) 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci/* An infinity is represented with the max exponent and a zero mantissa */ 1528c2ecf20Sopenharmony_ci#define Sgl_setinfinity_exponent(sgl_value) \ 1538c2ecf20Sopenharmony_ci Deposit_sexponent(sgl_value,SGL_INFINITY_EXPONENT) 1548c2ecf20Sopenharmony_ci#define Sgl_setinfinity_exponentmantissa(sgl_value) \ 1558c2ecf20Sopenharmony_ci Deposit_sexponentmantissa(sgl_value, \ 1568c2ecf20Sopenharmony_ci (SGL_INFINITY_EXPONENT << (32-(1+SGL_EXP_LENGTH)))) 1578c2ecf20Sopenharmony_ci#define Sgl_setinfinitypositive(sgl_value) \ 1588c2ecf20Sopenharmony_ci Sall(sgl_value) = (SGL_INFINITY_EXPONENT << (32-(1+SGL_EXP_LENGTH))) 1598c2ecf20Sopenharmony_ci#define Sgl_setinfinitynegative(sgl_value) \ 1608c2ecf20Sopenharmony_ci Sall(sgl_value) = (SGL_INFINITY_EXPONENT << (32-(1+SGL_EXP_LENGTH))) \ 1618c2ecf20Sopenharmony_ci | ((unsigned int)1<<31) 1628c2ecf20Sopenharmony_ci#define Sgl_setinfinity(sgl_value,sign) \ 1638c2ecf20Sopenharmony_ci Sall(sgl_value) = (SGL_INFINITY_EXPONENT << (32-(1+SGL_EXP_LENGTH))) | \ 1648c2ecf20Sopenharmony_ci ((unsigned int)sign << 31) 1658c2ecf20Sopenharmony_ci#define Sgl_sethigh4bits(sgl_value, extsign) \ 1668c2ecf20Sopenharmony_ci Deposit_shigh4(sgl_value,extsign) 1678c2ecf20Sopenharmony_ci#define Sgl_set_sign(sgl_value,sign) Deposit_ssign(sgl_value,sign) 1688c2ecf20Sopenharmony_ci#define Sgl_invert_sign(sgl_value) \ 1698c2ecf20Sopenharmony_ci Deposit_ssign(sgl_value,~Ssign(sgl_value)) 1708c2ecf20Sopenharmony_ci#define Sgl_setone_sign(sgl_value) Deposit_ssign(sgl_value,1) 1718c2ecf20Sopenharmony_ci#define Sgl_setone_lowmantissa(sgl_value) Deposit_slow(sgl_value,1) 1728c2ecf20Sopenharmony_ci#define Sgl_setzero_sign(sgl_value) Sall(sgl_value) &= 0x7fffffff 1738c2ecf20Sopenharmony_ci#define Sgl_setzero_exponent(sgl_value) Sall(sgl_value) &= 0x807fffff 1748c2ecf20Sopenharmony_ci#define Sgl_setzero_mantissa(sgl_value) Sall(sgl_value) &= 0xff800000 1758c2ecf20Sopenharmony_ci#define Sgl_setzero_exponentmantissa(sgl_value) Sall(sgl_value) &= 0x80000000 1768c2ecf20Sopenharmony_ci#define Sgl_setzero(sgl_value) Sall(sgl_value) = 0 1778c2ecf20Sopenharmony_ci#define Sgl_setnegativezero(sgl_value) Sall(sgl_value) = (unsigned int)1 << 31 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci/* Use following macro for both overflow & underflow conditions */ 1808c2ecf20Sopenharmony_ci#define ovfl - 1818c2ecf20Sopenharmony_ci#define unfl + 1828c2ecf20Sopenharmony_ci#define Sgl_setwrapped_exponent(sgl_value,exponent,op) \ 1838c2ecf20Sopenharmony_ci Deposit_sexponent(sgl_value,(exponent op SGL_WRAP)) 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci#define Sgl_setlargestpositive(sgl_value) \ 1868c2ecf20Sopenharmony_ci Sall(sgl_value) = ((SGL_EMAX+SGL_BIAS) << (32-(1+SGL_EXP_LENGTH))) \ 1878c2ecf20Sopenharmony_ci | ((1<<(32-(1+SGL_EXP_LENGTH))) - 1 ) 1888c2ecf20Sopenharmony_ci#define Sgl_setlargestnegative(sgl_value) \ 1898c2ecf20Sopenharmony_ci Sall(sgl_value) = ((SGL_EMAX+SGL_BIAS) << (32-(1+SGL_EXP_LENGTH))) \ 1908c2ecf20Sopenharmony_ci | ((1<<(32-(1+SGL_EXP_LENGTH))) - 1 ) \ 1918c2ecf20Sopenharmony_ci | ((unsigned int)1<<31) 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci#define Sgl_setnegativeinfinity(sgl_value) \ 1948c2ecf20Sopenharmony_ci Sall(sgl_value) = \ 1958c2ecf20Sopenharmony_ci ((1<<SGL_EXP_LENGTH) | SGL_INFINITY_EXPONENT) << (32-(1+SGL_EXP_LENGTH)) 1968c2ecf20Sopenharmony_ci#define Sgl_setlargest(sgl_value,sign) \ 1978c2ecf20Sopenharmony_ci Sall(sgl_value) = (unsigned int)sign << 31 | \ 1988c2ecf20Sopenharmony_ci (((SGL_EMAX+SGL_BIAS) << (32-(1+SGL_EXP_LENGTH))) \ 1998c2ecf20Sopenharmony_ci | ((1 << (32-(1+SGL_EXP_LENGTH))) - 1 )) 2008c2ecf20Sopenharmony_ci#define Sgl_setlargest_exponentmantissa(sgl_value) \ 2018c2ecf20Sopenharmony_ci Sall(sgl_value) = Sall(sgl_value) & ((unsigned int)1<<31) | \ 2028c2ecf20Sopenharmony_ci (((SGL_EMAX+SGL_BIAS) << (32-(1+SGL_EXP_LENGTH))) \ 2038c2ecf20Sopenharmony_ci | ((1 << (32-(1+SGL_EXP_LENGTH))) - 1 )) 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci/* The high bit is always zero so arithmetic or logical shifts will work. */ 2068c2ecf20Sopenharmony_ci#define Sgl_right_align(srcdst,shift,extent) \ 2078c2ecf20Sopenharmony_ci /* sgl_floating_point srcdst; int shift; extension extent */ \ 2088c2ecf20Sopenharmony_ci if (shift < 32) { \ 2098c2ecf20Sopenharmony_ci Extall(extent) = Sall(srcdst) << (32-(shift)); \ 2108c2ecf20Sopenharmony_ci Sall(srcdst) >>= shift; \ 2118c2ecf20Sopenharmony_ci } \ 2128c2ecf20Sopenharmony_ci else { \ 2138c2ecf20Sopenharmony_ci Extall(extent) = Sall(srcdst); \ 2148c2ecf20Sopenharmony_ci Sall(srcdst) = 0; \ 2158c2ecf20Sopenharmony_ci } 2168c2ecf20Sopenharmony_ci#define Sgl_hiddenhigh3mantissa(sgl_value) Shiddenhigh3mantissa(sgl_value) 2178c2ecf20Sopenharmony_ci#define Sgl_hidden(sgl_value) Shidden(sgl_value) 2188c2ecf20Sopenharmony_ci#define Sgl_lowmantissa(sgl_value) Slow(sgl_value) 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci/* The left argument is never smaller than the right argument */ 2218c2ecf20Sopenharmony_ci#define Sgl_subtract(sgl_left,sgl_right,sgl_result) \ 2228c2ecf20Sopenharmony_ci Sall(sgl_result) = Sall(sgl_left) - Sall(sgl_right) 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci/* Subtract right augmented with extension from left augmented with zeros and 2258c2ecf20Sopenharmony_ci * store into result and extension. */ 2268c2ecf20Sopenharmony_ci#define Sgl_subtract_withextension(left,right,extent,result) \ 2278c2ecf20Sopenharmony_ci /* sgl_floating_point left,right,result; extension extent */ \ 2288c2ecf20Sopenharmony_ci Sgl_subtract(left,right,result); \ 2298c2ecf20Sopenharmony_ci if((Extall(extent) = 0-Extall(extent))) \ 2308c2ecf20Sopenharmony_ci Sall(result) = Sall(result)-1 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci#define Sgl_addition(sgl_left,sgl_right,sgl_result) \ 2338c2ecf20Sopenharmony_ci Sall(sgl_result) = Sall(sgl_left) + Sall(sgl_right) 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci#define Sgl_xortointp1(left,right,result) \ 2368c2ecf20Sopenharmony_ci result = Sall(left) XOR Sall(right); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci#define Sgl_xorfromintp1(left,right,result) \ 2398c2ecf20Sopenharmony_ci Sall(result) = left XOR Sall(right) 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ci/* Need to Initialize */ 2428c2ecf20Sopenharmony_ci#define Sgl_makequietnan(dest) \ 2438c2ecf20Sopenharmony_ci Sall(dest) = ((SGL_EMAX+SGL_BIAS)+1)<< (32-(1+SGL_EXP_LENGTH)) \ 2448c2ecf20Sopenharmony_ci | (1<<(32-(1+SGL_EXP_LENGTH+2))) 2458c2ecf20Sopenharmony_ci#define Sgl_makesignalingnan(dest) \ 2468c2ecf20Sopenharmony_ci Sall(dest) = ((SGL_EMAX+SGL_BIAS)+1)<< (32-(1+SGL_EXP_LENGTH)) \ 2478c2ecf20Sopenharmony_ci | (1<<(32-(1+SGL_EXP_LENGTH+1))) 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci#define Sgl_normalize(sgl_opnd,exponent) \ 2508c2ecf20Sopenharmony_ci while(Sgl_iszero_hiddenhigh7mantissa(sgl_opnd)) { \ 2518c2ecf20Sopenharmony_ci Sgl_leftshiftby8(sgl_opnd); \ 2528c2ecf20Sopenharmony_ci exponent -= 8; \ 2538c2ecf20Sopenharmony_ci } \ 2548c2ecf20Sopenharmony_ci if(Sgl_iszero_hiddenhigh3mantissa(sgl_opnd)) { \ 2558c2ecf20Sopenharmony_ci Sgl_leftshiftby4(sgl_opnd); \ 2568c2ecf20Sopenharmony_ci exponent -= 4; \ 2578c2ecf20Sopenharmony_ci } \ 2588c2ecf20Sopenharmony_ci while(Sgl_iszero_hidden(sgl_opnd)) { \ 2598c2ecf20Sopenharmony_ci Sgl_leftshiftby1(sgl_opnd); \ 2608c2ecf20Sopenharmony_ci exponent -= 1; \ 2618c2ecf20Sopenharmony_ci } 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci#define Sgl_setoverflow(sgl_opnd) \ 2648c2ecf20Sopenharmony_ci /* set result to infinity or largest number */ \ 2658c2ecf20Sopenharmony_ci switch (Rounding_mode()) { \ 2668c2ecf20Sopenharmony_ci case ROUNDPLUS: \ 2678c2ecf20Sopenharmony_ci if (Sgl_isone_sign(sgl_opnd)) { \ 2688c2ecf20Sopenharmony_ci Sgl_setlargestnegative(sgl_opnd); \ 2698c2ecf20Sopenharmony_ci } \ 2708c2ecf20Sopenharmony_ci else { \ 2718c2ecf20Sopenharmony_ci Sgl_setinfinitypositive(sgl_opnd); \ 2728c2ecf20Sopenharmony_ci } \ 2738c2ecf20Sopenharmony_ci break; \ 2748c2ecf20Sopenharmony_ci case ROUNDMINUS: \ 2758c2ecf20Sopenharmony_ci if (Sgl_iszero_sign(sgl_opnd)) { \ 2768c2ecf20Sopenharmony_ci Sgl_setlargestpositive(sgl_opnd); \ 2778c2ecf20Sopenharmony_ci } \ 2788c2ecf20Sopenharmony_ci else { \ 2798c2ecf20Sopenharmony_ci Sgl_setinfinitynegative(sgl_opnd); \ 2808c2ecf20Sopenharmony_ci } \ 2818c2ecf20Sopenharmony_ci break; \ 2828c2ecf20Sopenharmony_ci case ROUNDNEAREST: \ 2838c2ecf20Sopenharmony_ci Sgl_setinfinity_exponentmantissa(sgl_opnd); \ 2848c2ecf20Sopenharmony_ci break; \ 2858c2ecf20Sopenharmony_ci case ROUNDZERO: \ 2868c2ecf20Sopenharmony_ci Sgl_setlargest_exponentmantissa(sgl_opnd); \ 2878c2ecf20Sopenharmony_ci } 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci#define Sgl_denormalize(opnd,exponent,guard,sticky,inexact) \ 2908c2ecf20Sopenharmony_ci Sgl_clear_signexponent_set_hidden(opnd); \ 2918c2ecf20Sopenharmony_ci if (exponent >= (1 - SGL_P)) { \ 2928c2ecf20Sopenharmony_ci guard = (Sall(opnd) >> -exponent) & 1; \ 2938c2ecf20Sopenharmony_ci if (exponent < 0) sticky |= Sall(opnd) << (32+exponent); \ 2948c2ecf20Sopenharmony_ci inexact = guard | sticky; \ 2958c2ecf20Sopenharmony_ci Sall(opnd) >>= (1-exponent); \ 2968c2ecf20Sopenharmony_ci } \ 2978c2ecf20Sopenharmony_ci else { \ 2988c2ecf20Sopenharmony_ci guard = 0; \ 2998c2ecf20Sopenharmony_ci sticky |= Sall(opnd); \ 3008c2ecf20Sopenharmony_ci inexact = sticky; \ 3018c2ecf20Sopenharmony_ci Sgl_setzero(opnd); \ 3028c2ecf20Sopenharmony_ci } 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci/* 3058c2ecf20Sopenharmony_ci * The fused multiply add instructions requires a single extended format, 3068c2ecf20Sopenharmony_ci * with 48 bits of mantissa. 3078c2ecf20Sopenharmony_ci */ 3088c2ecf20Sopenharmony_ci#define SGLEXT_THRESHOLD 48 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci#define Sglext_setzero(valA,valB) \ 3118c2ecf20Sopenharmony_ci Sextallp1(valA) = 0; Sextallp2(valB) = 0 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci#define Sglext_isnotzero_mantissap2(valB) (Sextallp2(valB)!=0) 3148c2ecf20Sopenharmony_ci#define Sglext_isone_lowp1(val) (Sextlowp1(val)!=0) 3158c2ecf20Sopenharmony_ci#define Sglext_isone_highp2(val) (Sexthighp2(val)!=0) 3168c2ecf20Sopenharmony_ci#define Sglext_isnotzero_low31p2(val) (Sextlow31p2(val)!=0) 3178c2ecf20Sopenharmony_ci#define Sglext_iszero(valA,valB) (Sextallp1(valA)==0 && Sextallp2(valB)==0) 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci#define Sgl_copytoptr(src,destptr) *destptr = src 3208c2ecf20Sopenharmony_ci#define Sgl_copyfromptr(srcptr,dest) dest = *srcptr 3218c2ecf20Sopenharmony_ci#define Sglext_copy(srca,srcb,desta,destb) \ 3228c2ecf20Sopenharmony_ci Sextallp1(desta) = Sextallp1(srca); \ 3238c2ecf20Sopenharmony_ci Sextallp2(destb) = Sextallp2(srcb) 3248c2ecf20Sopenharmony_ci#define Sgl_copyto_sglext(src1,dest1,dest2) \ 3258c2ecf20Sopenharmony_ci Sextallp1(dest1) = Sall(src1); Sextallp2(dest2) = 0 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci#define Sglext_swap_lower(leftp2,rightp2) \ 3288c2ecf20Sopenharmony_ci Sextallp2(leftp2) = Sextallp2(leftp2) XOR Sextallp2(rightp2); \ 3298c2ecf20Sopenharmony_ci Sextallp2(rightp2) = Sextallp2(leftp2) XOR Sextallp2(rightp2); \ 3308c2ecf20Sopenharmony_ci Sextallp2(leftp2) = Sextallp2(leftp2) XOR Sextallp2(rightp2) 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci#define Sglext_setone_lowmantissap2(value) Deposit_dlowp2(value,1) 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci/* The high bit is always zero so arithmetic or logical shifts will work. */ 3358c2ecf20Sopenharmony_ci#define Sglext_right_align(srcdstA,srcdstB,shift) \ 3368c2ecf20Sopenharmony_ci {int shiftamt, sticky; \ 3378c2ecf20Sopenharmony_ci shiftamt = shift % 32; \ 3388c2ecf20Sopenharmony_ci sticky = 0; \ 3398c2ecf20Sopenharmony_ci switch (shift/32) { \ 3408c2ecf20Sopenharmony_ci case 0: if (shiftamt > 0) { \ 3418c2ecf20Sopenharmony_ci sticky = Sextallp2(srcdstB) << 32 - (shiftamt); \ 3428c2ecf20Sopenharmony_ci Variable_shift_double(Sextallp1(srcdstA), \ 3438c2ecf20Sopenharmony_ci Sextallp2(srcdstB),shiftamt,Sextallp2(srcdstB)); \ 3448c2ecf20Sopenharmony_ci Sextallp1(srcdstA) >>= shiftamt; \ 3458c2ecf20Sopenharmony_ci } \ 3468c2ecf20Sopenharmony_ci break; \ 3478c2ecf20Sopenharmony_ci case 1: if (shiftamt > 0) { \ 3488c2ecf20Sopenharmony_ci sticky = (Sextallp1(srcdstA) << 32 - (shiftamt)) | \ 3498c2ecf20Sopenharmony_ci Sextallp2(srcdstB); \ 3508c2ecf20Sopenharmony_ci } \ 3518c2ecf20Sopenharmony_ci else { \ 3528c2ecf20Sopenharmony_ci sticky = Sextallp2(srcdstB); \ 3538c2ecf20Sopenharmony_ci } \ 3548c2ecf20Sopenharmony_ci Sextallp2(srcdstB) = Sextallp1(srcdstA) >> shiftamt; \ 3558c2ecf20Sopenharmony_ci Sextallp1(srcdstA) = 0; \ 3568c2ecf20Sopenharmony_ci break; \ 3578c2ecf20Sopenharmony_ci } \ 3588c2ecf20Sopenharmony_ci if (sticky) Sglext_setone_lowmantissap2(srcdstB); \ 3598c2ecf20Sopenharmony_ci } 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci/* The left argument is never smaller than the right argument */ 3628c2ecf20Sopenharmony_ci#define Sglext_subtract(lefta,leftb,righta,rightb,resulta,resultb) \ 3638c2ecf20Sopenharmony_ci if( Sextallp2(rightb) > Sextallp2(leftb) ) Sextallp1(lefta)--; \ 3648c2ecf20Sopenharmony_ci Sextallp2(resultb) = Sextallp2(leftb) - Sextallp2(rightb); \ 3658c2ecf20Sopenharmony_ci Sextallp1(resulta) = Sextallp1(lefta) - Sextallp1(righta) 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci#define Sglext_addition(lefta,leftb,righta,rightb,resulta,resultb) \ 3688c2ecf20Sopenharmony_ci /* If the sum of the low words is less than either source, then \ 3698c2ecf20Sopenharmony_ci * an overflow into the next word occurred. */ \ 3708c2ecf20Sopenharmony_ci if ((Sextallp2(resultb) = Sextallp2(leftb)+Sextallp2(rightb)) < \ 3718c2ecf20Sopenharmony_ci Sextallp2(rightb)) \ 3728c2ecf20Sopenharmony_ci Sextallp1(resulta) = Sextallp1(lefta)+Sextallp1(righta)+1; \ 3738c2ecf20Sopenharmony_ci else Sextallp1(resulta) = Sextallp1(lefta)+Sextallp1(righta) 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci#define Sglext_arithrightshiftby1(srcdstA,srcdstB) \ 3778c2ecf20Sopenharmony_ci Shiftdouble(Sextallp1(srcdstA),Sextallp2(srcdstB),1,Sextallp2(srcdstB)); \ 3788c2ecf20Sopenharmony_ci Sextallp1(srcdstA) = (int)Sextallp1(srcdstA) >> 1 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci#define Sglext_leftshiftby8(valA,valB) \ 3818c2ecf20Sopenharmony_ci Shiftdouble(Sextallp1(valA),Sextallp2(valB),24,Sextallp1(valA)); \ 3828c2ecf20Sopenharmony_ci Sextallp2(valB) <<= 8 3838c2ecf20Sopenharmony_ci#define Sglext_leftshiftby4(valA,valB) \ 3848c2ecf20Sopenharmony_ci Shiftdouble(Sextallp1(valA),Sextallp2(valB),28,Sextallp1(valA)); \ 3858c2ecf20Sopenharmony_ci Sextallp2(valB) <<= 4 3868c2ecf20Sopenharmony_ci#define Sglext_leftshiftby3(valA,valB) \ 3878c2ecf20Sopenharmony_ci Shiftdouble(Sextallp1(valA),Sextallp2(valB),29,Sextallp1(valA)); \ 3888c2ecf20Sopenharmony_ci Sextallp2(valB) <<= 3 3898c2ecf20Sopenharmony_ci#define Sglext_leftshiftby2(valA,valB) \ 3908c2ecf20Sopenharmony_ci Shiftdouble(Sextallp1(valA),Sextallp2(valB),30,Sextallp1(valA)); \ 3918c2ecf20Sopenharmony_ci Sextallp2(valB) <<= 2 3928c2ecf20Sopenharmony_ci#define Sglext_leftshiftby1(valA,valB) \ 3938c2ecf20Sopenharmony_ci Shiftdouble(Sextallp1(valA),Sextallp2(valB),31,Sextallp1(valA)); \ 3948c2ecf20Sopenharmony_ci Sextallp2(valB) <<= 1 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci#define Sglext_rightshiftby4(valueA,valueB) \ 3978c2ecf20Sopenharmony_ci Shiftdouble(Sextallp1(valueA),Sextallp2(valueB),4,Sextallp2(valueB)); \ 3988c2ecf20Sopenharmony_ci Sextallp1(valueA) >>= 4 3998c2ecf20Sopenharmony_ci#define Sglext_rightshiftby3(valueA,valueB) \ 4008c2ecf20Sopenharmony_ci Shiftdouble(Sextallp1(valueA),Sextallp2(valueB),3,Sextallp2(valueB)); \ 4018c2ecf20Sopenharmony_ci Sextallp1(valueA) >>= 3 4028c2ecf20Sopenharmony_ci#define Sglext_rightshiftby1(valueA,valueB) \ 4038c2ecf20Sopenharmony_ci Shiftdouble(Sextallp1(valueA),Sextallp2(valueB),1,Sextallp2(valueB)); \ 4048c2ecf20Sopenharmony_ci Sextallp1(valueA) >>= 1 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci#define Sglext_xortointp1(left,right,result) Sgl_xortointp1(left,right,result) 4078c2ecf20Sopenharmony_ci#define Sglext_xorfromintp1(left,right,result) \ 4088c2ecf20Sopenharmony_ci Sgl_xorfromintp1(left,right,result) 4098c2ecf20Sopenharmony_ci#define Sglext_copytoint_exponentmantissa(src,dest) \ 4108c2ecf20Sopenharmony_ci Sgl_copytoint_exponentmantissa(src,dest) 4118c2ecf20Sopenharmony_ci#define Sglext_ismagnitudeless(signlessleft,signlessright) \ 4128c2ecf20Sopenharmony_ci Sgl_ismagnitudeless(signlessleft,signlessright) 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci#define Sglext_set_sign(dbl_value,sign) Sgl_set_sign(dbl_value,sign) 4158c2ecf20Sopenharmony_ci#define Sglext_clear_signexponent_set_hidden(srcdst) \ 4168c2ecf20Sopenharmony_ci Sgl_clear_signexponent_set_hidden(srcdst) 4178c2ecf20Sopenharmony_ci#define Sglext_clear_signexponent(srcdst) Sgl_clear_signexponent(srcdst) 4188c2ecf20Sopenharmony_ci#define Sglext_clear_sign(srcdst) Sgl_clear_sign(srcdst) 4198c2ecf20Sopenharmony_ci#define Sglext_isone_hidden(dbl_value) Sgl_isone_hidden(dbl_value) 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci#define Sglext_denormalize(opndp1,opndp2,exponent,is_tiny) \ 4228c2ecf20Sopenharmony_ci {int sticky; \ 4238c2ecf20Sopenharmony_ci is_tiny = TRUE; \ 4248c2ecf20Sopenharmony_ci if (exponent == 0 && Sextallp2(opndp2)) { \ 4258c2ecf20Sopenharmony_ci switch (Rounding_mode()) { \ 4268c2ecf20Sopenharmony_ci case ROUNDPLUS: \ 4278c2ecf20Sopenharmony_ci if (Sgl_iszero_sign(opndp1)) \ 4288c2ecf20Sopenharmony_ci if (Sgl_isone_hiddenoverflow(opndp1 + 1)) \ 4298c2ecf20Sopenharmony_ci is_tiny = FALSE; \ 4308c2ecf20Sopenharmony_ci break; \ 4318c2ecf20Sopenharmony_ci case ROUNDMINUS: \ 4328c2ecf20Sopenharmony_ci if (Sgl_isone_sign(opndp1)) { \ 4338c2ecf20Sopenharmony_ci if (Sgl_isone_hiddenoverflow(opndp1 + 1)) \ 4348c2ecf20Sopenharmony_ci is_tiny = FALSE; \ 4358c2ecf20Sopenharmony_ci } \ 4368c2ecf20Sopenharmony_ci break; \ 4378c2ecf20Sopenharmony_ci case ROUNDNEAREST: \ 4388c2ecf20Sopenharmony_ci if (Sglext_isone_highp2(opndp2) && \ 4398c2ecf20Sopenharmony_ci (Sglext_isone_lowp1(opndp1) || \ 4408c2ecf20Sopenharmony_ci Sglext_isnotzero_low31p2(opndp2))) \ 4418c2ecf20Sopenharmony_ci if (Sgl_isone_hiddenoverflow(opndp1 + 1)) \ 4428c2ecf20Sopenharmony_ci is_tiny = FALSE; \ 4438c2ecf20Sopenharmony_ci break; \ 4448c2ecf20Sopenharmony_ci } \ 4458c2ecf20Sopenharmony_ci } \ 4468c2ecf20Sopenharmony_ci Sglext_clear_signexponent_set_hidden(opndp1); \ 4478c2ecf20Sopenharmony_ci if (exponent >= (1-DBL_P)) { \ 4488c2ecf20Sopenharmony_ci if (exponent >= -31) { \ 4498c2ecf20Sopenharmony_ci if (exponent > -31) { \ 4508c2ecf20Sopenharmony_ci sticky = Sextallp2(opndp2) << 31+exponent; \ 4518c2ecf20Sopenharmony_ci Variable_shift_double(opndp1,opndp2,1-exponent,opndp2); \ 4528c2ecf20Sopenharmony_ci Sextallp1(opndp1) >>= 1-exponent; \ 4538c2ecf20Sopenharmony_ci } \ 4548c2ecf20Sopenharmony_ci else { \ 4558c2ecf20Sopenharmony_ci sticky = Sextallp2(opndp2); \ 4568c2ecf20Sopenharmony_ci Sextallp2(opndp2) = Sextallp1(opndp1); \ 4578c2ecf20Sopenharmony_ci Sextallp1(opndp1) = 0; \ 4588c2ecf20Sopenharmony_ci } \ 4598c2ecf20Sopenharmony_ci } \ 4608c2ecf20Sopenharmony_ci else { \ 4618c2ecf20Sopenharmony_ci sticky = (Sextallp1(opndp1) << 31+exponent) | \ 4628c2ecf20Sopenharmony_ci Sextallp2(opndp2); \ 4638c2ecf20Sopenharmony_ci Sextallp2(opndp2) = Sextallp1(opndp1) >> -31-exponent; \ 4648c2ecf20Sopenharmony_ci Sextallp1(opndp1) = 0; \ 4658c2ecf20Sopenharmony_ci } \ 4668c2ecf20Sopenharmony_ci } \ 4678c2ecf20Sopenharmony_ci else { \ 4688c2ecf20Sopenharmony_ci sticky = Sextallp1(opndp1) | Sextallp2(opndp2); \ 4698c2ecf20Sopenharmony_ci Sglext_setzero(opndp1,opndp2); \ 4708c2ecf20Sopenharmony_ci } \ 4718c2ecf20Sopenharmony_ci if (sticky) Sglext_setone_lowmantissap2(opndp2); \ 4728c2ecf20Sopenharmony_ci exponent = 0; \ 4738c2ecf20Sopenharmony_ci } 474