1*0a6a1f1dSLionel Sambuc /* $NetBSD: softfloat.h,v 1.7 2014/09/01 07:33:31 matt Exp $ */ 22fe8fb19SBen Gras 32fe8fb19SBen Gras /* This is a derivative work. */ 42fe8fb19SBen Gras 52fe8fb19SBen Gras /* 62fe8fb19SBen Gras =============================================================================== 72fe8fb19SBen Gras 82fe8fb19SBen Gras This C header file is part of the SoftFloat IEC/IEEE Floating-point 92fe8fb19SBen Gras Arithmetic Package, Release 2a. 102fe8fb19SBen Gras 112fe8fb19SBen Gras Written by John R. Hauser. This work was made possible in part by the 122fe8fb19SBen Gras International Computer Science Institute, located at Suite 600, 1947 Center 132fe8fb19SBen Gras Street, Berkeley, California 94704. Funding was partially provided by the 142fe8fb19SBen Gras National Science Foundation under grant MIP-9311980. The original version 152fe8fb19SBen Gras of this code was written as part of a project to build a fixed-point vector 162fe8fb19SBen Gras processor in collaboration with the University of California at Berkeley, 172fe8fb19SBen Gras overseen by Profs. Nelson Morgan and John Wawrzynek. More information 182fe8fb19SBen Gras is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/ 192fe8fb19SBen Gras arithmetic/SoftFloat.html'. 202fe8fb19SBen Gras 212fe8fb19SBen Gras THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort 222fe8fb19SBen Gras has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT 232fe8fb19SBen Gras TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO 242fe8fb19SBen Gras PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY 252fe8fb19SBen Gras AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. 262fe8fb19SBen Gras 272fe8fb19SBen Gras Derivative works are acceptable, even for commercial purposes, so long as 282fe8fb19SBen Gras (1) they include prominent notice that the work is derivative, and (2) they 292fe8fb19SBen Gras include prominent notice akin to these four paragraphs for those parts of 302fe8fb19SBen Gras this code that are retained. 312fe8fb19SBen Gras 322fe8fb19SBen Gras =============================================================================== 332fe8fb19SBen Gras */ 342fe8fb19SBen Gras 352fe8fb19SBen Gras /* 362fe8fb19SBen Gras ------------------------------------------------------------------------------- 372fe8fb19SBen Gras The macro `FLOATX80' must be defined to enable the extended double-precision 382fe8fb19SBen Gras floating-point format `floatx80'. If this macro is not defined, the 392fe8fb19SBen Gras `floatx80' type will not be defined, and none of the functions that either 402fe8fb19SBen Gras input or output the `floatx80' type will be defined. The same applies to 412fe8fb19SBen Gras the `FLOAT128' macro and the quadruple-precision format `float128'. 422fe8fb19SBen Gras ------------------------------------------------------------------------------- 432fe8fb19SBen Gras */ 4484d9c625SLionel Sambuc #ifndef __mcoldfire__ 452fe8fb19SBen Gras #define FLOATX80 4684d9c625SLionel Sambuc #endif 472fe8fb19SBen Gras /* #define FLOAT128 */ 482fe8fb19SBen Gras 492fe8fb19SBen Gras #include <machine/ieeefp.h> 502fe8fb19SBen Gras 512fe8fb19SBen Gras /* 522fe8fb19SBen Gras ------------------------------------------------------------------------------- 532fe8fb19SBen Gras Software IEC/IEEE floating-point types. 542fe8fb19SBen Gras ------------------------------------------------------------------------------- 552fe8fb19SBen Gras */ 562fe8fb19SBen Gras typedef unsigned int float32; 572fe8fb19SBen Gras typedef unsigned long long float64; 582fe8fb19SBen Gras #ifdef FLOATX80 592fe8fb19SBen Gras typedef struct { 602fe8fb19SBen Gras unsigned short high; 612fe8fb19SBen Gras unsigned long long low; 622fe8fb19SBen Gras } floatx80; 632fe8fb19SBen Gras #endif 642fe8fb19SBen Gras #ifdef FLOAT128 652fe8fb19SBen Gras typedef struct { 662fe8fb19SBen Gras unsigned long long high, low; 672fe8fb19SBen Gras } float128; 682fe8fb19SBen Gras #endif 692fe8fb19SBen Gras 702fe8fb19SBen Gras /* 712fe8fb19SBen Gras ------------------------------------------------------------------------------- 722fe8fb19SBen Gras Software IEC/IEEE floating-point underflow tininess-detection mode. 732fe8fb19SBen Gras ------------------------------------------------------------------------------- 742fe8fb19SBen Gras */ 752fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC 762fe8fb19SBen Gras extern int8 float_detect_tininess; 772fe8fb19SBen Gras #endif 782fe8fb19SBen Gras enum { 792fe8fb19SBen Gras float_tininess_after_rounding = 0, 802fe8fb19SBen Gras float_tininess_before_rounding = 1 812fe8fb19SBen Gras }; 822fe8fb19SBen Gras 832fe8fb19SBen Gras /* 842fe8fb19SBen Gras ------------------------------------------------------------------------------- 852fe8fb19SBen Gras Software IEC/IEEE floating-point rounding mode. 862fe8fb19SBen Gras ------------------------------------------------------------------------------- 872fe8fb19SBen Gras */ 882fe8fb19SBen Gras extern fp_rnd float_rounding_mode; 89e415d488SLionel Sambuc #define float_round_nearest_even FP_RN 90e415d488SLionel Sambuc #define float_round_to_zero FP_RZ 91e415d488SLionel Sambuc #define float_round_down FP_RM 92e415d488SLionel Sambuc #define float_round_up FP_RP 932fe8fb19SBen Gras 942fe8fb19SBen Gras /* 952fe8fb19SBen Gras ------------------------------------------------------------------------------- 962fe8fb19SBen Gras Software IEC/IEEE floating-point exception flags. 972fe8fb19SBen Gras ------------------------------------------------------------------------------- 982fe8fb19SBen Gras */ 992fe8fb19SBen Gras extern fp_except float_exception_flags; 1002fe8fb19SBen Gras extern fp_except float_exception_mask; 1012fe8fb19SBen Gras enum { 1022fe8fb19SBen Gras float_flag_inexact = FP_X_IMP, 1032fe8fb19SBen Gras float_flag_underflow = FP_X_UFL, 1042fe8fb19SBen Gras float_flag_overflow = FP_X_OFL, 1052fe8fb19SBen Gras float_flag_divbyzero = FP_X_DZ, 1062fe8fb19SBen Gras float_flag_invalid = FP_X_INV 1072fe8fb19SBen Gras }; 1082fe8fb19SBen Gras 1092fe8fb19SBen Gras /* 1102fe8fb19SBen Gras ------------------------------------------------------------------------------- 1112fe8fb19SBen Gras Routine to raise any or all of the software IEC/IEEE floating-point 1122fe8fb19SBen Gras exception flags. 1132fe8fb19SBen Gras ------------------------------------------------------------------------------- 1142fe8fb19SBen Gras */ 1152fe8fb19SBen Gras void float_raise( fp_except ); 1162fe8fb19SBen Gras 1172fe8fb19SBen Gras /* 1182fe8fb19SBen Gras ------------------------------------------------------------------------------- 1192fe8fb19SBen Gras Software IEC/IEEE integer-to-floating-point conversion routines. 1202fe8fb19SBen Gras ------------------------------------------------------------------------------- 1212fe8fb19SBen Gras */ 122e415d488SLionel Sambuc float32 int32_to_float32( int32 ); 123e415d488SLionel Sambuc float32 uint32_to_float32( uint32 ); 124e415d488SLionel Sambuc float64 int32_to_float64( int32 ); 125e415d488SLionel Sambuc float64 uint32_to_float64( uint32 ); 1262fe8fb19SBen Gras #ifdef FLOATX80 127e415d488SLionel Sambuc floatx80 int32_to_floatx80( int32 ); 128e415d488SLionel Sambuc floatx80 uint32_to_floatx80( uint32 ); 1292fe8fb19SBen Gras #endif 1302fe8fb19SBen Gras #ifdef FLOAT128 131e415d488SLionel Sambuc float128 int32_to_float128( int32 ); 132e415d488SLionel Sambuc float128 uint32_to_float128( uint32 ); 1332fe8fb19SBen Gras #endif 1342fe8fb19SBen Gras float32 int64_to_float32( long long ); 1352fe8fb19SBen Gras float64 int64_to_float64( long long ); 1362fe8fb19SBen Gras #ifdef FLOATX80 1372fe8fb19SBen Gras floatx80 int64_to_floatx80( long long ); 1382fe8fb19SBen Gras #endif 1392fe8fb19SBen Gras #ifdef FLOAT128 1402fe8fb19SBen Gras float128 int64_to_float128( long long ); 1412fe8fb19SBen Gras #endif 1422fe8fb19SBen Gras 1432fe8fb19SBen Gras /* 1442fe8fb19SBen Gras ------------------------------------------------------------------------------- 1452fe8fb19SBen Gras Software IEC/IEEE single-precision conversion routines. 1462fe8fb19SBen Gras ------------------------------------------------------------------------------- 1472fe8fb19SBen Gras */ 1482fe8fb19SBen Gras int float32_to_int32( float32 ); 1492fe8fb19SBen Gras int float32_to_int32_round_to_zero( float32 ); 1502fe8fb19SBen Gras unsigned int float32_to_uint32_round_to_zero( float32 ); 1512fe8fb19SBen Gras long long float32_to_int64( float32 ); 1522fe8fb19SBen Gras long long float32_to_int64_round_to_zero( float32 ); 1532fe8fb19SBen Gras float64 float32_to_float64( float32 ); 1542fe8fb19SBen Gras #ifdef FLOATX80 1552fe8fb19SBen Gras floatx80 float32_to_floatx80( float32 ); 1562fe8fb19SBen Gras #endif 1572fe8fb19SBen Gras #ifdef FLOAT128 1582fe8fb19SBen Gras float128 float32_to_float128( float32 ); 1592fe8fb19SBen Gras #endif 1602fe8fb19SBen Gras 1612fe8fb19SBen Gras /* 1622fe8fb19SBen Gras ------------------------------------------------------------------------------- 1632fe8fb19SBen Gras Software IEC/IEEE single-precision operations. 1642fe8fb19SBen Gras ------------------------------------------------------------------------------- 1652fe8fb19SBen Gras */ 1662fe8fb19SBen Gras float32 float32_round_to_int( float32 ); 1672fe8fb19SBen Gras float32 float32_add( float32, float32 ); 1682fe8fb19SBen Gras float32 float32_sub( float32, float32 ); 1692fe8fb19SBen Gras float32 float32_mul( float32, float32 ); 1702fe8fb19SBen Gras float32 float32_div( float32, float32 ); 1712fe8fb19SBen Gras float32 float32_rem( float32, float32 ); 1722fe8fb19SBen Gras float32 float32_sqrt( float32 ); 1732fe8fb19SBen Gras flag float32_eq( float32, float32 ); 1742fe8fb19SBen Gras flag float32_le( float32, float32 ); 1752fe8fb19SBen Gras flag float32_lt( float32, float32 ); 1762fe8fb19SBen Gras flag float32_eq_signaling( float32, float32 ); 1772fe8fb19SBen Gras flag float32_le_quiet( float32, float32 ); 1782fe8fb19SBen Gras flag float32_lt_quiet( float32, float32 ); 179*0a6a1f1dSLionel Sambuc #if !defined(SOFTFLOAT_FOR_GCC) || defined(SOFTFLOATM68K_FOR_GCC) 1802fe8fb19SBen Gras flag float32_is_signaling_nan( float32 ); 1812fe8fb19SBen Gras #endif 1822fe8fb19SBen Gras 1832fe8fb19SBen Gras /* 1842fe8fb19SBen Gras ------------------------------------------------------------------------------- 1852fe8fb19SBen Gras Software IEC/IEEE double-precision conversion routines. 1862fe8fb19SBen Gras ------------------------------------------------------------------------------- 1872fe8fb19SBen Gras */ 1882fe8fb19SBen Gras int float64_to_int32( float64 ); 1892fe8fb19SBen Gras int float64_to_int32_round_to_zero( float64 ); 1902fe8fb19SBen Gras unsigned int float64_to_uint32_round_to_zero( float64 ); 1912fe8fb19SBen Gras long long float64_to_int64( float64 ); 1922fe8fb19SBen Gras long long float64_to_int64_round_to_zero( float64 ); 1932fe8fb19SBen Gras float32 float64_to_float32( float64 ); 1942fe8fb19SBen Gras #ifdef FLOATX80 1952fe8fb19SBen Gras floatx80 float64_to_floatx80( float64 ); 1962fe8fb19SBen Gras #endif 1972fe8fb19SBen Gras #ifdef FLOAT128 1982fe8fb19SBen Gras float128 float64_to_float128( float64 ); 1992fe8fb19SBen Gras #endif 2002fe8fb19SBen Gras 2012fe8fb19SBen Gras /* 2022fe8fb19SBen Gras ------------------------------------------------------------------------------- 2032fe8fb19SBen Gras Software IEC/IEEE double-precision operations. 2042fe8fb19SBen Gras ------------------------------------------------------------------------------- 2052fe8fb19SBen Gras */ 2062fe8fb19SBen Gras float64 float64_round_to_int( float64 ); 2072fe8fb19SBen Gras float64 float64_add( float64, float64 ); 2082fe8fb19SBen Gras float64 float64_sub( float64, float64 ); 2092fe8fb19SBen Gras float64 float64_mul( float64, float64 ); 2102fe8fb19SBen Gras float64 float64_div( float64, float64 ); 2112fe8fb19SBen Gras float64 float64_rem( float64, float64 ); 2122fe8fb19SBen Gras float64 float64_sqrt( float64 ); 2132fe8fb19SBen Gras flag float64_eq( float64, float64 ); 2142fe8fb19SBen Gras flag float64_le( float64, float64 ); 2152fe8fb19SBen Gras flag float64_lt( float64, float64 ); 2162fe8fb19SBen Gras flag float64_eq_signaling( float64, float64 ); 2172fe8fb19SBen Gras flag float64_le_quiet( float64, float64 ); 2182fe8fb19SBen Gras flag float64_lt_quiet( float64, float64 ); 2192fe8fb19SBen Gras flag float64_is_signaling_nan( float64 ); 2202fe8fb19SBen Gras 2212fe8fb19SBen Gras #ifdef FLOATX80 2222fe8fb19SBen Gras 2232fe8fb19SBen Gras /* 2242fe8fb19SBen Gras ------------------------------------------------------------------------------- 2252fe8fb19SBen Gras Software IEC/IEEE extended double-precision conversion routines. 2262fe8fb19SBen Gras ------------------------------------------------------------------------------- 2272fe8fb19SBen Gras */ 2282fe8fb19SBen Gras int floatx80_to_int32( floatx80 ); 2292fe8fb19SBen Gras int floatx80_to_int32_round_to_zero( floatx80 ); 2302fe8fb19SBen Gras long long floatx80_to_int64( floatx80 ); 2312fe8fb19SBen Gras long long floatx80_to_int64_round_to_zero( floatx80 ); 2322fe8fb19SBen Gras float32 floatx80_to_float32( floatx80 ); 2332fe8fb19SBen Gras float64 floatx80_to_float64( floatx80 ); 2342fe8fb19SBen Gras #ifdef FLOAT128 2352fe8fb19SBen Gras float128 floatx80_to_float128( floatx80 ); 2362fe8fb19SBen Gras #endif 2372fe8fb19SBen Gras 2382fe8fb19SBen Gras /* 2392fe8fb19SBen Gras ------------------------------------------------------------------------------- 2402fe8fb19SBen Gras Software IEC/IEEE extended double-precision rounding precision. Valid 2412fe8fb19SBen Gras values are 32, 64, and 80. 2422fe8fb19SBen Gras ------------------------------------------------------------------------------- 2432fe8fb19SBen Gras */ 2442fe8fb19SBen Gras extern int floatx80_rounding_precision; 2452fe8fb19SBen Gras 2462fe8fb19SBen Gras /* 2472fe8fb19SBen Gras ------------------------------------------------------------------------------- 2482fe8fb19SBen Gras Software IEC/IEEE extended double-precision operations. 2492fe8fb19SBen Gras ------------------------------------------------------------------------------- 2502fe8fb19SBen Gras */ 2512fe8fb19SBen Gras floatx80 floatx80_round_to_int( floatx80 ); 2522fe8fb19SBen Gras floatx80 floatx80_add( floatx80, floatx80 ); 2532fe8fb19SBen Gras floatx80 floatx80_sub( floatx80, floatx80 ); 2542fe8fb19SBen Gras floatx80 floatx80_mul( floatx80, floatx80 ); 2552fe8fb19SBen Gras floatx80 floatx80_div( floatx80, floatx80 ); 2562fe8fb19SBen Gras floatx80 floatx80_rem( floatx80, floatx80 ); 2572fe8fb19SBen Gras floatx80 floatx80_sqrt( floatx80 ); 2582fe8fb19SBen Gras flag floatx80_eq( floatx80, floatx80 ); 2592fe8fb19SBen Gras flag floatx80_le( floatx80, floatx80 ); 2602fe8fb19SBen Gras flag floatx80_lt( floatx80, floatx80 ); 2612fe8fb19SBen Gras flag floatx80_eq_signaling( floatx80, floatx80 ); 2622fe8fb19SBen Gras flag floatx80_le_quiet( floatx80, floatx80 ); 2632fe8fb19SBen Gras flag floatx80_lt_quiet( floatx80, floatx80 ); 2642fe8fb19SBen Gras flag floatx80_is_signaling_nan( floatx80 ); 2652fe8fb19SBen Gras flag floatx80_is_nan( floatx80 ); 2662fe8fb19SBen Gras 2672fe8fb19SBen Gras #endif 2682fe8fb19SBen Gras 2692fe8fb19SBen Gras #ifdef FLOAT128 2702fe8fb19SBen Gras 2712fe8fb19SBen Gras /* 2722fe8fb19SBen Gras ------------------------------------------------------------------------------- 2732fe8fb19SBen Gras Software IEC/IEEE quadruple-precision conversion routines. 2742fe8fb19SBen Gras ------------------------------------------------------------------------------- 2752fe8fb19SBen Gras */ 2762fe8fb19SBen Gras int float128_to_int32( float128 ); 2772fe8fb19SBen Gras int float128_to_int32_round_to_zero( float128 ); 2782fe8fb19SBen Gras long long float128_to_int64( float128 ); 2792fe8fb19SBen Gras long long float128_to_int64_round_to_zero( float128 ); 2802fe8fb19SBen Gras float32 float128_to_float32( float128 ); 2812fe8fb19SBen Gras float64 float128_to_float64( float128 ); 2822fe8fb19SBen Gras #ifdef FLOATX80 2832fe8fb19SBen Gras floatx80 float128_to_floatx80( float128 ); 2842fe8fb19SBen Gras #endif 2852fe8fb19SBen Gras 2862fe8fb19SBen Gras /* 2872fe8fb19SBen Gras ------------------------------------------------------------------------------- 2882fe8fb19SBen Gras Software IEC/IEEE quadruple-precision operations. 2892fe8fb19SBen Gras ------------------------------------------------------------------------------- 2902fe8fb19SBen Gras */ 2912fe8fb19SBen Gras float128 float128_round_to_int( float128 ); 2922fe8fb19SBen Gras float128 float128_add( float128, float128 ); 2932fe8fb19SBen Gras float128 float128_sub( float128, float128 ); 2942fe8fb19SBen Gras float128 float128_mul( float128, float128 ); 2952fe8fb19SBen Gras float128 float128_div( float128, float128 ); 2962fe8fb19SBen Gras float128 float128_rem( float128, float128 ); 2972fe8fb19SBen Gras float128 float128_sqrt( float128 ); 2982fe8fb19SBen Gras flag float128_eq( float128, float128 ); 2992fe8fb19SBen Gras flag float128_le( float128, float128 ); 3002fe8fb19SBen Gras flag float128_lt( float128, float128 ); 3012fe8fb19SBen Gras flag float128_eq_signaling( float128, float128 ); 3022fe8fb19SBen Gras flag float128_le_quiet( float128, float128 ); 3032fe8fb19SBen Gras flag float128_lt_quiet( float128, float128 ); 3042fe8fb19SBen Gras flag float128_is_signaling_nan( float128 ); 3052fe8fb19SBen Gras 3062fe8fb19SBen Gras #endif 307