xref: /freebsd/lib/libc/arm/softfloat/softfloat.h (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
12357939bSOlivier Houchard /*	$NetBSD: softfloat.h,v 1.6 2002/05/12 13:12:46 bjh21 Exp $	*/
22357939bSOlivier Houchard 
32357939bSOlivier Houchard /* This is a derivative work. */
42357939bSOlivier Houchard 
52357939bSOlivier Houchard /*
62357939bSOlivier Houchard ===============================================================================
72357939bSOlivier Houchard 
82357939bSOlivier Houchard This C header file is part of the SoftFloat IEC/IEEE Floating-point
92357939bSOlivier Houchard Arithmetic Package, Release 2a.
102357939bSOlivier Houchard 
112357939bSOlivier Houchard Written by John R. Hauser.  This work was made possible in part by the
122357939bSOlivier Houchard International Computer Science Institute, located at Suite 600, 1947 Center
132357939bSOlivier Houchard Street, Berkeley, California 94704.  Funding was partially provided by the
142357939bSOlivier Houchard National Science Foundation under grant MIP-9311980.  The original version
152357939bSOlivier Houchard of this code was written as part of a project to build a fixed-point vector
162357939bSOlivier Houchard processor in collaboration with the University of California at Berkeley,
172357939bSOlivier Houchard overseen by Profs. Nelson Morgan and John Wawrzynek.  More information
182357939bSOlivier Houchard is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/
192357939bSOlivier Houchard arithmetic/SoftFloat.html'.
202357939bSOlivier Houchard 
212357939bSOlivier Houchard THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort
222357939bSOlivier Houchard has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
232357939bSOlivier Houchard TIMES RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO
242357939bSOlivier Houchard PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
252357939bSOlivier Houchard AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
262357939bSOlivier Houchard 
272357939bSOlivier Houchard Derivative works are acceptable, even for commercial purposes, so long as
282357939bSOlivier Houchard (1) they include prominent notice that the work is derivative, and (2) they
292357939bSOlivier Houchard include prominent notice akin to these four paragraphs for those parts of
302357939bSOlivier Houchard this code that are retained.
312357939bSOlivier Houchard 
322357939bSOlivier Houchard ===============================================================================
332357939bSOlivier Houchard */
342357939bSOlivier Houchard 
352357939bSOlivier Houchard /*
362357939bSOlivier Houchard -------------------------------------------------------------------------------
372357939bSOlivier Houchard The macro `FLOATX80' must be defined to enable the extended double-precision
382357939bSOlivier Houchard floating-point format `floatx80'.  If this macro is not defined, the
392357939bSOlivier Houchard `floatx80' type will not be defined, and none of the functions that either
402357939bSOlivier Houchard input or output the `floatx80' type will be defined.  The same applies to
412357939bSOlivier Houchard the `FLOAT128' macro and the quadruple-precision format `float128'.
422357939bSOlivier Houchard -------------------------------------------------------------------------------
432357939bSOlivier Houchard */
442357939bSOlivier Houchard /* #define FLOATX80 */
452357939bSOlivier Houchard /* #define FLOAT128 */
462357939bSOlivier Houchard 
47*b1d04644SDavid Schultz #include <fenv.h>
482357939bSOlivier Houchard 
492357939bSOlivier Houchard /*
502357939bSOlivier Houchard -------------------------------------------------------------------------------
512357939bSOlivier Houchard Software IEC/IEEE floating-point types.
522357939bSOlivier Houchard -------------------------------------------------------------------------------
532357939bSOlivier Houchard */
542357939bSOlivier Houchard typedef unsigned int float32;
552357939bSOlivier Houchard typedef unsigned long long float64;
562357939bSOlivier Houchard #ifdef FLOATX80
572357939bSOlivier Houchard typedef struct {
582357939bSOlivier Houchard     unsigned short high;
592357939bSOlivier Houchard     unsigned long long low;
602357939bSOlivier Houchard } floatx80;
612357939bSOlivier Houchard #endif
622357939bSOlivier Houchard #ifdef FLOAT128
632357939bSOlivier Houchard typedef struct {
642357939bSOlivier Houchard     unsigned long long high, low;
652357939bSOlivier Houchard } float128;
662357939bSOlivier Houchard #endif
672357939bSOlivier Houchard 
682357939bSOlivier Houchard /*
692357939bSOlivier Houchard -------------------------------------------------------------------------------
702357939bSOlivier Houchard Software IEC/IEEE floating-point underflow tininess-detection mode.
712357939bSOlivier Houchard -------------------------------------------------------------------------------
722357939bSOlivier Houchard */
7394942af2SAlexander Kabaev #ifndef SOFTFLOAT_FOR_GCC
742357939bSOlivier Houchard extern int float_detect_tininess;
7594942af2SAlexander Kabaev #endif
762357939bSOlivier Houchard enum {
772357939bSOlivier Houchard     float_tininess_after_rounding  = 0,
782357939bSOlivier Houchard     float_tininess_before_rounding = 1
792357939bSOlivier Houchard };
802357939bSOlivier Houchard 
812357939bSOlivier Houchard /*
822357939bSOlivier Houchard -------------------------------------------------------------------------------
832357939bSOlivier Houchard Software IEC/IEEE floating-point rounding mode.
842357939bSOlivier Houchard -------------------------------------------------------------------------------
852357939bSOlivier Houchard */
86*b1d04644SDavid Schultz extern int float_rounding_mode;
872357939bSOlivier Houchard enum {
88*b1d04644SDavid Schultz     float_round_nearest_even = FE_TONEAREST,
89*b1d04644SDavid Schultz     float_round_to_zero      = FE_TOWARDZERO,
90*b1d04644SDavid Schultz     float_round_down         = FE_DOWNWARD,
91*b1d04644SDavid Schultz     float_round_up           = FE_UPWARD
922357939bSOlivier Houchard };
932357939bSOlivier Houchard 
942357939bSOlivier Houchard /*
952357939bSOlivier Houchard -------------------------------------------------------------------------------
962357939bSOlivier Houchard Software IEC/IEEE floating-point exception flags.
972357939bSOlivier Houchard -------------------------------------------------------------------------------
982357939bSOlivier Houchard */
99*b1d04644SDavid Schultz extern int float_exception_flags;
100*b1d04644SDavid Schultz extern int float_exception_mask;
1012357939bSOlivier Houchard enum {
102*b1d04644SDavid Schultz     float_flag_inexact   = FE_INEXACT,
103*b1d04644SDavid Schultz     float_flag_underflow = FE_UNDERFLOW,
104*b1d04644SDavid Schultz     float_flag_overflow  = FE_OVERFLOW,
105*b1d04644SDavid Schultz     float_flag_divbyzero = FE_DIVBYZERO,
106*b1d04644SDavid Schultz     float_flag_invalid   = FE_INVALID
1072357939bSOlivier Houchard };
1082357939bSOlivier Houchard 
1092357939bSOlivier Houchard /*
1102357939bSOlivier Houchard -------------------------------------------------------------------------------
1112357939bSOlivier Houchard Routine to raise any or all of the software IEC/IEEE floating-point
1122357939bSOlivier Houchard exception flags.
1132357939bSOlivier Houchard -------------------------------------------------------------------------------
1142357939bSOlivier Houchard */
115*b1d04644SDavid Schultz void float_raise( int );
1162357939bSOlivier Houchard 
1172357939bSOlivier Houchard /*
1182357939bSOlivier Houchard -------------------------------------------------------------------------------
1192357939bSOlivier Houchard Software IEC/IEEE integer-to-floating-point conversion routines.
1202357939bSOlivier Houchard -------------------------------------------------------------------------------
1212357939bSOlivier Houchard */
1222357939bSOlivier Houchard float32 int32_to_float32( int );
1232357939bSOlivier Houchard float64 int32_to_float64( int );
1242357939bSOlivier Houchard #ifdef FLOATX80
1252357939bSOlivier Houchard floatx80 int32_to_floatx80( int );
1262357939bSOlivier Houchard #endif
1272357939bSOlivier Houchard #ifdef FLOAT128
1282357939bSOlivier Houchard float128 int32_to_float128( int );
1292357939bSOlivier Houchard #endif
1302357939bSOlivier Houchard #ifndef SOFTFLOAT_FOR_GCC /* __floatdi?f is in libgcc2.c */
1312357939bSOlivier Houchard float32 int64_to_float32( long long );
1322357939bSOlivier Houchard float64 int64_to_float64( long long );
1332357939bSOlivier Houchard #ifdef FLOATX80
1342357939bSOlivier Houchard floatx80 int64_to_floatx80( long long );
1352357939bSOlivier Houchard #endif
1362357939bSOlivier Houchard #ifdef FLOAT128
1372357939bSOlivier Houchard float128 int64_to_float128( long long );
1382357939bSOlivier Houchard #endif
1392357939bSOlivier Houchard #endif
1402357939bSOlivier Houchard 
1412357939bSOlivier Houchard /*
1422357939bSOlivier Houchard -------------------------------------------------------------------------------
1432357939bSOlivier Houchard Software IEC/IEEE single-precision conversion routines.
1442357939bSOlivier Houchard -------------------------------------------------------------------------------
1452357939bSOlivier Houchard */
1462357939bSOlivier Houchard int float32_to_int32( float32 );
1472357939bSOlivier Houchard int float32_to_int32_round_to_zero( float32 );
1482357939bSOlivier Houchard #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS)
1492357939bSOlivier Houchard unsigned int float32_to_uint32_round_to_zero( float32 );
1502357939bSOlivier Houchard #endif
1512357939bSOlivier Houchard #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */
1522357939bSOlivier Houchard long long float32_to_int64( float32 );
1532357939bSOlivier Houchard long long float32_to_int64_round_to_zero( float32 );
1542357939bSOlivier Houchard #endif
1552357939bSOlivier Houchard float64 float32_to_float64( float32 );
1562357939bSOlivier Houchard #ifdef FLOATX80
1572357939bSOlivier Houchard floatx80 float32_to_floatx80( float32 );
1582357939bSOlivier Houchard #endif
1592357939bSOlivier Houchard #ifdef FLOAT128
1602357939bSOlivier Houchard float128 float32_to_float128( float32 );
1612357939bSOlivier Houchard #endif
1622357939bSOlivier Houchard 
1632357939bSOlivier Houchard /*
1642357939bSOlivier Houchard -------------------------------------------------------------------------------
1652357939bSOlivier Houchard Software IEC/IEEE single-precision operations.
1662357939bSOlivier Houchard -------------------------------------------------------------------------------
1672357939bSOlivier Houchard */
1682357939bSOlivier Houchard float32 float32_round_to_int( float32 );
1692357939bSOlivier Houchard float32 float32_add( float32, float32 );
1702357939bSOlivier Houchard float32 float32_sub( float32, float32 );
1712357939bSOlivier Houchard float32 float32_mul( float32, float32 );
1722357939bSOlivier Houchard float32 float32_div( float32, float32 );
1732357939bSOlivier Houchard float32 float32_rem( float32, float32 );
1742357939bSOlivier Houchard float32 float32_sqrt( float32 );
1752357939bSOlivier Houchard int float32_eq( float32, float32 );
1762357939bSOlivier Houchard int float32_le( float32, float32 );
1772357939bSOlivier Houchard int float32_lt( float32, float32 );
1782357939bSOlivier Houchard int float32_eq_signaling( float32, float32 );
1792357939bSOlivier Houchard int float32_le_quiet( float32, float32 );
1802357939bSOlivier Houchard int float32_lt_quiet( float32, float32 );
1812357939bSOlivier Houchard #ifndef SOFTFLOAT_FOR_GCC
1822357939bSOlivier Houchard int float32_is_signaling_nan( float32 );
1832357939bSOlivier Houchard #endif
1842357939bSOlivier Houchard 
1852357939bSOlivier Houchard /*
1862357939bSOlivier Houchard -------------------------------------------------------------------------------
1872357939bSOlivier Houchard Software IEC/IEEE double-precision conversion routines.
1882357939bSOlivier Houchard -------------------------------------------------------------------------------
1892357939bSOlivier Houchard */
1902357939bSOlivier Houchard int float64_to_int32( float64 );
1912357939bSOlivier Houchard int float64_to_int32_round_to_zero( float64 );
1922357939bSOlivier Houchard #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS)
1932357939bSOlivier Houchard unsigned int float64_to_uint32_round_to_zero( float64 );
1942357939bSOlivier Houchard #endif
1952357939bSOlivier Houchard #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */
1962357939bSOlivier Houchard long long float64_to_int64( float64 );
1972357939bSOlivier Houchard long long float64_to_int64_round_to_zero( float64 );
1982357939bSOlivier Houchard #endif
1992357939bSOlivier Houchard float32 float64_to_float32( float64 );
2002357939bSOlivier Houchard #ifdef FLOATX80
2012357939bSOlivier Houchard floatx80 float64_to_floatx80( float64 );
2022357939bSOlivier Houchard #endif
2032357939bSOlivier Houchard #ifdef FLOAT128
2042357939bSOlivier Houchard float128 float64_to_float128( float64 );
2052357939bSOlivier Houchard #endif
2062357939bSOlivier Houchard 
2072357939bSOlivier Houchard /*
2082357939bSOlivier Houchard -------------------------------------------------------------------------------
2092357939bSOlivier Houchard Software IEC/IEEE double-precision operations.
2102357939bSOlivier Houchard -------------------------------------------------------------------------------
2112357939bSOlivier Houchard */
2122357939bSOlivier Houchard float64 float64_round_to_int( float64 );
2132357939bSOlivier Houchard float64 float64_add( float64, float64 );
2142357939bSOlivier Houchard float64 float64_sub( float64, float64 );
2152357939bSOlivier Houchard float64 float64_mul( float64, float64 );
2162357939bSOlivier Houchard float64 float64_div( float64, float64 );
2172357939bSOlivier Houchard float64 float64_rem( float64, float64 );
2182357939bSOlivier Houchard float64 float64_sqrt( float64 );
2192357939bSOlivier Houchard int float64_eq( float64, float64 );
2202357939bSOlivier Houchard int float64_le( float64, float64 );
2212357939bSOlivier Houchard int float64_lt( float64, float64 );
2222357939bSOlivier Houchard int float64_eq_signaling( float64, float64 );
2232357939bSOlivier Houchard int float64_le_quiet( float64, float64 );
2242357939bSOlivier Houchard int float64_lt_quiet( float64, float64 );
2252357939bSOlivier Houchard #ifndef SOFTFLOAT_FOR_GCC
2262357939bSOlivier Houchard int float64_is_signaling_nan( float64 );
2272357939bSOlivier Houchard #endif
2282357939bSOlivier Houchard 
2292357939bSOlivier Houchard #ifdef FLOATX80
2302357939bSOlivier Houchard 
2312357939bSOlivier Houchard /*
2322357939bSOlivier Houchard -------------------------------------------------------------------------------
2332357939bSOlivier Houchard Software IEC/IEEE extended double-precision conversion routines.
2342357939bSOlivier Houchard -------------------------------------------------------------------------------
2352357939bSOlivier Houchard */
2362357939bSOlivier Houchard int floatx80_to_int32( floatx80 );
2372357939bSOlivier Houchard int floatx80_to_int32_round_to_zero( floatx80 );
2382357939bSOlivier Houchard long long floatx80_to_int64( floatx80 );
2392357939bSOlivier Houchard long long floatx80_to_int64_round_to_zero( floatx80 );
2402357939bSOlivier Houchard float32 floatx80_to_float32( floatx80 );
2412357939bSOlivier Houchard float64 floatx80_to_float64( floatx80 );
2422357939bSOlivier Houchard #ifdef FLOAT128
2432357939bSOlivier Houchard float128 floatx80_to_float128( floatx80 );
2442357939bSOlivier Houchard #endif
2452357939bSOlivier Houchard 
2462357939bSOlivier Houchard /*
2472357939bSOlivier Houchard -------------------------------------------------------------------------------
2482357939bSOlivier Houchard Software IEC/IEEE extended double-precision rounding precision.  Valid
2492357939bSOlivier Houchard values are 32, 64, and 80.
2502357939bSOlivier Houchard -------------------------------------------------------------------------------
2512357939bSOlivier Houchard */
2522357939bSOlivier Houchard extern int floatx80_rounding_precision;
2532357939bSOlivier Houchard 
2542357939bSOlivier Houchard /*
2552357939bSOlivier Houchard -------------------------------------------------------------------------------
2562357939bSOlivier Houchard Software IEC/IEEE extended double-precision operations.
2572357939bSOlivier Houchard -------------------------------------------------------------------------------
2582357939bSOlivier Houchard */
2592357939bSOlivier Houchard floatx80 floatx80_round_to_int( floatx80 );
2602357939bSOlivier Houchard floatx80 floatx80_add( floatx80, floatx80 );
2612357939bSOlivier Houchard floatx80 floatx80_sub( floatx80, floatx80 );
2622357939bSOlivier Houchard floatx80 floatx80_mul( floatx80, floatx80 );
2632357939bSOlivier Houchard floatx80 floatx80_div( floatx80, floatx80 );
2642357939bSOlivier Houchard floatx80 floatx80_rem( floatx80, floatx80 );
2652357939bSOlivier Houchard floatx80 floatx80_sqrt( floatx80 );
2662357939bSOlivier Houchard int floatx80_eq( floatx80, floatx80 );
2672357939bSOlivier Houchard int floatx80_le( floatx80, floatx80 );
2682357939bSOlivier Houchard int floatx80_lt( floatx80, floatx80 );
2692357939bSOlivier Houchard int floatx80_eq_signaling( floatx80, floatx80 );
2702357939bSOlivier Houchard int floatx80_le_quiet( floatx80, floatx80 );
2712357939bSOlivier Houchard int floatx80_lt_quiet( floatx80, floatx80 );
2722357939bSOlivier Houchard int floatx80_is_signaling_nan( floatx80 );
2732357939bSOlivier Houchard 
2742357939bSOlivier Houchard #endif
2752357939bSOlivier Houchard 
2762357939bSOlivier Houchard #ifdef FLOAT128
2772357939bSOlivier Houchard 
2782357939bSOlivier Houchard /*
2792357939bSOlivier Houchard -------------------------------------------------------------------------------
2802357939bSOlivier Houchard Software IEC/IEEE quadruple-precision conversion routines.
2812357939bSOlivier Houchard -------------------------------------------------------------------------------
2822357939bSOlivier Houchard */
2832357939bSOlivier Houchard int float128_to_int32( float128 );
2842357939bSOlivier Houchard int float128_to_int32_round_to_zero( float128 );
2852357939bSOlivier Houchard long long float128_to_int64( float128 );
2862357939bSOlivier Houchard long long float128_to_int64_round_to_zero( float128 );
2872357939bSOlivier Houchard float32 float128_to_float32( float128 );
2882357939bSOlivier Houchard float64 float128_to_float64( float128 );
2892357939bSOlivier Houchard #ifdef FLOATX80
2902357939bSOlivier Houchard floatx80 float128_to_floatx80( float128 );
2912357939bSOlivier Houchard #endif
2922357939bSOlivier Houchard 
2932357939bSOlivier Houchard /*
2942357939bSOlivier Houchard -------------------------------------------------------------------------------
2952357939bSOlivier Houchard Software IEC/IEEE quadruple-precision operations.
2962357939bSOlivier Houchard -------------------------------------------------------------------------------
2972357939bSOlivier Houchard */
2982357939bSOlivier Houchard float128 float128_round_to_int( float128 );
2992357939bSOlivier Houchard float128 float128_add( float128, float128 );
3002357939bSOlivier Houchard float128 float128_sub( float128, float128 );
3012357939bSOlivier Houchard float128 float128_mul( float128, float128 );
3022357939bSOlivier Houchard float128 float128_div( float128, float128 );
3032357939bSOlivier Houchard float128 float128_rem( float128, float128 );
3042357939bSOlivier Houchard float128 float128_sqrt( float128 );
3052357939bSOlivier Houchard int float128_eq( float128, float128 );
3062357939bSOlivier Houchard int float128_le( float128, float128 );
3072357939bSOlivier Houchard int float128_lt( float128, float128 );
3082357939bSOlivier Houchard int float128_eq_signaling( float128, float128 );
3092357939bSOlivier Houchard int float128_le_quiet( float128, float128 );
3102357939bSOlivier Houchard int float128_lt_quiet( float128, float128 );
3112357939bSOlivier Houchard int float128_is_signaling_nan( float128 );
3122357939bSOlivier Houchard 
3132357939bSOlivier Houchard #endif
3142357939bSOlivier Houchard 
315