1*2fe8fb19SBen Gras /* $NetBSD: softfloat.h,v 1.7 2006/05/16 20:55:51 mrg 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 <machine/ieeefp.h> 48*2fe8fb19SBen Gras 49*2fe8fb19SBen Gras /* 50*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 51*2fe8fb19SBen Gras Software IEC/IEEE floating-point types. 52*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 53*2fe8fb19SBen Gras */ 54*2fe8fb19SBen Gras typedef unsigned int float32; 55*2fe8fb19SBen Gras typedef unsigned long long float64; 56*2fe8fb19SBen Gras #ifdef FLOATX80 57*2fe8fb19SBen Gras typedef struct { 58*2fe8fb19SBen Gras unsigned short high; 59*2fe8fb19SBen Gras unsigned long long low; 60*2fe8fb19SBen Gras } floatx80; 61*2fe8fb19SBen Gras #endif 62*2fe8fb19SBen Gras #ifdef FLOAT128 63*2fe8fb19SBen Gras typedef struct { 64*2fe8fb19SBen Gras unsigned long long high, low; 65*2fe8fb19SBen Gras } float128; 66*2fe8fb19SBen Gras #endif 67*2fe8fb19SBen Gras 68*2fe8fb19SBen Gras /* 69*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 70*2fe8fb19SBen Gras Software IEC/IEEE floating-point underflow tininess-detection mode. 71*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 72*2fe8fb19SBen Gras */ 73*2fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC 74*2fe8fb19SBen Gras extern int float_detect_tininess; 75*2fe8fb19SBen Gras #endif 76*2fe8fb19SBen Gras enum { 77*2fe8fb19SBen Gras float_tininess_after_rounding = 0, 78*2fe8fb19SBen Gras float_tininess_before_rounding = 1 79*2fe8fb19SBen Gras }; 80*2fe8fb19SBen Gras 81*2fe8fb19SBen Gras /* 82*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 83*2fe8fb19SBen Gras Software IEC/IEEE floating-point rounding mode. 84*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 85*2fe8fb19SBen Gras */ 86*2fe8fb19SBen Gras extern fp_rnd float_rounding_mode; 87*2fe8fb19SBen Gras enum { 88*2fe8fb19SBen Gras float_round_nearest_even = FP_RN, 89*2fe8fb19SBen Gras float_round_to_zero = FP_RZ, 90*2fe8fb19SBen Gras float_round_down = FP_RM, 91*2fe8fb19SBen Gras float_round_up = FP_RP 92*2fe8fb19SBen Gras }; 93*2fe8fb19SBen Gras 94*2fe8fb19SBen Gras /* 95*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 96*2fe8fb19SBen Gras Software IEC/IEEE floating-point exception flags. 97*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 98*2fe8fb19SBen Gras */ 99*2fe8fb19SBen Gras extern fp_except float_exception_flags; 100*2fe8fb19SBen Gras extern fp_except float_exception_mask; 101*2fe8fb19SBen Gras enum { 102*2fe8fb19SBen Gras float_flag_inexact = FP_X_IMP, 103*2fe8fb19SBen Gras float_flag_underflow = FP_X_UFL, 104*2fe8fb19SBen Gras float_flag_overflow = FP_X_OFL, 105*2fe8fb19SBen Gras float_flag_divbyzero = FP_X_DZ, 106*2fe8fb19SBen Gras float_flag_invalid = FP_X_INV 107*2fe8fb19SBen Gras }; 108*2fe8fb19SBen Gras 109*2fe8fb19SBen Gras /* 110*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 111*2fe8fb19SBen Gras Routine to raise any or all of the software IEC/IEEE floating-point 112*2fe8fb19SBen Gras exception flags. 113*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 114*2fe8fb19SBen Gras */ 115*2fe8fb19SBen Gras void float_raise( fp_except ); 116*2fe8fb19SBen Gras 117*2fe8fb19SBen Gras /* 118*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 119*2fe8fb19SBen Gras Software IEC/IEEE integer-to-floating-point conversion routines. 120*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 121*2fe8fb19SBen Gras */ 122*2fe8fb19SBen Gras float32 int32_to_float32( int ); 123*2fe8fb19SBen Gras float64 int32_to_float64( int ); 124*2fe8fb19SBen Gras #ifdef FLOATX80 125*2fe8fb19SBen Gras floatx80 int32_to_floatx80( int ); 126*2fe8fb19SBen Gras #endif 127*2fe8fb19SBen Gras #ifdef FLOAT128 128*2fe8fb19SBen Gras float128 int32_to_float128( int ); 129*2fe8fb19SBen Gras #endif 130*2fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC /* __floatdi?f is in libgcc2.c */ 131*2fe8fb19SBen Gras float32 int64_to_float32( long long ); 132*2fe8fb19SBen Gras float64 int64_to_float64( long long ); 133*2fe8fb19SBen Gras #ifdef FLOATX80 134*2fe8fb19SBen Gras floatx80 int64_to_floatx80( long long ); 135*2fe8fb19SBen Gras #endif 136*2fe8fb19SBen Gras #ifdef FLOAT128 137*2fe8fb19SBen Gras float128 int64_to_float128( long long ); 138*2fe8fb19SBen Gras #endif 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 #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS) 149*2fe8fb19SBen Gras unsigned int float32_to_uint32_round_to_zero( float32 ); 150*2fe8fb19SBen Gras #endif 151*2fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */ 152*2fe8fb19SBen Gras long long float32_to_int64( float32 ); 153*2fe8fb19SBen Gras long long float32_to_int64_round_to_zero( float32 ); 154*2fe8fb19SBen Gras #endif 155*2fe8fb19SBen Gras float64 float32_to_float64( float32 ); 156*2fe8fb19SBen Gras #ifdef FLOATX80 157*2fe8fb19SBen Gras floatx80 float32_to_floatx80( float32 ); 158*2fe8fb19SBen Gras #endif 159*2fe8fb19SBen Gras #ifdef FLOAT128 160*2fe8fb19SBen Gras float128 float32_to_float128( float32 ); 161*2fe8fb19SBen Gras #endif 162*2fe8fb19SBen Gras 163*2fe8fb19SBen Gras /* 164*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 165*2fe8fb19SBen Gras Software IEC/IEEE single-precision operations. 166*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 167*2fe8fb19SBen Gras */ 168*2fe8fb19SBen Gras float32 float32_round_to_int( float32 ); 169*2fe8fb19SBen Gras float32 float32_add( float32, float32 ); 170*2fe8fb19SBen Gras float32 float32_sub( float32, float32 ); 171*2fe8fb19SBen Gras float32 float32_mul( float32, float32 ); 172*2fe8fb19SBen Gras float32 float32_div( float32, float32 ); 173*2fe8fb19SBen Gras float32 float32_rem( float32, float32 ); 174*2fe8fb19SBen Gras float32 float32_sqrt( float32 ); 175*2fe8fb19SBen Gras int float32_eq( float32, float32 ); 176*2fe8fb19SBen Gras int float32_le( float32, float32 ); 177*2fe8fb19SBen Gras int float32_lt( float32, float32 ); 178*2fe8fb19SBen Gras int float32_eq_signaling( float32, float32 ); 179*2fe8fb19SBen Gras int float32_le_quiet( float32, float32 ); 180*2fe8fb19SBen Gras int float32_lt_quiet( float32, float32 ); 181*2fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC 182*2fe8fb19SBen Gras int float32_is_signaling_nan( float32 ); 183*2fe8fb19SBen Gras #endif 184*2fe8fb19SBen Gras 185*2fe8fb19SBen Gras /* 186*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 187*2fe8fb19SBen Gras Software IEC/IEEE double-precision conversion routines. 188*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 189*2fe8fb19SBen Gras */ 190*2fe8fb19SBen Gras int float64_to_int32( float64 ); 191*2fe8fb19SBen Gras int float64_to_int32_round_to_zero( float64 ); 192*2fe8fb19SBen Gras #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS) 193*2fe8fb19SBen Gras unsigned int float64_to_uint32_round_to_zero( float64 ); 194*2fe8fb19SBen Gras #endif 195*2fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */ 196*2fe8fb19SBen Gras long long float64_to_int64( float64 ); 197*2fe8fb19SBen Gras long long float64_to_int64_round_to_zero( float64 ); 198*2fe8fb19SBen Gras #endif 199*2fe8fb19SBen Gras float32 float64_to_float32( float64 ); 200*2fe8fb19SBen Gras #ifdef FLOATX80 201*2fe8fb19SBen Gras floatx80 float64_to_floatx80( float64 ); 202*2fe8fb19SBen Gras #endif 203*2fe8fb19SBen Gras #ifdef FLOAT128 204*2fe8fb19SBen Gras float128 float64_to_float128( float64 ); 205*2fe8fb19SBen Gras #endif 206*2fe8fb19SBen Gras 207*2fe8fb19SBen Gras /* 208*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 209*2fe8fb19SBen Gras Software IEC/IEEE double-precision operations. 210*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 211*2fe8fb19SBen Gras */ 212*2fe8fb19SBen Gras float64 float64_round_to_int( float64 ); 213*2fe8fb19SBen Gras float64 float64_add( float64, float64 ); 214*2fe8fb19SBen Gras float64 float64_sub( float64, float64 ); 215*2fe8fb19SBen Gras float64 float64_mul( float64, float64 ); 216*2fe8fb19SBen Gras float64 float64_div( float64, float64 ); 217*2fe8fb19SBen Gras float64 float64_rem( float64, float64 ); 218*2fe8fb19SBen Gras float64 float64_sqrt( float64 ); 219*2fe8fb19SBen Gras int float64_eq( float64, float64 ); 220*2fe8fb19SBen Gras int float64_le( float64, float64 ); 221*2fe8fb19SBen Gras int float64_lt( float64, float64 ); 222*2fe8fb19SBen Gras int float64_eq_signaling( float64, float64 ); 223*2fe8fb19SBen Gras int float64_le_quiet( float64, float64 ); 224*2fe8fb19SBen Gras int float64_lt_quiet( float64, float64 ); 225*2fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC 226*2fe8fb19SBen Gras int float64_is_signaling_nan( float64 ); 227*2fe8fb19SBen Gras #endif 228*2fe8fb19SBen Gras 229*2fe8fb19SBen Gras #ifdef FLOATX80 230*2fe8fb19SBen Gras 231*2fe8fb19SBen Gras /* 232*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 233*2fe8fb19SBen Gras Software IEC/IEEE extended double-precision conversion routines. 234*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 235*2fe8fb19SBen Gras */ 236*2fe8fb19SBen Gras int floatx80_to_int32( floatx80 ); 237*2fe8fb19SBen Gras int floatx80_to_int32_round_to_zero( floatx80 ); 238*2fe8fb19SBen Gras long long floatx80_to_int64( floatx80 ); 239*2fe8fb19SBen Gras long long floatx80_to_int64_round_to_zero( floatx80 ); 240*2fe8fb19SBen Gras float32 floatx80_to_float32( floatx80 ); 241*2fe8fb19SBen Gras float64 floatx80_to_float64( floatx80 ); 242*2fe8fb19SBen Gras #ifdef FLOAT128 243*2fe8fb19SBen Gras float128 floatx80_to_float128( floatx80 ); 244*2fe8fb19SBen Gras #endif 245*2fe8fb19SBen Gras 246*2fe8fb19SBen Gras /* 247*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 248*2fe8fb19SBen Gras Software IEC/IEEE extended double-precision rounding precision. Valid 249*2fe8fb19SBen Gras values are 32, 64, and 80. 250*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 251*2fe8fb19SBen Gras */ 252*2fe8fb19SBen Gras extern int floatx80_rounding_precision; 253*2fe8fb19SBen Gras 254*2fe8fb19SBen Gras /* 255*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 256*2fe8fb19SBen Gras Software IEC/IEEE extended double-precision operations. 257*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 258*2fe8fb19SBen Gras */ 259*2fe8fb19SBen Gras floatx80 floatx80_round_to_int( floatx80 ); 260*2fe8fb19SBen Gras floatx80 floatx80_add( floatx80, floatx80 ); 261*2fe8fb19SBen Gras floatx80 floatx80_sub( floatx80, floatx80 ); 262*2fe8fb19SBen Gras floatx80 floatx80_mul( floatx80, floatx80 ); 263*2fe8fb19SBen Gras floatx80 floatx80_div( floatx80, floatx80 ); 264*2fe8fb19SBen Gras floatx80 floatx80_rem( floatx80, floatx80 ); 265*2fe8fb19SBen Gras floatx80 floatx80_sqrt( floatx80 ); 266*2fe8fb19SBen Gras int floatx80_eq( floatx80, floatx80 ); 267*2fe8fb19SBen Gras int floatx80_le( floatx80, floatx80 ); 268*2fe8fb19SBen Gras int floatx80_lt( floatx80, floatx80 ); 269*2fe8fb19SBen Gras int floatx80_eq_signaling( floatx80, floatx80 ); 270*2fe8fb19SBen Gras int floatx80_le_quiet( floatx80, floatx80 ); 271*2fe8fb19SBen Gras int floatx80_lt_quiet( floatx80, floatx80 ); 272*2fe8fb19SBen Gras int floatx80_is_signaling_nan( floatx80 ); 273*2fe8fb19SBen Gras 274*2fe8fb19SBen Gras #endif 275*2fe8fb19SBen Gras 276*2fe8fb19SBen Gras #ifdef FLOAT128 277*2fe8fb19SBen Gras 278*2fe8fb19SBen Gras /* 279*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 280*2fe8fb19SBen Gras Software IEC/IEEE quadruple-precision conversion routines. 281*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 282*2fe8fb19SBen Gras */ 283*2fe8fb19SBen Gras int float128_to_int32( float128 ); 284*2fe8fb19SBen Gras int float128_to_int32_round_to_zero( float128 ); 285*2fe8fb19SBen Gras long long float128_to_int64( float128 ); 286*2fe8fb19SBen Gras long long float128_to_int64_round_to_zero( float128 ); 287*2fe8fb19SBen Gras float32 float128_to_float32( float128 ); 288*2fe8fb19SBen Gras float64 float128_to_float64( float128 ); 289*2fe8fb19SBen Gras #ifdef FLOATX80 290*2fe8fb19SBen Gras floatx80 float128_to_floatx80( float128 ); 291*2fe8fb19SBen Gras #endif 292*2fe8fb19SBen Gras 293*2fe8fb19SBen Gras /* 294*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 295*2fe8fb19SBen Gras Software IEC/IEEE quadruple-precision operations. 296*2fe8fb19SBen Gras ------------------------------------------------------------------------------- 297*2fe8fb19SBen Gras */ 298*2fe8fb19SBen Gras float128 float128_round_to_int( float128 ); 299*2fe8fb19SBen Gras float128 float128_add( float128, float128 ); 300*2fe8fb19SBen Gras float128 float128_sub( float128, float128 ); 301*2fe8fb19SBen Gras float128 float128_mul( float128, float128 ); 302*2fe8fb19SBen Gras float128 float128_div( float128, float128 ); 303*2fe8fb19SBen Gras float128 float128_rem( float128, float128 ); 304*2fe8fb19SBen Gras float128 float128_sqrt( float128 ); 305*2fe8fb19SBen Gras int float128_eq( float128, float128 ); 306*2fe8fb19SBen Gras int float128_le( float128, float128 ); 307*2fe8fb19SBen Gras int float128_lt( float128, float128 ); 308*2fe8fb19SBen Gras int float128_eq_signaling( float128, float128 ); 309*2fe8fb19SBen Gras int float128_le_quiet( float128, float128 ); 310*2fe8fb19SBen Gras int float128_lt_quiet( float128, float128 ); 311*2fe8fb19SBen Gras int float128_is_signaling_nan( float128 ); 312*2fe8fb19SBen Gras 313*2fe8fb19SBen Gras #endif 314*2fe8fb19SBen Gras 315