xref: /minix3/lib/libc/arch/sh3/softfloat/softfloat.h (revision e415d488727a332a2c69df018aa35e2cecf4148a)
1*e415d488SLionel Sambuc /*	$NetBSD: softfloat.h,v 1.11 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 /* #define FLOAT128 */
462fe8fb19SBen Gras 
472fe8fb19SBen Gras #include <machine/ieeefp.h>
482fe8fb19SBen Gras 
492fe8fb19SBen Gras /*
502fe8fb19SBen Gras -------------------------------------------------------------------------------
512fe8fb19SBen Gras Software IEC/IEEE floating-point types.
522fe8fb19SBen Gras -------------------------------------------------------------------------------
532fe8fb19SBen Gras */
542fe8fb19SBen Gras typedef unsigned int float32;
552fe8fb19SBen Gras typedef unsigned long long float64;
562fe8fb19SBen Gras #ifdef FLOATX80
572fe8fb19SBen Gras typedef struct {
582fe8fb19SBen Gras     unsigned short high;
592fe8fb19SBen Gras     unsigned long long low;
602fe8fb19SBen Gras } floatx80;
612fe8fb19SBen Gras #endif
622fe8fb19SBen Gras #ifdef FLOAT128
632fe8fb19SBen Gras typedef struct {
642fe8fb19SBen Gras     unsigned long long high, low;
652fe8fb19SBen Gras } float128;
662fe8fb19SBen Gras #endif
672fe8fb19SBen Gras 
682fe8fb19SBen Gras /*
692fe8fb19SBen Gras -------------------------------------------------------------------------------
702fe8fb19SBen Gras Software IEC/IEEE floating-point underflow tininess-detection mode.
712fe8fb19SBen Gras -------------------------------------------------------------------------------
722fe8fb19SBen Gras */
732fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC
742fe8fb19SBen Gras extern int8 float_detect_tininess;
752fe8fb19SBen Gras #endif
762fe8fb19SBen Gras enum {
772fe8fb19SBen Gras     float_tininess_after_rounding  = 0,
782fe8fb19SBen Gras     float_tininess_before_rounding = 1
792fe8fb19SBen Gras };
802fe8fb19SBen Gras 
812fe8fb19SBen Gras /*
822fe8fb19SBen Gras -------------------------------------------------------------------------------
832fe8fb19SBen Gras Software IEC/IEEE floating-point rounding mode.
842fe8fb19SBen Gras -------------------------------------------------------------------------------
852fe8fb19SBen Gras */
862fe8fb19SBen Gras extern fp_rnd float_rounding_mode;
87*e415d488SLionel Sambuc #define float_round_nearest_even FP_RN
88*e415d488SLionel Sambuc #define float_round_to_zero      FP_RZ
89*e415d488SLionel Sambuc #define float_round_down         FP_RM
90*e415d488SLionel Sambuc #define float_round_up           FP_RP
912fe8fb19SBen Gras 
922fe8fb19SBen Gras /*
932fe8fb19SBen Gras -------------------------------------------------------------------------------
942fe8fb19SBen Gras Software IEC/IEEE floating-point exception flags.
952fe8fb19SBen Gras -------------------------------------------------------------------------------
962fe8fb19SBen Gras */
972fe8fb19SBen Gras extern fp_except float_exception_flags;
982fe8fb19SBen Gras extern fp_except float_exception_mask;
992fe8fb19SBen Gras enum {
1002fe8fb19SBen Gras     float_flag_inexact   = FP_X_IMP,
1012fe8fb19SBen Gras     float_flag_underflow = FP_X_UFL,
1022fe8fb19SBen Gras     float_flag_overflow  = FP_X_OFL,
1032fe8fb19SBen Gras     float_flag_divbyzero = FP_X_DZ,
1042fe8fb19SBen Gras     float_flag_invalid   = FP_X_INV
1052fe8fb19SBen Gras };
1062fe8fb19SBen Gras 
1072fe8fb19SBen Gras /*
1082fe8fb19SBen Gras -------------------------------------------------------------------------------
1092fe8fb19SBen Gras Routine to raise any or all of the software IEC/IEEE floating-point
1102fe8fb19SBen Gras exception flags.
1112fe8fb19SBen Gras -------------------------------------------------------------------------------
1122fe8fb19SBen Gras */
1132fe8fb19SBen Gras void float_raise( fp_except );
1142fe8fb19SBen Gras 
1152fe8fb19SBen Gras /*
1162fe8fb19SBen Gras -------------------------------------------------------------------------------
1172fe8fb19SBen Gras Software IEC/IEEE integer-to-floating-point conversion routines.
1182fe8fb19SBen Gras -------------------------------------------------------------------------------
1192fe8fb19SBen Gras */
120*e415d488SLionel Sambuc float32 int32_to_float32( int32 );
121*e415d488SLionel Sambuc float32 uint32_to_float32( uint32 );
122*e415d488SLionel Sambuc float64 int32_to_float64( int32 );
123*e415d488SLionel Sambuc float64 uint32_to_float64( uint32 );
1242fe8fb19SBen Gras #ifdef FLOATX80
125*e415d488SLionel Sambuc floatx80 int32_to_floatx80( int32 );
126*e415d488SLionel Sambuc floatx80 uint32_to_floatx80( uint32 );
1272fe8fb19SBen Gras #endif
1282fe8fb19SBen Gras #ifdef FLOAT128
129*e415d488SLionel Sambuc float128 int32_to_float128( int32 );
130*e415d488SLionel Sambuc float128 uint32_to_float128( uint32 );
1312fe8fb19SBen Gras #endif
1322fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC /* __floatdi?f is in libgcc2.c */
1332fe8fb19SBen Gras float32 int64_to_float32( long long );
1342fe8fb19SBen Gras float64 int64_to_float64( long long );
1352fe8fb19SBen Gras #ifdef FLOATX80
1362fe8fb19SBen Gras floatx80 int64_to_floatx80( long long );
1372fe8fb19SBen Gras #endif
1382fe8fb19SBen Gras #ifdef FLOAT128
1392fe8fb19SBen Gras float128 int64_to_float128( long long );
1402fe8fb19SBen Gras #endif
1412fe8fb19SBen Gras #endif
1422fe8fb19SBen Gras 
1432fe8fb19SBen Gras /*
1442fe8fb19SBen Gras -------------------------------------------------------------------------------
1452fe8fb19SBen Gras Software IEC/IEEE single-precision conversion routines.
1462fe8fb19SBen Gras -------------------------------------------------------------------------------
1472fe8fb19SBen Gras */
1482fe8fb19SBen Gras int float32_to_int32( float32 );
1492fe8fb19SBen Gras int float32_to_int32_round_to_zero( float32 );
1502fe8fb19SBen Gras #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS)
1512fe8fb19SBen Gras unsigned int float32_to_uint32_round_to_zero( float32 );
1522fe8fb19SBen Gras #endif
1532fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */
1542fe8fb19SBen Gras long long float32_to_int64( float32 );
1552fe8fb19SBen Gras long long float32_to_int64_round_to_zero( float32 );
1562fe8fb19SBen Gras #endif
1572fe8fb19SBen Gras float64 float32_to_float64( float32 );
1582fe8fb19SBen Gras #ifdef FLOATX80
1592fe8fb19SBen Gras floatx80 float32_to_floatx80( float32 );
1602fe8fb19SBen Gras #endif
1612fe8fb19SBen Gras #ifdef FLOAT128
1622fe8fb19SBen Gras float128 float32_to_float128( float32 );
1632fe8fb19SBen Gras #endif
1642fe8fb19SBen Gras 
1652fe8fb19SBen Gras /*
1662fe8fb19SBen Gras -------------------------------------------------------------------------------
1672fe8fb19SBen Gras Software IEC/IEEE single-precision operations.
1682fe8fb19SBen Gras -------------------------------------------------------------------------------
1692fe8fb19SBen Gras */
1702fe8fb19SBen Gras float32 float32_round_to_int( float32 );
1712fe8fb19SBen Gras float32 float32_add( float32, float32 );
1722fe8fb19SBen Gras float32 float32_sub( float32, float32 );
1732fe8fb19SBen Gras float32 float32_mul( float32, float32 );
1742fe8fb19SBen Gras float32 float32_div( float32, float32 );
1752fe8fb19SBen Gras float32 float32_rem( float32, float32 );
1762fe8fb19SBen Gras float32 float32_sqrt( float32 );
1772fe8fb19SBen Gras flag float32_eq( float32, float32 );
1782fe8fb19SBen Gras flag float32_le( float32, float32 );
1792fe8fb19SBen Gras flag float32_lt( float32, float32 );
1802fe8fb19SBen Gras flag float32_eq_signaling( float32, float32 );
1812fe8fb19SBen Gras flag float32_le_quiet( float32, float32 );
1822fe8fb19SBen Gras flag float32_lt_quiet( float32, float32 );
1832fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC
1842fe8fb19SBen Gras flag float32_is_signaling_nan( float32 );
1852fe8fb19SBen Gras #endif
1862fe8fb19SBen Gras 
1872fe8fb19SBen Gras /*
1882fe8fb19SBen Gras -------------------------------------------------------------------------------
1892fe8fb19SBen Gras Software IEC/IEEE double-precision conversion routines.
1902fe8fb19SBen Gras -------------------------------------------------------------------------------
1912fe8fb19SBen Gras */
1922fe8fb19SBen Gras int float64_to_int32( float64 );
1932fe8fb19SBen Gras int float64_to_int32_round_to_zero( float64 );
1942fe8fb19SBen Gras #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS)
1952fe8fb19SBen Gras unsigned int float64_to_uint32_round_to_zero( float64 );
1962fe8fb19SBen Gras #endif
1972fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */
1982fe8fb19SBen Gras long long float64_to_int64( float64 );
1992fe8fb19SBen Gras long long float64_to_int64_round_to_zero( float64 );
2002fe8fb19SBen Gras #endif
2012fe8fb19SBen Gras float32 float64_to_float32( float64 );
2022fe8fb19SBen Gras #ifdef FLOATX80
2032fe8fb19SBen Gras floatx80 float64_to_floatx80( float64 );
2042fe8fb19SBen Gras #endif
2052fe8fb19SBen Gras #ifdef FLOAT128
2062fe8fb19SBen Gras float128 float64_to_float128( float64 );
2072fe8fb19SBen Gras #endif
2082fe8fb19SBen Gras 
2092fe8fb19SBen Gras /*
2102fe8fb19SBen Gras -------------------------------------------------------------------------------
2112fe8fb19SBen Gras Software IEC/IEEE double-precision operations.
2122fe8fb19SBen Gras -------------------------------------------------------------------------------
2132fe8fb19SBen Gras */
2142fe8fb19SBen Gras float64 float64_round_to_int( float64 );
2152fe8fb19SBen Gras float64 float64_add( float64, float64 );
2162fe8fb19SBen Gras float64 float64_sub( float64, float64 );
2172fe8fb19SBen Gras float64 float64_mul( float64, float64 );
2182fe8fb19SBen Gras float64 float64_div( float64, float64 );
2192fe8fb19SBen Gras float64 float64_rem( float64, float64 );
2202fe8fb19SBen Gras float64 float64_sqrt( float64 );
2212fe8fb19SBen Gras flag float64_eq( float64, float64 );
2222fe8fb19SBen Gras flag float64_le( float64, float64 );
2232fe8fb19SBen Gras flag float64_lt( float64, float64 );
2242fe8fb19SBen Gras flag float64_eq_signaling( float64, float64 );
2252fe8fb19SBen Gras flag float64_le_quiet( float64, float64 );
2262fe8fb19SBen Gras flag float64_lt_quiet( float64, float64 );
2272fe8fb19SBen Gras #ifndef SOFTFLOAT_FOR_GCC
2282fe8fb19SBen Gras flag float64_is_signaling_nan( float64 );
2292fe8fb19SBen Gras #endif
2302fe8fb19SBen Gras 
2312fe8fb19SBen Gras #ifdef FLOATX80
2322fe8fb19SBen Gras 
2332fe8fb19SBen Gras /*
2342fe8fb19SBen Gras -------------------------------------------------------------------------------
2352fe8fb19SBen Gras Software IEC/IEEE extended double-precision conversion routines.
2362fe8fb19SBen Gras -------------------------------------------------------------------------------
2372fe8fb19SBen Gras */
2382fe8fb19SBen Gras int floatx80_to_int32( floatx80 );
2392fe8fb19SBen Gras int floatx80_to_int32_round_to_zero( floatx80 );
2402fe8fb19SBen Gras long long floatx80_to_int64( floatx80 );
2412fe8fb19SBen Gras long long floatx80_to_int64_round_to_zero( floatx80 );
2422fe8fb19SBen Gras float32 floatx80_to_float32( floatx80 );
2432fe8fb19SBen Gras float64 floatx80_to_float64( floatx80 );
2442fe8fb19SBen Gras #ifdef FLOAT128
2452fe8fb19SBen Gras float128 floatx80_to_float128( floatx80 );
2462fe8fb19SBen Gras #endif
2472fe8fb19SBen Gras 
2482fe8fb19SBen Gras /*
2492fe8fb19SBen Gras -------------------------------------------------------------------------------
2502fe8fb19SBen Gras Software IEC/IEEE extended double-precision rounding precision.  Valid
2512fe8fb19SBen Gras values are 32, 64, and 80.
2522fe8fb19SBen Gras -------------------------------------------------------------------------------
2532fe8fb19SBen Gras */
2542fe8fb19SBen Gras extern int floatx80_rounding_precision;
2552fe8fb19SBen Gras 
2562fe8fb19SBen Gras /*
2572fe8fb19SBen Gras -------------------------------------------------------------------------------
2582fe8fb19SBen Gras Software IEC/IEEE extended double-precision operations.
2592fe8fb19SBen Gras -------------------------------------------------------------------------------
2602fe8fb19SBen Gras */
2612fe8fb19SBen Gras floatx80 floatx80_round_to_int( floatx80 );
2622fe8fb19SBen Gras floatx80 floatx80_add( floatx80, floatx80 );
2632fe8fb19SBen Gras floatx80 floatx80_sub( floatx80, floatx80 );
2642fe8fb19SBen Gras floatx80 floatx80_mul( floatx80, floatx80 );
2652fe8fb19SBen Gras floatx80 floatx80_div( floatx80, floatx80 );
2662fe8fb19SBen Gras floatx80 floatx80_rem( floatx80, floatx80 );
2672fe8fb19SBen Gras floatx80 floatx80_sqrt( floatx80 );
2682fe8fb19SBen Gras flag floatx80_eq( floatx80, floatx80 );
2692fe8fb19SBen Gras flag floatx80_le( floatx80, floatx80 );
2702fe8fb19SBen Gras flag floatx80_lt( floatx80, floatx80 );
2712fe8fb19SBen Gras flag floatx80_eq_signaling( floatx80, floatx80 );
2722fe8fb19SBen Gras flag floatx80_le_quiet( floatx80, floatx80 );
2732fe8fb19SBen Gras flag floatx80_lt_quiet( floatx80, floatx80 );
2742fe8fb19SBen Gras flag floatx80_is_signaling_nan( floatx80 );
2752fe8fb19SBen Gras 
2762fe8fb19SBen Gras #endif
2772fe8fb19SBen Gras 
2782fe8fb19SBen Gras #ifdef FLOAT128
2792fe8fb19SBen Gras 
2802fe8fb19SBen Gras /*
2812fe8fb19SBen Gras -------------------------------------------------------------------------------
2822fe8fb19SBen Gras Software IEC/IEEE quadruple-precision conversion routines.
2832fe8fb19SBen Gras -------------------------------------------------------------------------------
2842fe8fb19SBen Gras */
2852fe8fb19SBen Gras int float128_to_int32( float128 );
2862fe8fb19SBen Gras int float128_to_int32_round_to_zero( float128 );
2872fe8fb19SBen Gras long long float128_to_int64( float128 );
2882fe8fb19SBen Gras long long float128_to_int64_round_to_zero( float128 );
2892fe8fb19SBen Gras float32 float128_to_float32( float128 );
2902fe8fb19SBen Gras float64 float128_to_float64( float128 );
2912fe8fb19SBen Gras #ifdef FLOATX80
2922fe8fb19SBen Gras floatx80 float128_to_floatx80( float128 );
2932fe8fb19SBen Gras #endif
2942fe8fb19SBen Gras 
2952fe8fb19SBen Gras /*
2962fe8fb19SBen Gras -------------------------------------------------------------------------------
2972fe8fb19SBen Gras Software IEC/IEEE quadruple-precision operations.
2982fe8fb19SBen Gras -------------------------------------------------------------------------------
2992fe8fb19SBen Gras */
3002fe8fb19SBen Gras float128 float128_round_to_int( float128 );
3012fe8fb19SBen Gras float128 float128_add( float128, float128 );
3022fe8fb19SBen Gras float128 float128_sub( float128, float128 );
3032fe8fb19SBen Gras float128 float128_mul( float128, float128 );
3042fe8fb19SBen Gras float128 float128_div( float128, float128 );
3052fe8fb19SBen Gras float128 float128_rem( float128, float128 );
3062fe8fb19SBen Gras float128 float128_sqrt( float128 );
3072fe8fb19SBen Gras flag float128_eq( float128, float128 );
3082fe8fb19SBen Gras flag float128_le( float128, float128 );
3092fe8fb19SBen Gras flag float128_lt( float128, float128 );
3102fe8fb19SBen Gras flag float128_eq_signaling( float128, float128 );
3112fe8fb19SBen Gras flag float128_le_quiet( float128, float128 );
3122fe8fb19SBen Gras flag float128_lt_quiet( float128, float128 );
3132fe8fb19SBen Gras flag float128_is_signaling_nan( float128 );
3142fe8fb19SBen Gras 
3152fe8fb19SBen Gras #endif
3162fe8fb19SBen Gras 
317