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