xref: /minix3/lib/libc/arch/mips/softfloat/softfloat.h (revision e415d488727a332a2c69df018aa35e2cecf4148a)
1*e415d488SLionel Sambuc /*	$NetBSD: softfloat.h,v 1.5 2011/07/07 07:14:57 matt Exp $	*/
22fe8fb19SBen Gras 
32fe8fb19SBen Gras /* This is a derivative work. */
42fe8fb19SBen Gras 
52fe8fb19SBen Gras /*
62fe8fb19SBen Gras ===============================================================================
72fe8fb19SBen Gras 
82fe8fb19SBen Gras This C header file is part of the SoftFloat IEC/IEEE Floating-point
92fe8fb19SBen Gras Arithmetic Package, Release 2a.
102fe8fb19SBen Gras 
112fe8fb19SBen Gras Written by John R. Hauser.  This work was made possible in part by the
122fe8fb19SBen Gras International Computer Science Institute, located at Suite 600, 1947 Center
132fe8fb19SBen Gras Street, Berkeley, California 94704.  Funding was partially provided by the
142fe8fb19SBen Gras National Science Foundation under grant MIP-9311980.  The original version
152fe8fb19SBen Gras of this code was written as part of a project to build a fixed-point vector
162fe8fb19SBen Gras processor in collaboration with the University of California at Berkeley,
172fe8fb19SBen Gras overseen by Profs. Nelson Morgan and John Wawrzynek.  More information
182fe8fb19SBen Gras is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/
192fe8fb19SBen Gras arithmetic/SoftFloat.html'.
202fe8fb19SBen Gras 
212fe8fb19SBen Gras THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort
222fe8fb19SBen Gras has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
232fe8fb19SBen Gras TIMES RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO
242fe8fb19SBen Gras PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
252fe8fb19SBen Gras AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
262fe8fb19SBen Gras 
272fe8fb19SBen Gras Derivative works are acceptable, even for commercial purposes, so long as
282fe8fb19SBen Gras (1) they include prominent notice that the work is derivative, and (2) they
292fe8fb19SBen Gras include prominent notice akin to these four paragraphs for those parts of
302fe8fb19SBen Gras this code that are retained.
312fe8fb19SBen Gras 
322fe8fb19SBen Gras ===============================================================================
332fe8fb19SBen Gras */
342fe8fb19SBen Gras 
352fe8fb19SBen Gras /*
362fe8fb19SBen Gras -------------------------------------------------------------------------------
372fe8fb19SBen Gras The macro `FLOATX80' must be defined to enable the extended double-precision
382fe8fb19SBen Gras floating-point format `floatx80'.  If this macro is not defined, the
392fe8fb19SBen Gras `floatx80' type will not be defined, and none of the functions that either
402fe8fb19SBen Gras input or output the `floatx80' type will be defined.  The same applies to
412fe8fb19SBen Gras the `FLOAT128' macro and the quadruple-precision format `float128'.
422fe8fb19SBen Gras -------------------------------------------------------------------------------
432fe8fb19SBen Gras */
442fe8fb19SBen Gras /* #define FLOATX80 */
452fe8fb19SBen Gras #if defined(__mips_n32) || defined(__mips_n64)
462fe8fb19SBen Gras #define FLOAT128
472fe8fb19SBen Gras #endif
482fe8fb19SBen Gras 
492fe8fb19SBen Gras #include <machine/ieeefp.h>
502fe8fb19SBen Gras 
512fe8fb19SBen Gras /*
522fe8fb19SBen Gras -------------------------------------------------------------------------------
532fe8fb19SBen Gras Software IEC/IEEE floating-point types.
542fe8fb19SBen Gras -------------------------------------------------------------------------------
552fe8fb19SBen Gras */
562fe8fb19SBen Gras typedef unsigned int float32;
572fe8fb19SBen Gras typedef unsigned long long float64;
582fe8fb19SBen Gras #ifdef FLOATX80
592fe8fb19SBen Gras typedef struct {
602fe8fb19SBen Gras     unsigned short high;
612fe8fb19SBen Gras     unsigned long long low;
622fe8fb19SBen Gras } floatx80;
632fe8fb19SBen Gras #endif
642fe8fb19SBen Gras #ifdef FLOAT128
652fe8fb19SBen Gras typedef struct {
662fe8fb19SBen Gras     unsigned long long high, low;
672fe8fb19SBen Gras } float128;
682fe8fb19SBen Gras #endif
692fe8fb19SBen Gras 
702fe8fb19SBen Gras /*
712fe8fb19SBen Gras -------------------------------------------------------------------------------
722fe8fb19SBen Gras Software IEC/IEEE floating-point underflow tininess-detection mode.
732fe8fb19SBen Gras -------------------------------------------------------------------------------
742fe8fb19SBen Gras */
752fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC
762fe8fb19SBen Gras extern int float_detect_tininess;
772fe8fb19SBen Gras #endif
782fe8fb19SBen Gras enum {
792fe8fb19SBen Gras     float_tininess_after_rounding  = 0,
802fe8fb19SBen Gras     float_tininess_before_rounding = 1
812fe8fb19SBen Gras };
822fe8fb19SBen Gras 
832fe8fb19SBen Gras /*
842fe8fb19SBen Gras -------------------------------------------------------------------------------
852fe8fb19SBen Gras Software IEC/IEEE floating-point rounding mode.
862fe8fb19SBen Gras -------------------------------------------------------------------------------
872fe8fb19SBen Gras */
882fe8fb19SBen Gras extern fp_rnd float_rounding_mode;
89*e415d488SLionel Sambuc #define float_round_nearest_even	FP_RN
90*e415d488SLionel Sambuc #define float_round_to_zero		FP_RZ
91*e415d488SLionel Sambuc #define float_round_down		FP_RM
92*e415d488SLionel Sambuc #define float_round_up			FP_RP
932fe8fb19SBen Gras 
942fe8fb19SBen Gras /*
952fe8fb19SBen Gras -------------------------------------------------------------------------------
962fe8fb19SBen Gras Software IEC/IEEE floating-point exception flags.
972fe8fb19SBen Gras -------------------------------------------------------------------------------
982fe8fb19SBen Gras */
992fe8fb19SBen Gras extern fp_except float_exception_flags;
1002fe8fb19SBen Gras extern fp_except float_exception_mask;
1012fe8fb19SBen Gras enum {
1022fe8fb19SBen Gras     float_flag_inexact   = FP_X_IMP,
1032fe8fb19SBen Gras     float_flag_underflow = FP_X_UFL,
1042fe8fb19SBen Gras     float_flag_overflow  = FP_X_OFL,
1052fe8fb19SBen Gras     float_flag_divbyzero = FP_X_DZ,
1062fe8fb19SBen Gras     float_flag_invalid   = FP_X_INV
1072fe8fb19SBen Gras };
1082fe8fb19SBen Gras 
1092fe8fb19SBen Gras /*
1102fe8fb19SBen Gras -------------------------------------------------------------------------------
1112fe8fb19SBen Gras Routine to raise any or all of the software IEC/IEEE floating-point
1122fe8fb19SBen Gras exception flags.
1132fe8fb19SBen Gras -------------------------------------------------------------------------------
1142fe8fb19SBen Gras */
1152fe8fb19SBen Gras void float_raise( fp_except );
1162fe8fb19SBen Gras 
1172fe8fb19SBen Gras /*
1182fe8fb19SBen Gras -------------------------------------------------------------------------------
1192fe8fb19SBen Gras Software IEC/IEEE integer-to-floating-point conversion routines.
1202fe8fb19SBen Gras -------------------------------------------------------------------------------
1212fe8fb19SBen Gras */
122*e415d488SLionel Sambuc float32 int32_to_float32( int32 );
123*e415d488SLionel Sambuc float32 uint32_to_float32( uint32 );
124*e415d488SLionel Sambuc float64 int32_to_float64( int32 );
125*e415d488SLionel Sambuc float64 uint32_to_float64( uint32 );
1262fe8fb19SBen Gras #ifdef FLOATX80
127*e415d488SLionel Sambuc floatx80 int32_to_floatx80( int32 );
128*e415d488SLionel Sambuc floatx80 uint32_to_floatx80( uint32 );
1292fe8fb19SBen Gras #endif
1302fe8fb19SBen Gras #ifdef FLOAT128
131*e415d488SLionel Sambuc float128 int32_to_float128( int32 );
132*e415d488SLionel Sambuc float128 uint32_to_float128( uint32 );
1332fe8fb19SBen Gras #endif
1342fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC /* __floatdi?f is in libgcc2.c */
1352fe8fb19SBen Gras float32 int64_to_float32( long long );
1362fe8fb19SBen Gras float64 int64_to_float64( long long );
1372fe8fb19SBen Gras #ifdef FLOATX80
1382fe8fb19SBen Gras floatx80 int64_to_floatx80( long long );
1392fe8fb19SBen Gras #endif
1402fe8fb19SBen Gras #endif
1412fe8fb19SBen Gras #ifdef FLOAT128
1422fe8fb19SBen Gras float128 int64_to_float128( long long );
1432fe8fb19SBen Gras #endif
1442fe8fb19SBen Gras 
1452fe8fb19SBen Gras /*
1462fe8fb19SBen Gras -------------------------------------------------------------------------------
1472fe8fb19SBen Gras Software IEC/IEEE single-precision conversion routines.
1482fe8fb19SBen Gras -------------------------------------------------------------------------------
1492fe8fb19SBen Gras */
1502fe8fb19SBen Gras int float32_to_int32( float32 );
1512fe8fb19SBen Gras int float32_to_int32_round_to_zero( float32 );
1522fe8fb19SBen Gras #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS)
1532fe8fb19SBen Gras unsigned int float32_to_uint32_round_to_zero( float32 );
1542fe8fb19SBen Gras #endif
1552fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */
1562fe8fb19SBen Gras long long float32_to_int64( float32 );
1572fe8fb19SBen Gras long long float32_to_int64_round_to_zero( float32 );
1582fe8fb19SBen Gras #endif
1592fe8fb19SBen Gras float64 float32_to_float64( float32 );
1602fe8fb19SBen Gras #ifdef FLOATX80
1612fe8fb19SBen Gras floatx80 float32_to_floatx80( float32 );
1622fe8fb19SBen Gras #endif
1632fe8fb19SBen Gras #ifdef FLOAT128
1642fe8fb19SBen Gras float128 float32_to_float128( float32 );
1652fe8fb19SBen Gras #endif
1662fe8fb19SBen Gras 
1672fe8fb19SBen Gras /*
1682fe8fb19SBen Gras -------------------------------------------------------------------------------
1692fe8fb19SBen Gras Software IEC/IEEE single-precision operations.
1702fe8fb19SBen Gras -------------------------------------------------------------------------------
1712fe8fb19SBen Gras */
1722fe8fb19SBen Gras float32 float32_round_to_int( float32 );
1732fe8fb19SBen Gras float32 float32_add( float32, float32 );
1742fe8fb19SBen Gras float32 float32_sub( float32, float32 );
1752fe8fb19SBen Gras float32 float32_mul( float32, float32 );
1762fe8fb19SBen Gras float32 float32_div( float32, float32 );
1772fe8fb19SBen Gras float32 float32_rem( float32, float32 );
1782fe8fb19SBen Gras float32 float32_sqrt( float32 );
1792fe8fb19SBen Gras int float32_eq( float32, float32 );
1802fe8fb19SBen Gras int float32_le( float32, float32 );
1812fe8fb19SBen Gras int float32_lt( float32, float32 );
1822fe8fb19SBen Gras int float32_eq_signaling( float32, float32 );
1832fe8fb19SBen Gras int float32_le_quiet( float32, float32 );
1842fe8fb19SBen Gras int float32_lt_quiet( float32, float32 );
1852fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC
1862fe8fb19SBen Gras int float32_is_signaling_nan( float32 );
1872fe8fb19SBen Gras #endif
1882fe8fb19SBen Gras 
1892fe8fb19SBen Gras /*
1902fe8fb19SBen Gras -------------------------------------------------------------------------------
1912fe8fb19SBen Gras Software IEC/IEEE double-precision conversion routines.
1922fe8fb19SBen Gras -------------------------------------------------------------------------------
1932fe8fb19SBen Gras */
1942fe8fb19SBen Gras int float64_to_int32( float64 );
1952fe8fb19SBen Gras int float64_to_int32_round_to_zero( float64 );
1962fe8fb19SBen Gras #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS)
1972fe8fb19SBen Gras unsigned int float64_to_uint32_round_to_zero( float64 );
1982fe8fb19SBen Gras #endif
1992fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */
2002fe8fb19SBen Gras long long float64_to_int64( float64 );
2012fe8fb19SBen Gras long long float64_to_int64_round_to_zero( float64 );
2022fe8fb19SBen Gras #endif
2032fe8fb19SBen Gras float32 float64_to_float32( float64 );
2042fe8fb19SBen Gras #ifdef FLOATX80
2052fe8fb19SBen Gras floatx80 float64_to_floatx80( float64 );
2062fe8fb19SBen Gras #endif
2072fe8fb19SBen Gras #ifdef FLOAT128
2082fe8fb19SBen Gras float128 float64_to_float128( float64 );
2092fe8fb19SBen Gras #endif
2102fe8fb19SBen Gras 
2112fe8fb19SBen Gras /*
2122fe8fb19SBen Gras -------------------------------------------------------------------------------
2132fe8fb19SBen Gras Software IEC/IEEE double-precision operations.
2142fe8fb19SBen Gras -------------------------------------------------------------------------------
2152fe8fb19SBen Gras */
2162fe8fb19SBen Gras float64 float64_round_to_int( float64 );
2172fe8fb19SBen Gras float64 float64_add( float64, float64 );
2182fe8fb19SBen Gras float64 float64_sub( float64, float64 );
2192fe8fb19SBen Gras float64 float64_mul( float64, float64 );
2202fe8fb19SBen Gras float64 float64_div( float64, float64 );
2212fe8fb19SBen Gras float64 float64_rem( float64, float64 );
2222fe8fb19SBen Gras float64 float64_sqrt( float64 );
2232fe8fb19SBen Gras int float64_eq( float64, float64 );
2242fe8fb19SBen Gras int float64_le( float64, float64 );
2252fe8fb19SBen Gras int float64_lt( float64, float64 );
2262fe8fb19SBen Gras int float64_eq_signaling( float64, float64 );
2272fe8fb19SBen Gras int float64_le_quiet( float64, float64 );
2282fe8fb19SBen Gras int float64_lt_quiet( float64, float64 );
2292fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC
2302fe8fb19SBen Gras int float64_is_signaling_nan( float64 );
2312fe8fb19SBen Gras #endif
2322fe8fb19SBen Gras 
2332fe8fb19SBen Gras #ifdef FLOATX80
2342fe8fb19SBen Gras 
2352fe8fb19SBen Gras /*
2362fe8fb19SBen Gras -------------------------------------------------------------------------------
2372fe8fb19SBen Gras Software IEC/IEEE extended double-precision conversion routines.
2382fe8fb19SBen Gras -------------------------------------------------------------------------------
2392fe8fb19SBen Gras */
2402fe8fb19SBen Gras int floatx80_to_int32( floatx80 );
2412fe8fb19SBen Gras int floatx80_to_int32_round_to_zero( floatx80 );
2422fe8fb19SBen Gras long long floatx80_to_int64( floatx80 );
2432fe8fb19SBen Gras long long floatx80_to_int64_round_to_zero( floatx80 );
2442fe8fb19SBen Gras float32 floatx80_to_float32( floatx80 );
2452fe8fb19SBen Gras float64 floatx80_to_float64( floatx80 );
2462fe8fb19SBen Gras #ifdef FLOAT128
2472fe8fb19SBen Gras float128 floatx80_to_float128( floatx80 );
2482fe8fb19SBen Gras #endif
2492fe8fb19SBen Gras 
2502fe8fb19SBen Gras /*
2512fe8fb19SBen Gras -------------------------------------------------------------------------------
2522fe8fb19SBen Gras Software IEC/IEEE extended double-precision rounding precision.  Valid
2532fe8fb19SBen Gras values are 32, 64, and 80.
2542fe8fb19SBen Gras -------------------------------------------------------------------------------
2552fe8fb19SBen Gras */
2562fe8fb19SBen Gras extern int floatx80_rounding_precision;
2572fe8fb19SBen Gras 
2582fe8fb19SBen Gras /*
2592fe8fb19SBen Gras -------------------------------------------------------------------------------
2602fe8fb19SBen Gras Software IEC/IEEE extended double-precision operations.
2612fe8fb19SBen Gras -------------------------------------------------------------------------------
2622fe8fb19SBen Gras */
2632fe8fb19SBen Gras floatx80 floatx80_round_to_int( floatx80 );
2642fe8fb19SBen Gras floatx80 floatx80_add( floatx80, floatx80 );
2652fe8fb19SBen Gras floatx80 floatx80_sub( floatx80, floatx80 );
2662fe8fb19SBen Gras floatx80 floatx80_mul( floatx80, floatx80 );
2672fe8fb19SBen Gras floatx80 floatx80_div( floatx80, floatx80 );
2682fe8fb19SBen Gras floatx80 floatx80_rem( floatx80, floatx80 );
2692fe8fb19SBen Gras floatx80 floatx80_sqrt( floatx80 );
2702fe8fb19SBen Gras int floatx80_eq( floatx80, floatx80 );
2712fe8fb19SBen Gras int floatx80_le( floatx80, floatx80 );
2722fe8fb19SBen Gras int floatx80_lt( floatx80, floatx80 );
2732fe8fb19SBen Gras int floatx80_eq_signaling( floatx80, floatx80 );
2742fe8fb19SBen Gras int floatx80_le_quiet( floatx80, floatx80 );
2752fe8fb19SBen Gras int floatx80_lt_quiet( floatx80, floatx80 );
2762fe8fb19SBen Gras int floatx80_is_signaling_nan( floatx80 );
2772fe8fb19SBen Gras 
2782fe8fb19SBen Gras #endif
2792fe8fb19SBen Gras 
2802fe8fb19SBen Gras #ifdef FLOAT128
2812fe8fb19SBen Gras 
2822fe8fb19SBen Gras /*
2832fe8fb19SBen Gras -------------------------------------------------------------------------------
2842fe8fb19SBen Gras Software IEC/IEEE quadruple-precision conversion routines.
2852fe8fb19SBen Gras -------------------------------------------------------------------------------
2862fe8fb19SBen Gras */
2872fe8fb19SBen Gras int float128_to_int32( float128 );
2882fe8fb19SBen Gras int float128_to_int32_round_to_zero( float128 );
2892fe8fb19SBen Gras #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS)
2902fe8fb19SBen Gras unsigned int float128_to_uint32_round_to_zero( float64 );
2912fe8fb19SBen Gras #endif
2922fe8fb19SBen Gras long long float128_to_int64( float128 );
2932fe8fb19SBen Gras long long float128_to_int64_round_to_zero( float128 );
2942fe8fb19SBen Gras #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS)
2952fe8fb19SBen Gras unsigned long long float128_to_uint64_round_to_zero( float128 );
2962fe8fb19SBen Gras #endif
2972fe8fb19SBen Gras float32 float128_to_float32( float128 );
2982fe8fb19SBen Gras float64 float128_to_float64( float128 );
2992fe8fb19SBen Gras #ifdef FLOATX80
3002fe8fb19SBen Gras floatx80 float128_to_floatx80( float128 );
3012fe8fb19SBen Gras #endif
3022fe8fb19SBen Gras 
3032fe8fb19SBen Gras /*
3042fe8fb19SBen Gras -------------------------------------------------------------------------------
3052fe8fb19SBen Gras Software IEC/IEEE quadruple-precision operations.
3062fe8fb19SBen Gras -------------------------------------------------------------------------------
3072fe8fb19SBen Gras */
3082fe8fb19SBen Gras float128 float128_round_to_int( float128 );
3092fe8fb19SBen Gras float128 float128_add( float128, float128 );
3102fe8fb19SBen Gras float128 float128_sub( float128, float128 );
3112fe8fb19SBen Gras float128 float128_mul( float128, float128 );
3122fe8fb19SBen Gras float128 float128_div( float128, float128 );
3132fe8fb19SBen Gras float128 float128_rem( float128, float128 );
3142fe8fb19SBen Gras float128 float128_sqrt( float128 );
3152fe8fb19SBen Gras int float128_eq( float128, float128 );
3162fe8fb19SBen Gras int float128_le( float128, float128 );
3172fe8fb19SBen Gras int float128_lt( float128, float128 );
3182fe8fb19SBen Gras int float128_eq_signaling( float128, float128 );
3192fe8fb19SBen Gras int float128_le_quiet( float128, float128 );
3202fe8fb19SBen Gras int float128_lt_quiet( float128, float128 );
3212fe8fb19SBen Gras int float128_is_signaling_nan( float128 );
3222fe8fb19SBen Gras flag float128_is_nan( float128 );
3232fe8fb19SBen Gras 
3242fe8fb19SBen Gras #endif
3252fe8fb19SBen Gras 
326