1*2fe8fb19SBen Gras /* $NetBSD: softfloat.h,v 1.6 2007/11/08 15:50:23 martin Exp $ */ 2*2fe8fb19SBen Gras 3*2fe8fb19SBen Gras /* This is a derivative work. */ 4*2fe8fb19SBen Gras 5*2fe8fb19SBen Gras /* 6*2fe8fb19SBen Gras =============================================================================== 7*2fe8fb19SBen Gras 8*2fe8fb19SBen Gras This C header file is part of the SoftFloat IEC/IEEE Floating-point 9*2fe8fb19SBen Gras Arithmetic Package, Release 2a. 10*2fe8fb19SBen Gras 11*2fe8fb19SBen Gras Written by John R. Hauser. This work was made possible in part by the 12*2fe8fb19SBen Gras International Computer Science Institute, located at Suite 600, 1947 Center 13*2fe8fb19SBen Gras Street, Berkeley, California 94704. Funding was partially provided by the 14*2fe8fb19SBen Gras National Science Foundation under grant MIP-9311980. The original version 15*2fe8fb19SBen Gras of this code was written as part of a project to build a fixed-point vector 16*2fe8fb19SBen Gras processor in collaboration with the University of California at Berkeley, 17*2fe8fb19SBen Gras overseen by Profs. Nelson Morgan and John Wawrzynek. More information 18*2fe8fb19SBen Gras is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/ 19*2fe8fb19SBen Gras arithmetic/SoftFloat.html'. 20*2fe8fb19SBen Gras 21*2fe8fb19SBen Gras THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort 22*2fe8fb19SBen Gras has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT 23*2fe8fb19SBen Gras TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO 24*2fe8fb19SBen Gras PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY 25*2fe8fb19SBen Gras AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. 26*2fe8fb19SBen Gras 27*2fe8fb19SBen Gras Derivative works are acceptable, even for commercial purposes, so long as 28*2fe8fb19SBen Gras (1) they include prominent notice that the work is derivative, and (2) they 29*2fe8fb19SBen Gras include prominent notice akin to these four paragraphs for those parts of 30*2fe8fb19SBen Gras this code that are retained. 31*2fe8fb19SBen Gras 32*2fe8fb19SBen Gras =============================================================================== 33*2fe8fb19SBen Gras */ 34*2fe8fb19SBen Gras 35*2fe8fb19SBen Gras /* 36*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 37*2fe8fb19SBen Gras The macro `FLOATX80' must be defined to enable the extended double-precision 38*2fe8fb19SBen Gras floating-point format `floatx80'. If this macro is not defined, the 39*2fe8fb19SBen Gras `floatx80' type will not be defined, and none of the functions that either 40*2fe8fb19SBen Gras input or output the `floatx80' type will be defined. The same applies to 41*2fe8fb19SBen Gras the `FLOAT128' macro and the quadruple-precision format `float128'. 42*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 43*2fe8fb19SBen Gras */ 44*2fe8fb19SBen Gras /* #define FLOATX80 */ 45*2fe8fb19SBen Gras #define FLOAT128 46*2fe8fb19SBen Gras 47*2fe8fb19SBen Gras #include "softfloat-qp.h" 48*2fe8fb19SBen Gras 49*2fe8fb19SBen Gras #include <machine/ieeefp.h> 50*2fe8fb19SBen Gras 51*2fe8fb19SBen Gras /* 52*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 53*2fe8fb19SBen Gras Software IEC/IEEE floating-point types. 54*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 55*2fe8fb19SBen Gras */ 56*2fe8fb19SBen Gras typedef unsigned int float32; 57*2fe8fb19SBen Gras typedef unsigned long long float64; 58*2fe8fb19SBen Gras #ifdef FLOATX80 59*2fe8fb19SBen Gras typedef struct { 60*2fe8fb19SBen Gras unsigned short high; 61*2fe8fb19SBen Gras unsigned long long low; 62*2fe8fb19SBen Gras } floatx80; 63*2fe8fb19SBen Gras #endif 64*2fe8fb19SBen Gras #ifdef FLOAT128 65*2fe8fb19SBen Gras typedef struct { 66*2fe8fb19SBen Gras unsigned long long high, low; 67*2fe8fb19SBen Gras } float128; 68*2fe8fb19SBen Gras #endif 69*2fe8fb19SBen Gras 70*2fe8fb19SBen Gras /* 71*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 72*2fe8fb19SBen Gras Software IEC/IEEE floating-point underflow tininess-detection mode. 73*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 74*2fe8fb19SBen Gras */ 75*2fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC 76*2fe8fb19SBen Gras extern int8 float_detect_tininess; 77*2fe8fb19SBen Gras #endif 78*2fe8fb19SBen Gras enum { 79*2fe8fb19SBen Gras float_tininess_after_rounding = 0, 80*2fe8fb19SBen Gras float_tininess_before_rounding = 1 81*2fe8fb19SBen Gras }; 82*2fe8fb19SBen Gras 83*2fe8fb19SBen Gras /* 84*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 85*2fe8fb19SBen Gras Software IEC/IEEE floating-point rounding mode. 86*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 87*2fe8fb19SBen Gras */ 88*2fe8fb19SBen Gras extern fp_rnd float_rounding_mode; 89*2fe8fb19SBen Gras enum { 90*2fe8fb19SBen Gras float_round_nearest_even = FP_RN, 91*2fe8fb19SBen Gras float_round_to_zero = FP_RZ, 92*2fe8fb19SBen Gras float_round_down = FP_RM, 93*2fe8fb19SBen Gras float_round_up = FP_RP 94*2fe8fb19SBen Gras }; 95*2fe8fb19SBen Gras 96*2fe8fb19SBen Gras /* 97*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 98*2fe8fb19SBen Gras Software IEC/IEEE floating-point exception flags. 99*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 100*2fe8fb19SBen Gras */ 101*2fe8fb19SBen Gras extern fp_except float_exception_flags; 102*2fe8fb19SBen Gras extern fp_except float_exception_mask; 103*2fe8fb19SBen Gras enum { 104*2fe8fb19SBen Gras float_flag_inexact = FP_X_IMP, 105*2fe8fb19SBen Gras float_flag_underflow = FP_X_UFL, 106*2fe8fb19SBen Gras float_flag_overflow = FP_X_OFL, 107*2fe8fb19SBen Gras float_flag_divbyzero = FP_X_DZ, 108*2fe8fb19SBen Gras float_flag_invalid = FP_X_INV 109*2fe8fb19SBen Gras }; 110*2fe8fb19SBen Gras 111*2fe8fb19SBen Gras /* 112*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 113*2fe8fb19SBen Gras Routine to raise any or all of the software IEC/IEEE floating-point 114*2fe8fb19SBen Gras exception flags. 115*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 116*2fe8fb19SBen Gras */ 117*2fe8fb19SBen Gras void float_raise( fp_except ); 118*2fe8fb19SBen Gras 119*2fe8fb19SBen Gras /* 120*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 121*2fe8fb19SBen Gras Software IEC/IEEE integer-to-floating-point conversion routines. 122*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 123*2fe8fb19SBen Gras */ 124*2fe8fb19SBen Gras float32 int32_to_float32( int ); 125*2fe8fb19SBen Gras float64 int32_to_float64( int ); 126*2fe8fb19SBen Gras #ifdef FLOATX80 127*2fe8fb19SBen Gras floatx80 int32_to_floatx80( int ); 128*2fe8fb19SBen Gras #endif 129*2fe8fb19SBen Gras #ifdef FLOAT128 130*2fe8fb19SBen Gras float128 int32_to_float128( int ); 131*2fe8fb19SBen Gras #endif 132*2fe8fb19SBen Gras float32 int64_to_float32( long long ); 133*2fe8fb19SBen Gras float64 int64_to_float64( long long ); 134*2fe8fb19SBen Gras #ifdef FLOATX80 135*2fe8fb19SBen Gras floatx80 int64_to_floatx80( long long ); 136*2fe8fb19SBen Gras #endif 137*2fe8fb19SBen Gras #ifdef FLOAT128 138*2fe8fb19SBen Gras float128 int64_to_float128( long long ); 139*2fe8fb19SBen Gras #endif 140*2fe8fb19SBen Gras 141*2fe8fb19SBen Gras /* 142*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 143*2fe8fb19SBen Gras Software IEC/IEEE single-precision conversion routines. 144*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 145*2fe8fb19SBen Gras */ 146*2fe8fb19SBen Gras int float32_to_int32( float32 ); 147*2fe8fb19SBen Gras int float32_to_int32_round_to_zero( float32 ); 148*2fe8fb19SBen Gras unsigned int float32_to_uint32_round_to_zero( float32 ); 149*2fe8fb19SBen Gras long long float32_to_int64( float32 ); 150*2fe8fb19SBen Gras long long float32_to_int64_round_to_zero( float32 ); 151*2fe8fb19SBen Gras float64 float32_to_float64( float32 ); 152*2fe8fb19SBen Gras #ifdef FLOATX80 153*2fe8fb19SBen Gras floatx80 float32_to_floatx80( float32 ); 154*2fe8fb19SBen Gras #endif 155*2fe8fb19SBen Gras #ifdef FLOAT128 156*2fe8fb19SBen Gras float128 float32_to_float128( float32 ); 157*2fe8fb19SBen Gras #endif 158*2fe8fb19SBen Gras 159*2fe8fb19SBen Gras /* 160*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 161*2fe8fb19SBen Gras Software IEC/IEEE single-precision operations. 162*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 163*2fe8fb19SBen Gras */ 164*2fe8fb19SBen Gras float32 float32_round_to_int( float32 ); 165*2fe8fb19SBen Gras float32 float32_add( float32, float32 ); 166*2fe8fb19SBen Gras float32 float32_sub( float32, float32 ); 167*2fe8fb19SBen Gras float32 float32_mul( float32, float32 ); 168*2fe8fb19SBen Gras float32 float32_div( float32, float32 ); 169*2fe8fb19SBen Gras float32 float32_rem( float32, float32 ); 170*2fe8fb19SBen Gras float32 float32_sqrt( float32 ); 171*2fe8fb19SBen Gras flag float32_eq( float32, float32 ); 172*2fe8fb19SBen Gras flag float32_le( float32, float32 ); 173*2fe8fb19SBen Gras flag float32_lt( float32, float32 ); 174*2fe8fb19SBen Gras flag float32_eq_signaling( float32, float32 ); 175*2fe8fb19SBen Gras flag float32_le_quiet( float32, float32 ); 176*2fe8fb19SBen Gras flag float32_lt_quiet( float32, float32 ); 177*2fe8fb19SBen Gras flag float32_is_signaling_nan( float32 ); 178*2fe8fb19SBen Gras 179*2fe8fb19SBen Gras /* 180*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 181*2fe8fb19SBen Gras Software IEC/IEEE double-precision conversion routines. 182*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 183*2fe8fb19SBen Gras */ 184*2fe8fb19SBen Gras int float64_to_int32( float64 ); 185*2fe8fb19SBen Gras int float64_to_int32_round_to_zero( float64 ); 186*2fe8fb19SBen Gras unsigned int float64_to_uint32_round_to_zero( float64 ); 187*2fe8fb19SBen Gras long long float64_to_int64( float64 ); 188*2fe8fb19SBen Gras long long float64_to_int64_round_to_zero( float64 ); 189*2fe8fb19SBen Gras float32 float64_to_float32( float64 ); 190*2fe8fb19SBen Gras #ifdef FLOATX80 191*2fe8fb19SBen Gras floatx80 float64_to_floatx80( float64 ); 192*2fe8fb19SBen Gras #endif 193*2fe8fb19SBen Gras #ifdef FLOAT128 194*2fe8fb19SBen Gras float128 float64_to_float128( float64 ); 195*2fe8fb19SBen Gras #endif 196*2fe8fb19SBen Gras 197*2fe8fb19SBen Gras /* 198*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 199*2fe8fb19SBen Gras Software IEC/IEEE double-precision operations. 200*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 201*2fe8fb19SBen Gras */ 202*2fe8fb19SBen Gras float64 float64_round_to_int( float64 ); 203*2fe8fb19SBen Gras float64 float64_add( float64, float64 ); 204*2fe8fb19SBen Gras float64 float64_sub( float64, float64 ); 205*2fe8fb19SBen Gras float64 float64_mul( float64, float64 ); 206*2fe8fb19SBen Gras float64 float64_div( float64, float64 ); 207*2fe8fb19SBen Gras float64 float64_rem( float64, float64 ); 208*2fe8fb19SBen Gras float64 float64_sqrt( float64 ); 209*2fe8fb19SBen Gras flag float64_eq( float64, float64 ); 210*2fe8fb19SBen Gras flag float64_le( float64, float64 ); 211*2fe8fb19SBen Gras flag float64_lt( float64, float64 ); 212*2fe8fb19SBen Gras flag float64_eq_signaling( float64, float64 ); 213*2fe8fb19SBen Gras flag float64_le_quiet( float64, float64 ); 214*2fe8fb19SBen Gras flag float64_lt_quiet( float64, float64 ); 215*2fe8fb19SBen Gras flag float64_is_signaling_nan( float64 ); 216*2fe8fb19SBen Gras 217*2fe8fb19SBen Gras #ifdef FLOATX80 218*2fe8fb19SBen Gras 219*2fe8fb19SBen Gras /* 220*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 221*2fe8fb19SBen Gras Software IEC/IEEE extended double-precision conversion routines. 222*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 223*2fe8fb19SBen Gras */ 224*2fe8fb19SBen Gras int floatx80_to_int32( floatx80 ); 225*2fe8fb19SBen Gras int floatx80_to_int32_round_to_zero( floatx80 ); 226*2fe8fb19SBen Gras long long floatx80_to_int64( floatx80 ); 227*2fe8fb19SBen Gras long long floatx80_to_int64_round_to_zero( floatx80 ); 228*2fe8fb19SBen Gras float32 floatx80_to_float32( floatx80 ); 229*2fe8fb19SBen Gras float64 floatx80_to_float64( floatx80 ); 230*2fe8fb19SBen Gras #ifdef FLOAT128 231*2fe8fb19SBen Gras float128 floatx80_to_float128( floatx80 ); 232*2fe8fb19SBen Gras #endif 233*2fe8fb19SBen Gras 234*2fe8fb19SBen Gras /* 235*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 236*2fe8fb19SBen Gras Software IEC/IEEE extended double-precision rounding precision. Valid 237*2fe8fb19SBen Gras values are 32, 64, and 80. 238*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 239*2fe8fb19SBen Gras */ 240*2fe8fb19SBen Gras extern int floatx80_rounding_precision; 241*2fe8fb19SBen Gras 242*2fe8fb19SBen Gras /* 243*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 244*2fe8fb19SBen Gras Software IEC/IEEE extended double-precision operations. 245*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 246*2fe8fb19SBen Gras */ 247*2fe8fb19SBen Gras floatx80 floatx80_round_to_int( floatx80 ); 248*2fe8fb19SBen Gras floatx80 floatx80_add( floatx80, floatx80 ); 249*2fe8fb19SBen Gras floatx80 floatx80_sub( floatx80, floatx80 ); 250*2fe8fb19SBen Gras floatx80 floatx80_mul( floatx80, floatx80 ); 251*2fe8fb19SBen Gras floatx80 floatx80_div( floatx80, floatx80 ); 252*2fe8fb19SBen Gras floatx80 floatx80_rem( floatx80, floatx80 ); 253*2fe8fb19SBen Gras floatx80 floatx80_sqrt( floatx80 ); 254*2fe8fb19SBen Gras flag floatx80_eq( floatx80, floatx80 ); 255*2fe8fb19SBen Gras flag floatx80_le( floatx80, floatx80 ); 256*2fe8fb19SBen Gras flag floatx80_lt( floatx80, floatx80 ); 257*2fe8fb19SBen Gras flag floatx80_eq_signaling( floatx80, floatx80 ); 258*2fe8fb19SBen Gras flag floatx80_le_quiet( floatx80, floatx80 ); 259*2fe8fb19SBen Gras flag floatx80_lt_quiet( floatx80, floatx80 ); 260*2fe8fb19SBen Gras flag floatx80_is_signaling_nan( floatx80 ); 261*2fe8fb19SBen Gras 262*2fe8fb19SBen Gras #endif 263*2fe8fb19SBen Gras 264*2fe8fb19SBen Gras #ifdef FLOAT128 265*2fe8fb19SBen Gras 266*2fe8fb19SBen Gras /* 267*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 268*2fe8fb19SBen Gras Software IEC/IEEE quadruple-precision conversion routines. 269*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 270*2fe8fb19SBen Gras */ 271*2fe8fb19SBen Gras int float128_to_int32( float128 ); 272*2fe8fb19SBen Gras int float128_to_int32_round_to_zero( float128 ); 273*2fe8fb19SBen Gras long long float128_to_int64( float128 ); 274*2fe8fb19SBen Gras long long float128_to_int64_round_to_zero( float128 ); 275*2fe8fb19SBen Gras unsigned long long float128_to_uint64_round_to_zero( float128 ); 276*2fe8fb19SBen Gras float32 float128_to_float32( float128 ); 277*2fe8fb19SBen Gras float64 float128_to_float64( float128 ); 278*2fe8fb19SBen Gras #ifdef FLOATX80 279*2fe8fb19SBen Gras floatx80 float128_to_floatx80( float128 ); 280*2fe8fb19SBen Gras #endif 281*2fe8fb19SBen Gras 282*2fe8fb19SBen Gras /* 283*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 284*2fe8fb19SBen Gras Software IEC/IEEE quadruple-precision operations. 285*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 286*2fe8fb19SBen Gras */ 287*2fe8fb19SBen Gras float128 float128_round_to_int( float128 ); 288*2fe8fb19SBen Gras float128 float128_add( float128, float128 ); 289*2fe8fb19SBen Gras float128 float128_sub( float128, float128 ); 290*2fe8fb19SBen Gras float128 float128_mul( float128, float128 ); 291*2fe8fb19SBen Gras float128 float128_div( float128, float128 ); 292*2fe8fb19SBen Gras float128 float128_rem( float128, float128 ); 293*2fe8fb19SBen Gras float128 float128_sqrt( float128 ); 294*2fe8fb19SBen Gras flag float128_eq( float128, float128 ); 295*2fe8fb19SBen Gras flag float128_le( float128, float128 ); 296*2fe8fb19SBen Gras flag float128_lt( float128, float128 ); 297*2fe8fb19SBen Gras flag float128_eq_signaling( float128, float128 ); 298*2fe8fb19SBen Gras flag float128_le_quiet( float128, float128 ); 299*2fe8fb19SBen Gras flag float128_lt_quiet( float128, float128 ); 300*2fe8fb19SBen Gras flag float128_is_signaling_nan( float128 ); 301*2fe8fb19SBen Gras flag float128_is_nan( float128 ); 302*2fe8fb19SBen Gras 303*2fe8fb19SBen Gras #endif 304