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