18c2ecf20Sopenharmony_ci 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci=============================================================================== 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciThis C header file is part of the SoftFloat IEC/IEEE Floating-point 68c2ecf20Sopenharmony_ciArithmetic Package, Release 2. 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciWritten by John R. Hauser. This work was made possible in part by the 98c2ecf20Sopenharmony_ciInternational Computer Science Institute, located at Suite 600, 1947 Center 108c2ecf20Sopenharmony_ciStreet, Berkeley, California 94704. Funding was partially provided by the 118c2ecf20Sopenharmony_ciNational Science Foundation under grant MIP-9311980. The original version 128c2ecf20Sopenharmony_ciof this code was written as part of a project to build a fixed-point vector 138c2ecf20Sopenharmony_ciprocessor in collaboration with the University of California at Berkeley, 148c2ecf20Sopenharmony_cioverseen by Profs. Nelson Morgan and John Wawrzynek. More information 158c2ecf20Sopenharmony_ciis available through the Web page 168c2ecf20Sopenharmony_cihttp://www.jhauser.us/arithmetic/SoftFloat-2b/SoftFloat-source.txt 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ciTHIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort 198c2ecf20Sopenharmony_cihas been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT 208c2ecf20Sopenharmony_ciTIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO 218c2ecf20Sopenharmony_ciPERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY 228c2ecf20Sopenharmony_ciAND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ciDerivative works are acceptable, even for commercial purposes, so long as 258c2ecf20Sopenharmony_ci(1) they include prominent notice that the work is derivative, and (2) they 268c2ecf20Sopenharmony_ciinclude prominent notice akin to these three paragraphs for those parts of 278c2ecf20Sopenharmony_cithis code that are retained. 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci=============================================================================== 308c2ecf20Sopenharmony_ci*/ 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#ifndef __SOFTFLOAT_H__ 338c2ecf20Sopenharmony_ci#define __SOFTFLOAT_H__ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci/* 378c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 388c2ecf20Sopenharmony_ciThe macro `FLOATX80' must be defined to enable the extended double-precision 398c2ecf20Sopenharmony_cifloating-point format `floatx80'. If this macro is not defined, the 408c2ecf20Sopenharmony_ci`floatx80' type will not be defined, and none of the functions that either 418c2ecf20Sopenharmony_ciinput or output the `floatx80' type will be defined. 428c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 438c2ecf20Sopenharmony_ci*/ 448c2ecf20Sopenharmony_ci#ifdef CONFIG_FPE_NWFPE_XP 458c2ecf20Sopenharmony_ci#define FLOATX80 468c2ecf20Sopenharmony_ci#endif 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* 498c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 508c2ecf20Sopenharmony_ciSoftware IEC/IEEE floating-point types. 518c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 528c2ecf20Sopenharmony_ci*/ 538c2ecf20Sopenharmony_citypedef u32 float32; 548c2ecf20Sopenharmony_citypedef u64 float64; 558c2ecf20Sopenharmony_citypedef struct { 568c2ecf20Sopenharmony_ci#ifdef __ARMEB__ 578c2ecf20Sopenharmony_ci u16 __padding; 588c2ecf20Sopenharmony_ci u16 high; 598c2ecf20Sopenharmony_ci#else 608c2ecf20Sopenharmony_ci u16 high; 618c2ecf20Sopenharmony_ci u16 __padding; 628c2ecf20Sopenharmony_ci#endif 638c2ecf20Sopenharmony_ci u64 low; 648c2ecf20Sopenharmony_ci} __attribute__ ((packed,aligned(4))) floatx80; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* 678c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 688c2ecf20Sopenharmony_ciSoftware IEC/IEEE floating-point underflow tininess-detection mode. 698c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 708c2ecf20Sopenharmony_ci*/ 718c2ecf20Sopenharmony_ciextern signed char float_detect_tininess; 728c2ecf20Sopenharmony_cienum { 738c2ecf20Sopenharmony_ci float_tininess_after_rounding = 0, 748c2ecf20Sopenharmony_ci float_tininess_before_rounding = 1 758c2ecf20Sopenharmony_ci}; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* 788c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 798c2ecf20Sopenharmony_ciSoftware IEC/IEEE floating-point rounding mode. 808c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 818c2ecf20Sopenharmony_ci*/ 828c2ecf20Sopenharmony_ci//extern int8 float_rounding_mode; 838c2ecf20Sopenharmony_cienum { 848c2ecf20Sopenharmony_ci float_round_nearest_even = 0, 858c2ecf20Sopenharmony_ci float_round_to_zero = 1, 868c2ecf20Sopenharmony_ci float_round_down = 2, 878c2ecf20Sopenharmony_ci float_round_up = 3 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci/* 918c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 928c2ecf20Sopenharmony_ciSoftware IEC/IEEE floating-point exception flags. 938c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 948c2ecf20Sopenharmony_cienum { 958c2ecf20Sopenharmony_ci float_flag_inexact = 1, 968c2ecf20Sopenharmony_ci float_flag_underflow = 2, 978c2ecf20Sopenharmony_ci float_flag_overflow = 4, 988c2ecf20Sopenharmony_ci float_flag_divbyzero = 8, 998c2ecf20Sopenharmony_ci float_flag_invalid = 16 1008c2ecf20Sopenharmony_ci}; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ciScottB: November 4, 1998 1038c2ecf20Sopenharmony_ciChanged the enumeration to match the bit order in the FPA11. 1048c2ecf20Sopenharmony_ci*/ 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cienum { 1078c2ecf20Sopenharmony_ci float_flag_invalid = 1, 1088c2ecf20Sopenharmony_ci float_flag_divbyzero = 2, 1098c2ecf20Sopenharmony_ci float_flag_overflow = 4, 1108c2ecf20Sopenharmony_ci float_flag_underflow = 8, 1118c2ecf20Sopenharmony_ci float_flag_inexact = 16 1128c2ecf20Sopenharmony_ci}; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci/* 1158c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 1168c2ecf20Sopenharmony_ciRoutine to raise any or all of the software IEC/IEEE floating-point 1178c2ecf20Sopenharmony_ciexception flags. 1188c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 1198c2ecf20Sopenharmony_ci*/ 1208c2ecf20Sopenharmony_civoid float_raise( signed char ); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/* 1238c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 1248c2ecf20Sopenharmony_ciSoftware IEC/IEEE integer-to-floating-point conversion routines. 1258c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 1268c2ecf20Sopenharmony_ci*/ 1278c2ecf20Sopenharmony_cifloat32 int32_to_float32( struct roundingData *, signed int ); 1288c2ecf20Sopenharmony_cifloat64 int32_to_float64( signed int ); 1298c2ecf20Sopenharmony_ci#ifdef FLOATX80 1308c2ecf20Sopenharmony_cifloatx80 int32_to_floatx80( signed int ); 1318c2ecf20Sopenharmony_ci#endif 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci/* 1348c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 1358c2ecf20Sopenharmony_ciSoftware IEC/IEEE single-precision conversion routines. 1368c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 1378c2ecf20Sopenharmony_ci*/ 1388c2ecf20Sopenharmony_cisigned int float32_to_int32( struct roundingData *, float32 ); 1398c2ecf20Sopenharmony_cisigned int float32_to_int32_round_to_zero( float32 ); 1408c2ecf20Sopenharmony_cifloat64 float32_to_float64( float32 ); 1418c2ecf20Sopenharmony_ci#ifdef FLOATX80 1428c2ecf20Sopenharmony_cifloatx80 float32_to_floatx80( float32 ); 1438c2ecf20Sopenharmony_ci#endif 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci/* 1468c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 1478c2ecf20Sopenharmony_ciSoftware IEC/IEEE single-precision operations. 1488c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 1498c2ecf20Sopenharmony_ci*/ 1508c2ecf20Sopenharmony_cifloat32 float32_round_to_int( struct roundingData*, float32 ); 1518c2ecf20Sopenharmony_cifloat32 float32_add( struct roundingData *, float32, float32 ); 1528c2ecf20Sopenharmony_cifloat32 float32_sub( struct roundingData *, float32, float32 ); 1538c2ecf20Sopenharmony_cifloat32 float32_mul( struct roundingData *, float32, float32 ); 1548c2ecf20Sopenharmony_cifloat32 float32_div( struct roundingData *, float32, float32 ); 1558c2ecf20Sopenharmony_cifloat32 float32_rem( struct roundingData *, float32, float32 ); 1568c2ecf20Sopenharmony_cifloat32 float32_sqrt( struct roundingData*, float32 ); 1578c2ecf20Sopenharmony_cichar float32_eq( float32, float32 ); 1588c2ecf20Sopenharmony_cichar float32_le( float32, float32 ); 1598c2ecf20Sopenharmony_cichar float32_lt( float32, float32 ); 1608c2ecf20Sopenharmony_cichar float32_eq_signaling( float32, float32 ); 1618c2ecf20Sopenharmony_cichar float32_le_quiet( float32, float32 ); 1628c2ecf20Sopenharmony_cichar float32_lt_quiet( float32, float32 ); 1638c2ecf20Sopenharmony_cichar float32_is_signaling_nan( float32 ); 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci/* 1668c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 1678c2ecf20Sopenharmony_ciSoftware IEC/IEEE double-precision conversion routines. 1688c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 1698c2ecf20Sopenharmony_ci*/ 1708c2ecf20Sopenharmony_cisigned int float64_to_int32( struct roundingData *, float64 ); 1718c2ecf20Sopenharmony_cisigned int float64_to_int32_round_to_zero( float64 ); 1728c2ecf20Sopenharmony_cifloat32 float64_to_float32( struct roundingData *, float64 ); 1738c2ecf20Sopenharmony_ci#ifdef FLOATX80 1748c2ecf20Sopenharmony_cifloatx80 float64_to_floatx80( float64 ); 1758c2ecf20Sopenharmony_ci#endif 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci/* 1788c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 1798c2ecf20Sopenharmony_ciSoftware IEC/IEEE double-precision operations. 1808c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 1818c2ecf20Sopenharmony_ci*/ 1828c2ecf20Sopenharmony_cifloat64 float64_round_to_int( struct roundingData *, float64 ); 1838c2ecf20Sopenharmony_cifloat64 float64_add( struct roundingData *, float64, float64 ); 1848c2ecf20Sopenharmony_cifloat64 float64_sub( struct roundingData *, float64, float64 ); 1858c2ecf20Sopenharmony_cifloat64 float64_mul( struct roundingData *, float64, float64 ); 1868c2ecf20Sopenharmony_cifloat64 float64_div( struct roundingData *, float64, float64 ); 1878c2ecf20Sopenharmony_cifloat64 float64_rem( struct roundingData *, float64, float64 ); 1888c2ecf20Sopenharmony_cifloat64 float64_sqrt( struct roundingData *, float64 ); 1898c2ecf20Sopenharmony_cichar float64_eq( float64, float64 ); 1908c2ecf20Sopenharmony_cichar float64_le( float64, float64 ); 1918c2ecf20Sopenharmony_cichar float64_lt( float64, float64 ); 1928c2ecf20Sopenharmony_cichar float64_eq_signaling( float64, float64 ); 1938c2ecf20Sopenharmony_cichar float64_le_quiet( float64, float64 ); 1948c2ecf20Sopenharmony_cichar float64_lt_quiet( float64, float64 ); 1958c2ecf20Sopenharmony_cichar float64_is_signaling_nan( float64 ); 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci#ifdef FLOATX80 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci/* 2008c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 2018c2ecf20Sopenharmony_ciSoftware IEC/IEEE extended double-precision conversion routines. 2028c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 2038c2ecf20Sopenharmony_ci*/ 2048c2ecf20Sopenharmony_cisigned int floatx80_to_int32( struct roundingData *, floatx80 ); 2058c2ecf20Sopenharmony_cisigned int floatx80_to_int32_round_to_zero( floatx80 ); 2068c2ecf20Sopenharmony_cifloat32 floatx80_to_float32( struct roundingData *, floatx80 ); 2078c2ecf20Sopenharmony_cifloat64 floatx80_to_float64( struct roundingData *, floatx80 ); 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci/* 2108c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 2118c2ecf20Sopenharmony_ciSoftware IEC/IEEE extended double-precision operations. 2128c2ecf20Sopenharmony_ci------------------------------------------------------------------------------- 2138c2ecf20Sopenharmony_ci*/ 2148c2ecf20Sopenharmony_cifloatx80 floatx80_round_to_int( struct roundingData *, floatx80 ); 2158c2ecf20Sopenharmony_cifloatx80 floatx80_add( struct roundingData *, floatx80, floatx80 ); 2168c2ecf20Sopenharmony_cifloatx80 floatx80_sub( struct roundingData *, floatx80, floatx80 ); 2178c2ecf20Sopenharmony_cifloatx80 floatx80_mul( struct roundingData *, floatx80, floatx80 ); 2188c2ecf20Sopenharmony_cifloatx80 floatx80_div( struct roundingData *, floatx80, floatx80 ); 2198c2ecf20Sopenharmony_cifloatx80 floatx80_rem( struct roundingData *, floatx80, floatx80 ); 2208c2ecf20Sopenharmony_cifloatx80 floatx80_sqrt( struct roundingData *, floatx80 ); 2218c2ecf20Sopenharmony_cichar floatx80_eq( floatx80, floatx80 ); 2228c2ecf20Sopenharmony_cichar floatx80_le( floatx80, floatx80 ); 2238c2ecf20Sopenharmony_cichar floatx80_lt( floatx80, floatx80 ); 2248c2ecf20Sopenharmony_cichar floatx80_eq_signaling( floatx80, floatx80 ); 2258c2ecf20Sopenharmony_cichar floatx80_le_quiet( floatx80, floatx80 ); 2268c2ecf20Sopenharmony_cichar floatx80_lt_quiet( floatx80, floatx80 ); 2278c2ecf20Sopenharmony_cichar floatx80_is_signaling_nan( floatx80 ); 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ciextern flag floatx80_is_nan(floatx80); 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci#endif 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_cistatic inline flag extractFloat32Sign(float32 a) 2348c2ecf20Sopenharmony_ci{ 2358c2ecf20Sopenharmony_ci return a >> 31; 2368c2ecf20Sopenharmony_ci} 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_cistatic inline flag float32_eq_nocheck(float32 a, float32 b) 2398c2ecf20Sopenharmony_ci{ 2408c2ecf20Sopenharmony_ci return (a == b) || ((bits32) ((a | b) << 1) == 0); 2418c2ecf20Sopenharmony_ci} 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_cistatic inline flag float32_lt_nocheck(float32 a, float32 b) 2448c2ecf20Sopenharmony_ci{ 2458c2ecf20Sopenharmony_ci flag aSign, bSign; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci aSign = extractFloat32Sign(a); 2488c2ecf20Sopenharmony_ci bSign = extractFloat32Sign(b); 2498c2ecf20Sopenharmony_ci if (aSign != bSign) 2508c2ecf20Sopenharmony_ci return aSign && ((bits32) ((a | b) << 1) != 0); 2518c2ecf20Sopenharmony_ci return (a != b) && (aSign ^ (a < b)); 2528c2ecf20Sopenharmony_ci} 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_cistatic inline flag extractFloat64Sign(float64 a) 2558c2ecf20Sopenharmony_ci{ 2568c2ecf20Sopenharmony_ci return a >> 63; 2578c2ecf20Sopenharmony_ci} 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_cistatic inline flag float64_eq_nocheck(float64 a, float64 b) 2608c2ecf20Sopenharmony_ci{ 2618c2ecf20Sopenharmony_ci return (a == b) || ((bits64) ((a | b) << 1) == 0); 2628c2ecf20Sopenharmony_ci} 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_cistatic inline flag float64_lt_nocheck(float64 a, float64 b) 2658c2ecf20Sopenharmony_ci{ 2668c2ecf20Sopenharmony_ci flag aSign, bSign; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci aSign = extractFloat64Sign(a); 2698c2ecf20Sopenharmony_ci bSign = extractFloat64Sign(b); 2708c2ecf20Sopenharmony_ci if (aSign != bSign) 2718c2ecf20Sopenharmony_ci return aSign && ((bits64) ((a | b) << 1) != 0); 2728c2ecf20Sopenharmony_ci return (a != b) && (aSign ^ (a < b)); 2738c2ecf20Sopenharmony_ci} 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ciextern flag float32_is_nan( float32 a ); 2768c2ecf20Sopenharmony_ciextern flag float64_is_nan( float64 a ); 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ciextern int32 float64_to_uint32( struct roundingData *roundData, float64 a ); 2798c2ecf20Sopenharmony_ciextern int32 float64_to_uint32_round_to_zero( float64 a ); 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci#endif 282