1*84d9c625SLionel Sambuc /* $NetBSD: softfloat.h,v 1.10 2013/04/24 18:04:46 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 */ 442fe8fb19SBen Gras /* #define FLOATX80 */ 452fe8fb19SBen Gras /* #define FLOAT128 */ 462fe8fb19SBen Gras 47*84d9c625SLionel Sambuc #include <stdint.h> 482fe8fb19SBen Gras #include <machine/ieeefp.h> 492fe8fb19SBen Gras 502fe8fb19SBen Gras /* 512fe8fb19SBen Gras ------------------------------------------------------------------------------- 522fe8fb19SBen Gras Software IEC/IEEE floating-point types. 532fe8fb19SBen Gras ------------------------------------------------------------------------------- 542fe8fb19SBen Gras */ 552fe8fb19SBen Gras typedef unsigned int float32; 562fe8fb19SBen Gras typedef unsigned long long float64; 572fe8fb19SBen Gras #ifdef FLOATX80 582fe8fb19SBen Gras typedef struct { 592fe8fb19SBen Gras unsigned short high; 602fe8fb19SBen Gras unsigned long long low; 612fe8fb19SBen Gras } floatx80; 622fe8fb19SBen Gras #endif 632fe8fb19SBen Gras #ifdef FLOAT128 642fe8fb19SBen Gras typedef struct { 652fe8fb19SBen Gras unsigned long long high, low; 662fe8fb19SBen Gras } float128; 672fe8fb19SBen Gras #endif 682fe8fb19SBen Gras 692fe8fb19SBen Gras /* 702fe8fb19SBen Gras ------------------------------------------------------------------------------- 712fe8fb19SBen Gras Software IEC/IEEE floating-point underflow tininess-detection mode. 722fe8fb19SBen Gras ------------------------------------------------------------------------------- 732fe8fb19SBen Gras */ 742fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC 752fe8fb19SBen Gras extern int float_detect_tininess; 762fe8fb19SBen Gras #endif 772fe8fb19SBen Gras enum { 782fe8fb19SBen Gras float_tininess_after_rounding = 0, 792fe8fb19SBen Gras float_tininess_before_rounding = 1 802fe8fb19SBen Gras }; 812fe8fb19SBen Gras 822fe8fb19SBen Gras /* 832fe8fb19SBen Gras ------------------------------------------------------------------------------- 842fe8fb19SBen Gras Software IEC/IEEE floating-point rounding mode. 852fe8fb19SBen Gras ------------------------------------------------------------------------------- 862fe8fb19SBen Gras */ 872fe8fb19SBen Gras extern fp_rnd float_rounding_mode; 88f14fb602SLionel Sambuc #define float_round_nearest_even FP_RN 89f14fb602SLionel Sambuc #define float_round_to_zero FP_RZ 90f14fb602SLionel Sambuc #define float_round_down FP_RM 91f14fb602SLionel Sambuc #define float_round_up FP_RP 922fe8fb19SBen Gras 932fe8fb19SBen Gras /* 942fe8fb19SBen Gras ------------------------------------------------------------------------------- 952fe8fb19SBen Gras Software IEC/IEEE floating-point exception flags. 962fe8fb19SBen Gras ------------------------------------------------------------------------------- 972fe8fb19SBen Gras */ 982fe8fb19SBen Gras extern fp_except float_exception_flags; 992fe8fb19SBen Gras extern fp_except float_exception_mask; 1002fe8fb19SBen Gras enum { 1012fe8fb19SBen Gras float_flag_inexact = FP_X_IMP, 1022fe8fb19SBen Gras float_flag_underflow = FP_X_UFL, 1032fe8fb19SBen Gras float_flag_overflow = FP_X_OFL, 1042fe8fb19SBen Gras float_flag_divbyzero = FP_X_DZ, 1052fe8fb19SBen Gras float_flag_invalid = FP_X_INV 1062fe8fb19SBen Gras }; 1072fe8fb19SBen Gras 1082fe8fb19SBen Gras /* 1092fe8fb19SBen Gras ------------------------------------------------------------------------------- 1102fe8fb19SBen Gras Routine to raise any or all of the software IEC/IEEE floating-point 1112fe8fb19SBen Gras exception flags. 1122fe8fb19SBen Gras ------------------------------------------------------------------------------- 1132fe8fb19SBen Gras */ 1142fe8fb19SBen Gras void float_raise( fp_except ); 1152fe8fb19SBen Gras 1162fe8fb19SBen Gras /* 1172fe8fb19SBen Gras ------------------------------------------------------------------------------- 1182fe8fb19SBen Gras Software IEC/IEEE integer-to-floating-point conversion routines. 1192fe8fb19SBen Gras ------------------------------------------------------------------------------- 1202fe8fb19SBen Gras */ 121f14fb602SLionel Sambuc float32 int32_to_float32( int32 ); 122f14fb602SLionel Sambuc float32 uint32_to_float32( uint32 ); 123f14fb602SLionel Sambuc float64 int32_to_float64( int32 ); 124f14fb602SLionel Sambuc float64 uint32_to_float64( uint32 ); 1252fe8fb19SBen Gras #ifdef FLOATX80 126f14fb602SLionel Sambuc floatx80 int32_to_floatx80( int32 ); 127f14fb602SLionel Sambuc floatx80 uint32_to_floatx80( uint32 ); 1282fe8fb19SBen Gras #endif 1292fe8fb19SBen Gras #ifdef FLOAT128 130f14fb602SLionel Sambuc float128 int32_to_float128( int32 ); 131f14fb602SLionel Sambuc float128 uint32_to_float128( uint32 ); 1322fe8fb19SBen Gras #endif 1332fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC /* __floatdi?f is in libgcc2.c */ 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 #endif 1432fe8fb19SBen Gras 1442fe8fb19SBen Gras /* 1452fe8fb19SBen Gras ------------------------------------------------------------------------------- 1462fe8fb19SBen Gras Software IEC/IEEE single-precision conversion routines. 1472fe8fb19SBen Gras ------------------------------------------------------------------------------- 1482fe8fb19SBen Gras */ 1492fe8fb19SBen Gras int float32_to_int32( float32 ); 1502fe8fb19SBen Gras int float32_to_int32_round_to_zero( float32 ); 1512fe8fb19SBen Gras #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS) 1522fe8fb19SBen Gras unsigned int float32_to_uint32_round_to_zero( float32 ); 1532fe8fb19SBen Gras #endif 1542fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */ 1552fe8fb19SBen Gras long long float32_to_int64( float32 ); 1562fe8fb19SBen Gras long long float32_to_int64_round_to_zero( float32 ); 1572fe8fb19SBen Gras #endif 1582fe8fb19SBen Gras float64 float32_to_float64( float32 ); 1592fe8fb19SBen Gras #ifdef FLOATX80 1602fe8fb19SBen Gras floatx80 float32_to_floatx80( float32 ); 1612fe8fb19SBen Gras #endif 1622fe8fb19SBen Gras #ifdef FLOAT128 1632fe8fb19SBen Gras float128 float32_to_float128( float32 ); 1642fe8fb19SBen Gras #endif 1652fe8fb19SBen Gras 1662fe8fb19SBen Gras /* 1672fe8fb19SBen Gras ------------------------------------------------------------------------------- 1682fe8fb19SBen Gras Software IEC/IEEE single-precision operations. 1692fe8fb19SBen Gras ------------------------------------------------------------------------------- 1702fe8fb19SBen Gras */ 1712fe8fb19SBen Gras float32 float32_round_to_int( float32 ); 1722fe8fb19SBen Gras float32 float32_add( float32, float32 ); 1732fe8fb19SBen Gras float32 float32_sub( float32, float32 ); 1742fe8fb19SBen Gras float32 float32_mul( float32, float32 ); 1752fe8fb19SBen Gras float32 float32_div( float32, float32 ); 1762fe8fb19SBen Gras float32 float32_rem( float32, float32 ); 1772fe8fb19SBen Gras float32 float32_sqrt( float32 ); 1782fe8fb19SBen Gras int float32_eq( float32, float32 ); 1792fe8fb19SBen Gras int float32_le( float32, float32 ); 1802fe8fb19SBen Gras int float32_lt( float32, float32 ); 1812fe8fb19SBen Gras int float32_eq_signaling( float32, float32 ); 1822fe8fb19SBen Gras int float32_le_quiet( float32, float32 ); 1832fe8fb19SBen Gras int float32_lt_quiet( float32, float32 ); 1842fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC 1852fe8fb19SBen Gras int float32_is_signaling_nan( float32 ); 1862fe8fb19SBen Gras #endif 1872fe8fb19SBen Gras 1882fe8fb19SBen Gras /* 1892fe8fb19SBen Gras ------------------------------------------------------------------------------- 1902fe8fb19SBen Gras Software IEC/IEEE double-precision conversion routines. 1912fe8fb19SBen Gras ------------------------------------------------------------------------------- 1922fe8fb19SBen Gras */ 1932fe8fb19SBen Gras int float64_to_int32( float64 ); 1942fe8fb19SBen Gras int float64_to_int32_round_to_zero( float64 ); 1952fe8fb19SBen Gras #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS) 1962fe8fb19SBen Gras unsigned int float64_to_uint32_round_to_zero( float64 ); 1972fe8fb19SBen Gras #endif 1982fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */ 1992fe8fb19SBen Gras long long float64_to_int64( float64 ); 2002fe8fb19SBen Gras long long float64_to_int64_round_to_zero( float64 ); 2012fe8fb19SBen Gras #endif 2022fe8fb19SBen Gras float32 float64_to_float32( float64 ); 2032fe8fb19SBen Gras #ifdef FLOATX80 2042fe8fb19SBen Gras floatx80 float64_to_floatx80( float64 ); 2052fe8fb19SBen Gras #endif 2062fe8fb19SBen Gras #ifdef FLOAT128 2072fe8fb19SBen Gras float128 float64_to_float128( float64 ); 2082fe8fb19SBen Gras #endif 2092fe8fb19SBen Gras 2102fe8fb19SBen Gras /* 2112fe8fb19SBen Gras ------------------------------------------------------------------------------- 2122fe8fb19SBen Gras Software IEC/IEEE double-precision operations. 2132fe8fb19SBen Gras ------------------------------------------------------------------------------- 2142fe8fb19SBen Gras */ 2152fe8fb19SBen Gras float64 float64_round_to_int( float64 ); 2162fe8fb19SBen Gras float64 float64_add( float64, float64 ); 2172fe8fb19SBen Gras float64 float64_sub( float64, float64 ); 2182fe8fb19SBen Gras float64 float64_mul( float64, float64 ); 2192fe8fb19SBen Gras float64 float64_div( float64, float64 ); 2202fe8fb19SBen Gras float64 float64_rem( float64, float64 ); 2212fe8fb19SBen Gras float64 float64_sqrt( float64 ); 2222fe8fb19SBen Gras int float64_eq( float64, float64 ); 2232fe8fb19SBen Gras int float64_le( float64, float64 ); 2242fe8fb19SBen Gras int float64_lt( float64, float64 ); 2252fe8fb19SBen Gras int float64_eq_signaling( float64, float64 ); 2262fe8fb19SBen Gras int float64_le_quiet( float64, float64 ); 2272fe8fb19SBen Gras int float64_lt_quiet( float64, float64 ); 2282fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC 2292fe8fb19SBen Gras int float64_is_signaling_nan( float64 ); 2302fe8fb19SBen Gras #endif 2312fe8fb19SBen Gras 2322fe8fb19SBen Gras #ifdef FLOATX80 2332fe8fb19SBen Gras 2342fe8fb19SBen Gras /* 2352fe8fb19SBen Gras ------------------------------------------------------------------------------- 2362fe8fb19SBen Gras Software IEC/IEEE extended double-precision conversion routines. 2372fe8fb19SBen Gras ------------------------------------------------------------------------------- 2382fe8fb19SBen Gras */ 2392fe8fb19SBen Gras int floatx80_to_int32( floatx80 ); 2402fe8fb19SBen Gras int floatx80_to_int32_round_to_zero( floatx80 ); 2412fe8fb19SBen Gras long long floatx80_to_int64( floatx80 ); 2422fe8fb19SBen Gras long long floatx80_to_int64_round_to_zero( floatx80 ); 2432fe8fb19SBen Gras float32 floatx80_to_float32( floatx80 ); 2442fe8fb19SBen Gras float64 floatx80_to_float64( floatx80 ); 2452fe8fb19SBen Gras #ifdef FLOAT128 2462fe8fb19SBen Gras float128 floatx80_to_float128( floatx80 ); 2472fe8fb19SBen Gras #endif 2482fe8fb19SBen Gras 2492fe8fb19SBen Gras /* 2502fe8fb19SBen Gras ------------------------------------------------------------------------------- 2512fe8fb19SBen Gras Software IEC/IEEE extended double-precision rounding precision. Valid 2522fe8fb19SBen Gras values are 32, 64, and 80. 2532fe8fb19SBen Gras ------------------------------------------------------------------------------- 2542fe8fb19SBen Gras */ 2552fe8fb19SBen Gras extern int floatx80_rounding_precision; 2562fe8fb19SBen Gras 2572fe8fb19SBen Gras /* 2582fe8fb19SBen Gras ------------------------------------------------------------------------------- 2592fe8fb19SBen Gras Software IEC/IEEE extended double-precision operations. 2602fe8fb19SBen Gras ------------------------------------------------------------------------------- 2612fe8fb19SBen Gras */ 2622fe8fb19SBen Gras floatx80 floatx80_round_to_int( floatx80 ); 2632fe8fb19SBen Gras floatx80 floatx80_add( floatx80, floatx80 ); 2642fe8fb19SBen Gras floatx80 floatx80_sub( floatx80, floatx80 ); 2652fe8fb19SBen Gras floatx80 floatx80_mul( floatx80, floatx80 ); 2662fe8fb19SBen Gras floatx80 floatx80_div( floatx80, floatx80 ); 2672fe8fb19SBen Gras floatx80 floatx80_rem( floatx80, floatx80 ); 2682fe8fb19SBen Gras floatx80 floatx80_sqrt( floatx80 ); 2692fe8fb19SBen Gras int floatx80_eq( floatx80, floatx80 ); 2702fe8fb19SBen Gras int floatx80_le( floatx80, floatx80 ); 2712fe8fb19SBen Gras int floatx80_lt( floatx80, floatx80 ); 2722fe8fb19SBen Gras int floatx80_eq_signaling( floatx80, floatx80 ); 2732fe8fb19SBen Gras int floatx80_le_quiet( floatx80, floatx80 ); 2742fe8fb19SBen Gras int floatx80_lt_quiet( floatx80, floatx80 ); 2752fe8fb19SBen Gras int floatx80_is_signaling_nan( floatx80 ); 2762fe8fb19SBen Gras 2772fe8fb19SBen Gras #endif 2782fe8fb19SBen Gras 2792fe8fb19SBen Gras #ifdef FLOAT128 2802fe8fb19SBen Gras 2812fe8fb19SBen Gras /* 2822fe8fb19SBen Gras ------------------------------------------------------------------------------- 2832fe8fb19SBen Gras Software IEC/IEEE quadruple-precision conversion routines. 2842fe8fb19SBen Gras ------------------------------------------------------------------------------- 2852fe8fb19SBen Gras */ 2862fe8fb19SBen Gras int float128_to_int32( float128 ); 2872fe8fb19SBen Gras int float128_to_int32_round_to_zero( float128 ); 2882fe8fb19SBen Gras long long float128_to_int64( float128 ); 2892fe8fb19SBen Gras long long float128_to_int64_round_to_zero( float128 ); 2902fe8fb19SBen Gras float32 float128_to_float32( float128 ); 2912fe8fb19SBen Gras float64 float128_to_float64( float128 ); 2922fe8fb19SBen Gras #ifdef FLOATX80 2932fe8fb19SBen Gras floatx80 float128_to_floatx80( float128 ); 2942fe8fb19SBen Gras #endif 2952fe8fb19SBen Gras 2962fe8fb19SBen Gras /* 2972fe8fb19SBen Gras ------------------------------------------------------------------------------- 2982fe8fb19SBen Gras Software IEC/IEEE quadruple-precision operations. 2992fe8fb19SBen Gras ------------------------------------------------------------------------------- 3002fe8fb19SBen Gras */ 3012fe8fb19SBen Gras float128 float128_round_to_int( float128 ); 3022fe8fb19SBen Gras float128 float128_add( float128, float128 ); 3032fe8fb19SBen Gras float128 float128_sub( float128, float128 ); 3042fe8fb19SBen Gras float128 float128_mul( float128, float128 ); 3052fe8fb19SBen Gras float128 float128_div( float128, float128 ); 3062fe8fb19SBen Gras float128 float128_rem( float128, float128 ); 3072fe8fb19SBen Gras float128 float128_sqrt( float128 ); 3082fe8fb19SBen Gras int float128_eq( float128, float128 ); 3092fe8fb19SBen Gras int float128_le( float128, float128 ); 3102fe8fb19SBen Gras int float128_lt( float128, float128 ); 3112fe8fb19SBen Gras int float128_eq_signaling( float128, float128 ); 3122fe8fb19SBen Gras int float128_le_quiet( float128, float128 ); 3132fe8fb19SBen Gras int float128_lt_quiet( float128, float128 ); 3142fe8fb19SBen Gras int float128_is_signaling_nan( float128 ); 3152fe8fb19SBen Gras 3162fe8fb19SBen Gras #endif 3172fe8fb19SBen Gras 318