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