115144b0fSOlivier Houchard 215144b0fSOlivier Houchard /* 315144b0fSOlivier Houchard =============================================================================== 415144b0fSOlivier Houchard 515144b0fSOlivier Houchard This C header file is part of the SoftFloat IEC/IEEE Floating-point 615144b0fSOlivier Houchard Arithmetic Package, Release 2a. 715144b0fSOlivier Houchard 815144b0fSOlivier Houchard Written by John R. Hauser. This work was made possible in part by the 915144b0fSOlivier Houchard International Computer Science Institute, located at Suite 600, 1947 Center 1015144b0fSOlivier Houchard Street, Berkeley, California 94704. Funding was partially provided by the 1115144b0fSOlivier Houchard National Science Foundation under grant MIP-9311980. The original version 1215144b0fSOlivier Houchard of this code was written as part of a project to build a fixed-point vector 1315144b0fSOlivier Houchard processor in collaboration with the University of California at Berkeley, 1415144b0fSOlivier Houchard overseen by Profs. Nelson Morgan and John Wawrzynek. More information 1515144b0fSOlivier Houchard is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/ 1615144b0fSOlivier Houchard arithmetic/SoftFloat.html'. 1715144b0fSOlivier Houchard 1815144b0fSOlivier Houchard THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort 1915144b0fSOlivier Houchard has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT 2015144b0fSOlivier Houchard TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO 2115144b0fSOlivier Houchard PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY 2215144b0fSOlivier Houchard AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. 2315144b0fSOlivier Houchard 2415144b0fSOlivier Houchard Derivative works are acceptable, even for commercial purposes, so long as 2515144b0fSOlivier Houchard (1) they include prominent notice that the work is derivative, and (2) they 2615144b0fSOlivier Houchard include prominent notice akin to these four paragraphs for those parts of 2715144b0fSOlivier Houchard this code that are retained. 2815144b0fSOlivier Houchard 2915144b0fSOlivier Houchard =============================================================================== 3015144b0fSOlivier Houchard */ 3115144b0fSOlivier Houchard 3215144b0fSOlivier Houchard /* 3315144b0fSOlivier Houchard ------------------------------------------------------------------------------- 3415144b0fSOlivier Houchard The macro `FLOATX80' must be defined to enable the extended double-precision 3515144b0fSOlivier Houchard floating-point format `floatx80'. If this macro is not defined, the 3615144b0fSOlivier Houchard `floatx80' type will not be defined, and none of the functions that either 3715144b0fSOlivier Houchard input or output the `floatx80' type will be defined. The same applies to 3815144b0fSOlivier Houchard the `FLOAT128' macro and the quadruple-precision format `float128'. 3915144b0fSOlivier Houchard ------------------------------------------------------------------------------- 4015144b0fSOlivier Houchard */ 4115144b0fSOlivier Houchard #define FLOATX80 4215144b0fSOlivier Houchard #define FLOAT128 4315144b0fSOlivier Houchard 4415144b0fSOlivier Houchard /* 4515144b0fSOlivier Houchard ------------------------------------------------------------------------------- 4615144b0fSOlivier Houchard Software IEC/IEEE floating-point types. 4715144b0fSOlivier Houchard ------------------------------------------------------------------------------- 4815144b0fSOlivier Houchard */ 4915144b0fSOlivier Houchard typedef !!!bits32 float32; 5015144b0fSOlivier Houchard typedef !!!bits64 float64; 5115144b0fSOlivier Houchard #ifdef FLOATX80 5215144b0fSOlivier Houchard typedef struct { 5315144b0fSOlivier Houchard !!!bits16 high; 5415144b0fSOlivier Houchard !!!bits64 low; 5515144b0fSOlivier Houchard } floatx80; 5615144b0fSOlivier Houchard #endif 5715144b0fSOlivier Houchard #ifdef FLOAT128 5815144b0fSOlivier Houchard typedef struct { 5915144b0fSOlivier Houchard !!!bits64 high, low; 6015144b0fSOlivier Houchard } float128; 6115144b0fSOlivier Houchard #endif 6215144b0fSOlivier Houchard 6315144b0fSOlivier Houchard /* 6415144b0fSOlivier Houchard ------------------------------------------------------------------------------- 6515144b0fSOlivier Houchard Software IEC/IEEE floating-point underflow tininess-detection mode. 6615144b0fSOlivier Houchard ------------------------------------------------------------------------------- 6715144b0fSOlivier Houchard */ 6815144b0fSOlivier Houchard extern !!!int8 float_detect_tininess; 6915144b0fSOlivier Houchard enum { 7015144b0fSOlivier Houchard float_tininess_after_rounding = 0, 7115144b0fSOlivier Houchard float_tininess_before_rounding = 1 7215144b0fSOlivier Houchard }; 7315144b0fSOlivier Houchard 7415144b0fSOlivier Houchard /* 7515144b0fSOlivier Houchard ------------------------------------------------------------------------------- 7615144b0fSOlivier Houchard Software IEC/IEEE floating-point rounding mode. 7715144b0fSOlivier Houchard ------------------------------------------------------------------------------- 7815144b0fSOlivier Houchard */ 7915144b0fSOlivier Houchard extern !!!int8 float_rounding_mode; 8015144b0fSOlivier Houchard enum { 8115144b0fSOlivier Houchard float_round_nearest_even = 0, 8215144b0fSOlivier Houchard float_round_to_zero = 1, 8315144b0fSOlivier Houchard float_round_down = 2, 8415144b0fSOlivier Houchard float_round_up = 3 8515144b0fSOlivier Houchard }; 8615144b0fSOlivier Houchard 8715144b0fSOlivier Houchard /* 8815144b0fSOlivier Houchard ------------------------------------------------------------------------------- 8915144b0fSOlivier Houchard Software IEC/IEEE floating-point exception flags. 9015144b0fSOlivier Houchard ------------------------------------------------------------------------------- 9115144b0fSOlivier Houchard */ 9215144b0fSOlivier Houchard extern !!!int8 float_exception_flags; 9315144b0fSOlivier Houchard enum { 9415144b0fSOlivier Houchard float_flag_inexact = 1, 9515144b0fSOlivier Houchard float_flag_underflow = 2, 9615144b0fSOlivier Houchard float_flag_overflow = 4, 9715144b0fSOlivier Houchard float_flag_divbyzero = 8, 9815144b0fSOlivier Houchard float_flag_invalid = 16 9915144b0fSOlivier Houchard }; 10015144b0fSOlivier Houchard 10115144b0fSOlivier Houchard /* 10215144b0fSOlivier Houchard ------------------------------------------------------------------------------- 10315144b0fSOlivier Houchard Routine to raise any or all of the software IEC/IEEE floating-point 10415144b0fSOlivier Houchard exception flags. 10515144b0fSOlivier Houchard ------------------------------------------------------------------------------- 10615144b0fSOlivier Houchard */ 10715144b0fSOlivier Houchard void float_raise( !!!int8 ); 10815144b0fSOlivier Houchard 10915144b0fSOlivier Houchard /* 11015144b0fSOlivier Houchard ------------------------------------------------------------------------------- 11115144b0fSOlivier Houchard Software IEC/IEEE integer-to-floating-point conversion routines. 11215144b0fSOlivier Houchard ------------------------------------------------------------------------------- 11315144b0fSOlivier Houchard */ 11415144b0fSOlivier Houchard float32 int32_to_float32( !!!int32 ); 11515144b0fSOlivier Houchard float64 int32_to_float64( !!!int32 ); 11615144b0fSOlivier Houchard #ifdef FLOATX80 11715144b0fSOlivier Houchard floatx80 int32_to_floatx80( !!!int32 ); 11815144b0fSOlivier Houchard #endif 11915144b0fSOlivier Houchard #ifdef FLOAT128 12015144b0fSOlivier Houchard float128 int32_to_float128( !!!int32 ); 12115144b0fSOlivier Houchard #endif 12215144b0fSOlivier Houchard float32 int64_to_float32( !!!int64 ); 12315144b0fSOlivier Houchard float64 int64_to_float64( !!!int64 ); 12415144b0fSOlivier Houchard #ifdef FLOATX80 12515144b0fSOlivier Houchard floatx80 int64_to_floatx80( !!!int64 ); 12615144b0fSOlivier Houchard #endif 12715144b0fSOlivier Houchard #ifdef FLOAT128 12815144b0fSOlivier Houchard float128 int64_to_float128( !!!int64 ); 12915144b0fSOlivier Houchard #endif 13015144b0fSOlivier Houchard 13115144b0fSOlivier Houchard /* 13215144b0fSOlivier Houchard ------------------------------------------------------------------------------- 13315144b0fSOlivier Houchard Software IEC/IEEE single-precision conversion routines. 13415144b0fSOlivier Houchard ------------------------------------------------------------------------------- 13515144b0fSOlivier Houchard */ 13615144b0fSOlivier Houchard !!!int32 float32_to_int32( float32 ); 13715144b0fSOlivier Houchard !!!int32 float32_to_int32_round_to_zero( float32 ); 13815144b0fSOlivier Houchard !!!int64 float32_to_int64( float32 ); 13915144b0fSOlivier Houchard !!!int64 float32_to_int64_round_to_zero( float32 ); 14015144b0fSOlivier Houchard float64 float32_to_float64( float32 ); 14115144b0fSOlivier Houchard #ifdef FLOATX80 14215144b0fSOlivier Houchard floatx80 float32_to_floatx80( float32 ); 14315144b0fSOlivier Houchard #endif 14415144b0fSOlivier Houchard #ifdef FLOAT128 14515144b0fSOlivier Houchard float128 float32_to_float128( float32 ); 14615144b0fSOlivier Houchard #endif 14715144b0fSOlivier Houchard 14815144b0fSOlivier Houchard /* 14915144b0fSOlivier Houchard ------------------------------------------------------------------------------- 15015144b0fSOlivier Houchard Software IEC/IEEE single-precision operations. 15115144b0fSOlivier Houchard ------------------------------------------------------------------------------- 15215144b0fSOlivier Houchard */ 15315144b0fSOlivier Houchard float32 float32_round_to_int( float32 ); 15415144b0fSOlivier Houchard float32 float32_add( float32, float32 ); 15515144b0fSOlivier Houchard float32 float32_sub( float32, float32 ); 15615144b0fSOlivier Houchard float32 float32_mul( float32, float32 ); 15715144b0fSOlivier Houchard float32 float32_div( float32, float32 ); 15815144b0fSOlivier Houchard float32 float32_rem( float32, float32 ); 15915144b0fSOlivier Houchard float32 float32_sqrt( float32 ); 16015144b0fSOlivier Houchard !!!flag float32_eq( float32, float32 ); 16115144b0fSOlivier Houchard !!!flag float32_le( float32, float32 ); 16215144b0fSOlivier Houchard !!!flag float32_lt( float32, float32 ); 16315144b0fSOlivier Houchard !!!flag float32_eq_signaling( float32, float32 ); 16415144b0fSOlivier Houchard !!!flag float32_le_quiet( float32, float32 ); 16515144b0fSOlivier Houchard !!!flag float32_lt_quiet( float32, float32 ); 16615144b0fSOlivier Houchard !!!flag float32_is_signaling_nan( float32 ); 16715144b0fSOlivier Houchard 16815144b0fSOlivier Houchard /* 16915144b0fSOlivier Houchard ------------------------------------------------------------------------------- 17015144b0fSOlivier Houchard Software IEC/IEEE double-precision conversion routines. 17115144b0fSOlivier Houchard ------------------------------------------------------------------------------- 17215144b0fSOlivier Houchard */ 17315144b0fSOlivier Houchard !!!int32 float64_to_int32( float64 ); 17415144b0fSOlivier Houchard !!!int32 float64_to_int32_round_to_zero( float64 ); 17515144b0fSOlivier Houchard !!!int64 float64_to_int64( float64 ); 17615144b0fSOlivier Houchard !!!int64 float64_to_int64_round_to_zero( float64 ); 17715144b0fSOlivier Houchard float32 float64_to_float32( float64 ); 17815144b0fSOlivier Houchard #ifdef FLOATX80 17915144b0fSOlivier Houchard floatx80 float64_to_floatx80( float64 ); 18015144b0fSOlivier Houchard #endif 18115144b0fSOlivier Houchard #ifdef FLOAT128 18215144b0fSOlivier Houchard float128 float64_to_float128( float64 ); 18315144b0fSOlivier Houchard #endif 18415144b0fSOlivier Houchard 18515144b0fSOlivier Houchard /* 18615144b0fSOlivier Houchard ------------------------------------------------------------------------------- 18715144b0fSOlivier Houchard Software IEC/IEEE double-precision operations. 18815144b0fSOlivier Houchard ------------------------------------------------------------------------------- 18915144b0fSOlivier Houchard */ 19015144b0fSOlivier Houchard float64 float64_round_to_int( float64 ); 19115144b0fSOlivier Houchard float64 float64_add( float64, float64 ); 19215144b0fSOlivier Houchard float64 float64_sub( float64, float64 ); 19315144b0fSOlivier Houchard float64 float64_mul( float64, float64 ); 19415144b0fSOlivier Houchard float64 float64_div( float64, float64 ); 19515144b0fSOlivier Houchard float64 float64_rem( float64, float64 ); 19615144b0fSOlivier Houchard float64 float64_sqrt( float64 ); 19715144b0fSOlivier Houchard !!!flag float64_eq( float64, float64 ); 19815144b0fSOlivier Houchard !!!flag float64_le( float64, float64 ); 19915144b0fSOlivier Houchard !!!flag float64_lt( float64, float64 ); 20015144b0fSOlivier Houchard !!!flag float64_eq_signaling( float64, float64 ); 20115144b0fSOlivier Houchard !!!flag float64_le_quiet( float64, float64 ); 20215144b0fSOlivier Houchard !!!flag float64_lt_quiet( float64, float64 ); 20315144b0fSOlivier Houchard !!!flag float64_is_signaling_nan( float64 ); 20415144b0fSOlivier Houchard 20515144b0fSOlivier Houchard #ifdef FLOATX80 20615144b0fSOlivier Houchard 20715144b0fSOlivier Houchard /* 20815144b0fSOlivier Houchard ------------------------------------------------------------------------------- 20915144b0fSOlivier Houchard Software IEC/IEEE extended double-precision conversion routines. 21015144b0fSOlivier Houchard ------------------------------------------------------------------------------- 21115144b0fSOlivier Houchard */ 21215144b0fSOlivier Houchard !!!int32 floatx80_to_int32( floatx80 ); 21315144b0fSOlivier Houchard !!!int32 floatx80_to_int32_round_to_zero( floatx80 ); 21415144b0fSOlivier Houchard !!!int64 floatx80_to_int64( floatx80 ); 21515144b0fSOlivier Houchard !!!int64 floatx80_to_int64_round_to_zero( floatx80 ); 21615144b0fSOlivier Houchard float32 floatx80_to_float32( floatx80 ); 21715144b0fSOlivier Houchard float64 floatx80_to_float64( floatx80 ); 21815144b0fSOlivier Houchard #ifdef FLOAT128 21915144b0fSOlivier Houchard float128 floatx80_to_float128( floatx80 ); 22015144b0fSOlivier Houchard #endif 22115144b0fSOlivier Houchard 22215144b0fSOlivier Houchard /* 22315144b0fSOlivier Houchard ------------------------------------------------------------------------------- 22415144b0fSOlivier Houchard Software IEC/IEEE extended double-precision rounding precision. Valid 22515144b0fSOlivier Houchard values are 32, 64, and 80. 22615144b0fSOlivier Houchard ------------------------------------------------------------------------------- 22715144b0fSOlivier Houchard */ 22815144b0fSOlivier Houchard extern !!!int8 floatx80_rounding_precision; 22915144b0fSOlivier Houchard 23015144b0fSOlivier Houchard /* 23115144b0fSOlivier Houchard ------------------------------------------------------------------------------- 23215144b0fSOlivier Houchard Software IEC/IEEE extended double-precision operations. 23315144b0fSOlivier Houchard ------------------------------------------------------------------------------- 23415144b0fSOlivier Houchard */ 23515144b0fSOlivier Houchard floatx80 floatx80_round_to_int( floatx80 ); 23615144b0fSOlivier Houchard floatx80 floatx80_add( floatx80, floatx80 ); 23715144b0fSOlivier Houchard floatx80 floatx80_sub( floatx80, floatx80 ); 23815144b0fSOlivier Houchard floatx80 floatx80_mul( floatx80, floatx80 ); 23915144b0fSOlivier Houchard floatx80 floatx80_div( floatx80, floatx80 ); 24015144b0fSOlivier Houchard floatx80 floatx80_rem( floatx80, floatx80 ); 24115144b0fSOlivier Houchard floatx80 floatx80_sqrt( floatx80 ); 24215144b0fSOlivier Houchard !!!flag floatx80_eq( floatx80, floatx80 ); 24315144b0fSOlivier Houchard !!!flag floatx80_le( floatx80, floatx80 ); 24415144b0fSOlivier Houchard !!!flag floatx80_lt( floatx80, floatx80 ); 24515144b0fSOlivier Houchard !!!flag floatx80_eq_signaling( floatx80, floatx80 ); 24615144b0fSOlivier Houchard !!!flag floatx80_le_quiet( floatx80, floatx80 ); 24715144b0fSOlivier Houchard !!!flag floatx80_lt_quiet( floatx80, floatx80 ); 24815144b0fSOlivier Houchard !!!flag floatx80_is_signaling_nan( floatx80 ); 24915144b0fSOlivier Houchard 25015144b0fSOlivier Houchard #endif 25115144b0fSOlivier Houchard 25215144b0fSOlivier Houchard #ifdef FLOAT128 25315144b0fSOlivier Houchard 25415144b0fSOlivier Houchard /* 25515144b0fSOlivier Houchard ------------------------------------------------------------------------------- 25615144b0fSOlivier Houchard Software IEC/IEEE quadruple-precision conversion routines. 25715144b0fSOlivier Houchard ------------------------------------------------------------------------------- 25815144b0fSOlivier Houchard */ 25915144b0fSOlivier Houchard !!!int32 float128_to_int32( float128 ); 26015144b0fSOlivier Houchard !!!int32 float128_to_int32_round_to_zero( float128 ); 26115144b0fSOlivier Houchard !!!int64 float128_to_int64( float128 ); 26215144b0fSOlivier Houchard !!!int64 float128_to_int64_round_to_zero( float128 ); 26315144b0fSOlivier Houchard float32 float128_to_float32( float128 ); 26415144b0fSOlivier Houchard float64 float128_to_float64( float128 ); 26515144b0fSOlivier Houchard #ifdef FLOATX80 26615144b0fSOlivier Houchard floatx80 float128_to_floatx80( float128 ); 26715144b0fSOlivier Houchard #endif 26815144b0fSOlivier Houchard 26915144b0fSOlivier Houchard /* 27015144b0fSOlivier Houchard ------------------------------------------------------------------------------- 27115144b0fSOlivier Houchard Software IEC/IEEE quadruple-precision operations. 27215144b0fSOlivier Houchard ------------------------------------------------------------------------------- 27315144b0fSOlivier Houchard */ 27415144b0fSOlivier Houchard float128 float128_round_to_int( float128 ); 27515144b0fSOlivier Houchard float128 float128_add( float128, float128 ); 27615144b0fSOlivier Houchard float128 float128_sub( float128, float128 ); 27715144b0fSOlivier Houchard float128 float128_mul( float128, float128 ); 27815144b0fSOlivier Houchard float128 float128_div( float128, float128 ); 27915144b0fSOlivier Houchard float128 float128_rem( float128, float128 ); 28015144b0fSOlivier Houchard float128 float128_sqrt( float128 ); 28115144b0fSOlivier Houchard !!!flag float128_eq( float128, float128 ); 28215144b0fSOlivier Houchard !!!flag float128_le( float128, float128 ); 28315144b0fSOlivier Houchard !!!flag float128_lt( float128, float128 ); 28415144b0fSOlivier Houchard !!!flag float128_eq_signaling( float128, float128 ); 28515144b0fSOlivier Houchard !!!flag float128_le_quiet( float128, float128 ); 28615144b0fSOlivier Houchard !!!flag float128_lt_quiet( float128, float128 ); 28715144b0fSOlivier Houchard !!!flag float128_is_signaling_nan( float128 ); 28815144b0fSOlivier Houchard 28915144b0fSOlivier Houchard #endif 29015144b0fSOlivier Houchard 291