1*3f2a55b3Smatt /* $NetBSD: softfloat.h,v 1.10 2013/04/24 18:04:46 matt Exp $ */ 2010758bfSbjh21 3010758bfSbjh21 /* This is a derivative work. */ 45aefcfdcSbjh21 55aefcfdcSbjh21 /* 65aefcfdcSbjh21 =============================================================================== 75aefcfdcSbjh21 85aefcfdcSbjh21 This C header file is part of the SoftFloat IEC/IEEE Floating-point 95aefcfdcSbjh21 Arithmetic Package, Release 2a. 105aefcfdcSbjh21 115aefcfdcSbjh21 Written by John R. Hauser. This work was made possible in part by the 125aefcfdcSbjh21 International Computer Science Institute, located at Suite 600, 1947 Center 135aefcfdcSbjh21 Street, Berkeley, California 94704. Funding was partially provided by the 145aefcfdcSbjh21 National Science Foundation under grant MIP-9311980. The original version 155aefcfdcSbjh21 of this code was written as part of a project to build a fixed-point vector 165aefcfdcSbjh21 processor in collaboration with the University of California at Berkeley, 175aefcfdcSbjh21 overseen by Profs. Nelson Morgan and John Wawrzynek. More information 185aefcfdcSbjh21 is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/ 195aefcfdcSbjh21 arithmetic/SoftFloat.html'. 205aefcfdcSbjh21 215aefcfdcSbjh21 THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort 225aefcfdcSbjh21 has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT 235aefcfdcSbjh21 TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO 245aefcfdcSbjh21 PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY 255aefcfdcSbjh21 AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. 265aefcfdcSbjh21 275aefcfdcSbjh21 Derivative works are acceptable, even for commercial purposes, so long as 285aefcfdcSbjh21 (1) they include prominent notice that the work is derivative, and (2) they 295aefcfdcSbjh21 include prominent notice akin to these four paragraphs for those parts of 305aefcfdcSbjh21 this code that are retained. 315aefcfdcSbjh21 325aefcfdcSbjh21 =============================================================================== 335aefcfdcSbjh21 */ 345aefcfdcSbjh21 355aefcfdcSbjh21 /* 365aefcfdcSbjh21 ------------------------------------------------------------------------------- 375aefcfdcSbjh21 The macro `FLOATX80' must be defined to enable the extended double-precision 385aefcfdcSbjh21 floating-point format `floatx80'. If this macro is not defined, the 395aefcfdcSbjh21 `floatx80' type will not be defined, and none of the functions that either 405aefcfdcSbjh21 input or output the `floatx80' type will be defined. The same applies to 415aefcfdcSbjh21 the `FLOAT128' macro and the quadruple-precision format `float128'. 425aefcfdcSbjh21 ------------------------------------------------------------------------------- 435aefcfdcSbjh21 */ 445aefcfdcSbjh21 /* #define FLOATX80 */ 455aefcfdcSbjh21 /* #define FLOAT128 */ 465aefcfdcSbjh21 47*3f2a55b3Smatt #include <stdint.h> 48dad27561Sbjh21 #include <machine/ieeefp.h> 49dad27561Sbjh21 505aefcfdcSbjh21 /* 515aefcfdcSbjh21 ------------------------------------------------------------------------------- 525aefcfdcSbjh21 Software IEC/IEEE floating-point types. 535aefcfdcSbjh21 ------------------------------------------------------------------------------- 545aefcfdcSbjh21 */ 555aefcfdcSbjh21 typedef unsigned int float32; 565aefcfdcSbjh21 typedef unsigned long long float64; 575aefcfdcSbjh21 #ifdef FLOATX80 585aefcfdcSbjh21 typedef struct { 595aefcfdcSbjh21 unsigned short high; 605aefcfdcSbjh21 unsigned long long low; 615aefcfdcSbjh21 } floatx80; 625aefcfdcSbjh21 #endif 635aefcfdcSbjh21 #ifdef FLOAT128 645aefcfdcSbjh21 typedef struct { 655aefcfdcSbjh21 unsigned long long high, low; 665aefcfdcSbjh21 } float128; 675aefcfdcSbjh21 #endif 685aefcfdcSbjh21 695aefcfdcSbjh21 /* 705aefcfdcSbjh21 ------------------------------------------------------------------------------- 715aefcfdcSbjh21 Software IEC/IEEE floating-point underflow tininess-detection mode. 725aefcfdcSbjh21 ------------------------------------------------------------------------------- 735aefcfdcSbjh21 */ 748726b401Smrg #ifndef SOFTFLOAT_FOR_GCC 755aefcfdcSbjh21 extern int float_detect_tininess; 768726b401Smrg #endif 775aefcfdcSbjh21 enum { 785aefcfdcSbjh21 float_tininess_after_rounding = 0, 795aefcfdcSbjh21 float_tininess_before_rounding = 1 805aefcfdcSbjh21 }; 815aefcfdcSbjh21 825aefcfdcSbjh21 /* 835aefcfdcSbjh21 ------------------------------------------------------------------------------- 845aefcfdcSbjh21 Software IEC/IEEE floating-point rounding mode. 855aefcfdcSbjh21 ------------------------------------------------------------------------------- 865aefcfdcSbjh21 */ 87251de84cSbjh21 extern fp_rnd float_rounding_mode; 88ea87d22aSmatt #define float_round_nearest_even FP_RN 89ea87d22aSmatt #define float_round_to_zero FP_RZ 90ea87d22aSmatt #define float_round_down FP_RM 91ea87d22aSmatt #define float_round_up FP_RP 925aefcfdcSbjh21 935aefcfdcSbjh21 /* 945aefcfdcSbjh21 ------------------------------------------------------------------------------- 955aefcfdcSbjh21 Software IEC/IEEE floating-point exception flags. 965aefcfdcSbjh21 ------------------------------------------------------------------------------- 975aefcfdcSbjh21 */ 98251de84cSbjh21 extern fp_except float_exception_flags; 99010758bfSbjh21 extern fp_except float_exception_mask; 1005aefcfdcSbjh21 enum { 101dad27561Sbjh21 float_flag_inexact = FP_X_IMP, 102dad27561Sbjh21 float_flag_underflow = FP_X_UFL, 103dad27561Sbjh21 float_flag_overflow = FP_X_OFL, 104dad27561Sbjh21 float_flag_divbyzero = FP_X_DZ, 105dad27561Sbjh21 float_flag_invalid = FP_X_INV 1065aefcfdcSbjh21 }; 1075aefcfdcSbjh21 1085aefcfdcSbjh21 /* 1095aefcfdcSbjh21 ------------------------------------------------------------------------------- 1105aefcfdcSbjh21 Routine to raise any or all of the software IEC/IEEE floating-point 1115aefcfdcSbjh21 exception flags. 1125aefcfdcSbjh21 ------------------------------------------------------------------------------- 1135aefcfdcSbjh21 */ 114010758bfSbjh21 void float_raise( fp_except ); 1155aefcfdcSbjh21 1165aefcfdcSbjh21 /* 1175aefcfdcSbjh21 ------------------------------------------------------------------------------- 1185aefcfdcSbjh21 Software IEC/IEEE integer-to-floating-point conversion routines. 1195aefcfdcSbjh21 ------------------------------------------------------------------------------- 1205aefcfdcSbjh21 */ 12165f52d9eSmatt float32 int32_to_float32( int32 ); 12265f52d9eSmatt float32 uint32_to_float32( uint32 ); 12365f52d9eSmatt float64 int32_to_float64( int32 ); 12465f52d9eSmatt float64 uint32_to_float64( uint32 ); 1255aefcfdcSbjh21 #ifdef FLOATX80 12665f52d9eSmatt floatx80 int32_to_floatx80( int32 ); 12765f52d9eSmatt floatx80 uint32_to_floatx80( uint32 ); 1285aefcfdcSbjh21 #endif 1295aefcfdcSbjh21 #ifdef FLOAT128 13065f52d9eSmatt float128 int32_to_float128( int32 ); 13165f52d9eSmatt float128 uint32_to_float128( uint32 ); 1325aefcfdcSbjh21 #endif 1330347c41aSbjh21 #ifndef SOFTFLOAT_FOR_GCC /* __floatdi?f is in libgcc2.c */ 1345aefcfdcSbjh21 float32 int64_to_float32( long long ); 1355aefcfdcSbjh21 float64 int64_to_float64( long long ); 1365aefcfdcSbjh21 #ifdef FLOATX80 1375aefcfdcSbjh21 floatx80 int64_to_floatx80( long long ); 1385aefcfdcSbjh21 #endif 1395aefcfdcSbjh21 #ifdef FLOAT128 1405aefcfdcSbjh21 float128 int64_to_float128( long long ); 1415aefcfdcSbjh21 #endif 1420347c41aSbjh21 #endif 1435aefcfdcSbjh21 1445aefcfdcSbjh21 /* 1455aefcfdcSbjh21 ------------------------------------------------------------------------------- 1465aefcfdcSbjh21 Software IEC/IEEE single-precision conversion routines. 1475aefcfdcSbjh21 ------------------------------------------------------------------------------- 1485aefcfdcSbjh21 */ 1495aefcfdcSbjh21 int float32_to_int32( float32 ); 1505aefcfdcSbjh21 int float32_to_int32_round_to_zero( float32 ); 1516964bdfcSbjh21 #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS) 1526964bdfcSbjh21 unsigned int float32_to_uint32_round_to_zero( float32 ); 1536964bdfcSbjh21 #endif 1540347c41aSbjh21 #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */ 1555aefcfdcSbjh21 long long float32_to_int64( float32 ); 1565aefcfdcSbjh21 long long float32_to_int64_round_to_zero( float32 ); 1570347c41aSbjh21 #endif 1585aefcfdcSbjh21 float64 float32_to_float64( float32 ); 1595aefcfdcSbjh21 #ifdef FLOATX80 1605aefcfdcSbjh21 floatx80 float32_to_floatx80( float32 ); 1615aefcfdcSbjh21 #endif 1625aefcfdcSbjh21 #ifdef FLOAT128 1635aefcfdcSbjh21 float128 float32_to_float128( float32 ); 1645aefcfdcSbjh21 #endif 1655aefcfdcSbjh21 1665aefcfdcSbjh21 /* 1675aefcfdcSbjh21 ------------------------------------------------------------------------------- 1685aefcfdcSbjh21 Software IEC/IEEE single-precision operations. 1695aefcfdcSbjh21 ------------------------------------------------------------------------------- 1705aefcfdcSbjh21 */ 1715aefcfdcSbjh21 float32 float32_round_to_int( float32 ); 1725aefcfdcSbjh21 float32 float32_add( float32, float32 ); 1735aefcfdcSbjh21 float32 float32_sub( float32, float32 ); 1745aefcfdcSbjh21 float32 float32_mul( float32, float32 ); 1755aefcfdcSbjh21 float32 float32_div( float32, float32 ); 1765aefcfdcSbjh21 float32 float32_rem( float32, float32 ); 1775aefcfdcSbjh21 float32 float32_sqrt( float32 ); 1785aefcfdcSbjh21 int float32_eq( float32, float32 ); 1795aefcfdcSbjh21 int float32_le( float32, float32 ); 1805aefcfdcSbjh21 int float32_lt( float32, float32 ); 1815aefcfdcSbjh21 int float32_eq_signaling( float32, float32 ); 1825aefcfdcSbjh21 int float32_le_quiet( float32, float32 ); 1835aefcfdcSbjh21 int float32_lt_quiet( float32, float32 ); 1845aefcfdcSbjh21 #ifndef SOFTFLOAT_FOR_GCC 1855aefcfdcSbjh21 int float32_is_signaling_nan( float32 ); 1865aefcfdcSbjh21 #endif 1875aefcfdcSbjh21 1885aefcfdcSbjh21 /* 1895aefcfdcSbjh21 ------------------------------------------------------------------------------- 1905aefcfdcSbjh21 Software IEC/IEEE double-precision conversion routines. 1915aefcfdcSbjh21 ------------------------------------------------------------------------------- 1925aefcfdcSbjh21 */ 1935aefcfdcSbjh21 int float64_to_int32( float64 ); 1945aefcfdcSbjh21 int float64_to_int32_round_to_zero( float64 ); 1956964bdfcSbjh21 #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS) 1966964bdfcSbjh21 unsigned int float64_to_uint32_round_to_zero( float64 ); 1976964bdfcSbjh21 #endif 1980347c41aSbjh21 #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */ 1995aefcfdcSbjh21 long long float64_to_int64( float64 ); 2005aefcfdcSbjh21 long long float64_to_int64_round_to_zero( float64 ); 2010347c41aSbjh21 #endif 2025aefcfdcSbjh21 float32 float64_to_float32( float64 ); 2035aefcfdcSbjh21 #ifdef FLOATX80 2045aefcfdcSbjh21 floatx80 float64_to_floatx80( float64 ); 2055aefcfdcSbjh21 #endif 2065aefcfdcSbjh21 #ifdef FLOAT128 2075aefcfdcSbjh21 float128 float64_to_float128( float64 ); 2085aefcfdcSbjh21 #endif 2095aefcfdcSbjh21 2105aefcfdcSbjh21 /* 2115aefcfdcSbjh21 ------------------------------------------------------------------------------- 2125aefcfdcSbjh21 Software IEC/IEEE double-precision operations. 2135aefcfdcSbjh21 ------------------------------------------------------------------------------- 2145aefcfdcSbjh21 */ 2155aefcfdcSbjh21 float64 float64_round_to_int( float64 ); 2165aefcfdcSbjh21 float64 float64_add( float64, float64 ); 2175aefcfdcSbjh21 float64 float64_sub( float64, float64 ); 2185aefcfdcSbjh21 float64 float64_mul( float64, float64 ); 2195aefcfdcSbjh21 float64 float64_div( float64, float64 ); 2205aefcfdcSbjh21 float64 float64_rem( float64, float64 ); 2215aefcfdcSbjh21 float64 float64_sqrt( float64 ); 2225aefcfdcSbjh21 int float64_eq( float64, float64 ); 2235aefcfdcSbjh21 int float64_le( float64, float64 ); 2245aefcfdcSbjh21 int float64_lt( float64, float64 ); 2255aefcfdcSbjh21 int float64_eq_signaling( float64, float64 ); 2265aefcfdcSbjh21 int float64_le_quiet( float64, float64 ); 2275aefcfdcSbjh21 int float64_lt_quiet( float64, float64 ); 2285aefcfdcSbjh21 #ifndef SOFTFLOAT_FOR_GCC 2295aefcfdcSbjh21 int float64_is_signaling_nan( float64 ); 2305aefcfdcSbjh21 #endif 2315aefcfdcSbjh21 2325aefcfdcSbjh21 #ifdef FLOATX80 2335aefcfdcSbjh21 2345aefcfdcSbjh21 /* 2355aefcfdcSbjh21 ------------------------------------------------------------------------------- 2365aefcfdcSbjh21 Software IEC/IEEE extended double-precision conversion routines. 2375aefcfdcSbjh21 ------------------------------------------------------------------------------- 2385aefcfdcSbjh21 */ 2395aefcfdcSbjh21 int floatx80_to_int32( floatx80 ); 2405aefcfdcSbjh21 int floatx80_to_int32_round_to_zero( floatx80 ); 2415aefcfdcSbjh21 long long floatx80_to_int64( floatx80 ); 2425aefcfdcSbjh21 long long floatx80_to_int64_round_to_zero( floatx80 ); 2435aefcfdcSbjh21 float32 floatx80_to_float32( floatx80 ); 2445aefcfdcSbjh21 float64 floatx80_to_float64( floatx80 ); 2455aefcfdcSbjh21 #ifdef FLOAT128 2465aefcfdcSbjh21 float128 floatx80_to_float128( floatx80 ); 2475aefcfdcSbjh21 #endif 2485aefcfdcSbjh21 2495aefcfdcSbjh21 /* 2505aefcfdcSbjh21 ------------------------------------------------------------------------------- 2515aefcfdcSbjh21 Software IEC/IEEE extended double-precision rounding precision. Valid 2525aefcfdcSbjh21 values are 32, 64, and 80. 2535aefcfdcSbjh21 ------------------------------------------------------------------------------- 2545aefcfdcSbjh21 */ 2555aefcfdcSbjh21 extern int floatx80_rounding_precision; 2565aefcfdcSbjh21 2575aefcfdcSbjh21 /* 2585aefcfdcSbjh21 ------------------------------------------------------------------------------- 2595aefcfdcSbjh21 Software IEC/IEEE extended double-precision operations. 2605aefcfdcSbjh21 ------------------------------------------------------------------------------- 2615aefcfdcSbjh21 */ 2625aefcfdcSbjh21 floatx80 floatx80_round_to_int( floatx80 ); 2635aefcfdcSbjh21 floatx80 floatx80_add( floatx80, floatx80 ); 2645aefcfdcSbjh21 floatx80 floatx80_sub( floatx80, floatx80 ); 2655aefcfdcSbjh21 floatx80 floatx80_mul( floatx80, floatx80 ); 2665aefcfdcSbjh21 floatx80 floatx80_div( floatx80, floatx80 ); 2675aefcfdcSbjh21 floatx80 floatx80_rem( floatx80, floatx80 ); 2685aefcfdcSbjh21 floatx80 floatx80_sqrt( floatx80 ); 2695aefcfdcSbjh21 int floatx80_eq( floatx80, floatx80 ); 2705aefcfdcSbjh21 int floatx80_le( floatx80, floatx80 ); 2715aefcfdcSbjh21 int floatx80_lt( floatx80, floatx80 ); 2725aefcfdcSbjh21 int floatx80_eq_signaling( floatx80, floatx80 ); 2735aefcfdcSbjh21 int floatx80_le_quiet( floatx80, floatx80 ); 2745aefcfdcSbjh21 int floatx80_lt_quiet( floatx80, floatx80 ); 2755aefcfdcSbjh21 int floatx80_is_signaling_nan( floatx80 ); 2765aefcfdcSbjh21 2775aefcfdcSbjh21 #endif 2785aefcfdcSbjh21 2795aefcfdcSbjh21 #ifdef FLOAT128 2805aefcfdcSbjh21 2815aefcfdcSbjh21 /* 2825aefcfdcSbjh21 ------------------------------------------------------------------------------- 2835aefcfdcSbjh21 Software IEC/IEEE quadruple-precision conversion routines. 2845aefcfdcSbjh21 ------------------------------------------------------------------------------- 2855aefcfdcSbjh21 */ 2865aefcfdcSbjh21 int float128_to_int32( float128 ); 2875aefcfdcSbjh21 int float128_to_int32_round_to_zero( float128 ); 2885aefcfdcSbjh21 long long float128_to_int64( float128 ); 2895aefcfdcSbjh21 long long float128_to_int64_round_to_zero( float128 ); 2905aefcfdcSbjh21 float32 float128_to_float32( float128 ); 2915aefcfdcSbjh21 float64 float128_to_float64( float128 ); 2925aefcfdcSbjh21 #ifdef FLOATX80 2935aefcfdcSbjh21 floatx80 float128_to_floatx80( float128 ); 2945aefcfdcSbjh21 #endif 2955aefcfdcSbjh21 2965aefcfdcSbjh21 /* 2975aefcfdcSbjh21 ------------------------------------------------------------------------------- 2985aefcfdcSbjh21 Software IEC/IEEE quadruple-precision operations. 2995aefcfdcSbjh21 ------------------------------------------------------------------------------- 3005aefcfdcSbjh21 */ 3015aefcfdcSbjh21 float128 float128_round_to_int( float128 ); 3025aefcfdcSbjh21 float128 float128_add( float128, float128 ); 3035aefcfdcSbjh21 float128 float128_sub( float128, float128 ); 3045aefcfdcSbjh21 float128 float128_mul( float128, float128 ); 3055aefcfdcSbjh21 float128 float128_div( float128, float128 ); 3065aefcfdcSbjh21 float128 float128_rem( float128, float128 ); 3075aefcfdcSbjh21 float128 float128_sqrt( float128 ); 3085aefcfdcSbjh21 int float128_eq( float128, float128 ); 3095aefcfdcSbjh21 int float128_le( float128, float128 ); 3105aefcfdcSbjh21 int float128_lt( float128, float128 ); 3115aefcfdcSbjh21 int float128_eq_signaling( float128, float128 ); 3125aefcfdcSbjh21 int float128_le_quiet( float128, float128 ); 3135aefcfdcSbjh21 int float128_lt_quiet( float128, float128 ); 3145aefcfdcSbjh21 int float128_is_signaling_nan( float128 ); 3155aefcfdcSbjh21 3165aefcfdcSbjh21 #endif 3175aefcfdcSbjh21 318