softfloat.h revision 178d85b8274f9ac82fb553c80760bbbb4044401c
/*============================================================================
Package, Release 2b.
Written by John R. Hauser. This work was made possible in part by the
International Computer Science Institute, located at Suite 600, 1947 Center
Street, Berkeley, California 94704. Funding was partially provided by the
National Science Foundation under grant MIP-9311980. The original version
of this code was written as part of a project to build a fixed-point vector
processor in collaboration with the University of California at Berkeley,
overseen by Profs. Nelson Morgan and John Wawrzynek. More information
is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
Derivative works are acceptable, even for commercial purposes, so long as
(1) the source code for the derivative work includes prominent notice that
the work is derivative, and (2) the source code includes prominent notice with
these four paragraphs for those parts of this code that are retained.
=============================================================================*/
#ifndef SOFTFLOAT_H
#define SOFTFLOAT_H
#ifdef VBOX
#endif
#if defined(HOST_SOLARIS) && defined(NEEDS_LIBSUNMATH)
#include <sunmath.h>
#endif
#include <inttypes.h>
#include "config.h"
/*----------------------------------------------------------------------------
| Each of the following `typedef's defines the most convenient type that holds
| integers of at least as many bits as specified. For example, `uint8' should
| be the most convenient type that can hold unsigned integers of as many as
| 8 bits. The `flag' type must be able to hold either a 0 or 1. For most
| implementations of C, `flag', `uint8', and `int8' should all be `typedef'ed
| to the same as `int'.
*----------------------------------------------------------------------------*/
typedef int uint16;
typedef int int16;
typedef unsigned int uint32;
typedef signed int int32;
/*----------------------------------------------------------------------------
| Each of the following `typedef's defines a type that holds integers
| of _exactly_ the number of bits specified. For instance, for most
| implementation of C, `bits16' and `sbits16' should be `typedef'ed to
| `unsigned short int' and `signed short int' (or `short int'), respectively.
*----------------------------------------------------------------------------*/
#define INLINE static inline
/*----------------------------------------------------------------------------
| The macro `FLOATX80' must be defined to enable the extended double-precision
| floating-point format `floatx80'. If this macro is not defined, the
| `floatx80' type will not be defined, and none of the functions that either
| input or output the `floatx80' type will be defined. The same applies to
| the `FLOAT128' macro and the quadruple-precision format `float128'.
*----------------------------------------------------------------------------*/
#ifdef CONFIG_SOFTFLOAT
/* bit exact soft float support */
#define FLOATX80
#define FLOAT128
#else
/* native float support */
#if (defined(__i386__) || defined(__x86_64__)) && (!defined(_BSD) || defined(VBOX)) /** @todo VBOX: not correct on windows */
#define FLOATX80
#endif
#endif /* !CONFIG_SOFTFLOAT */
#endif
#define STATUS_VAR , status
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
enum {
float_relation_less = -1,
float_relation_equal = 0,
};
#ifdef CONFIG_SOFTFLOAT
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
/* Use structures for soft-float types. This prevents accidentally mixing
sane ABI should be able to see though these structs. However
//#define USE_SOFTFLOAT_STRUCT_TYPES
#ifdef USE_SOFTFLOAT_STRUCT_TYPES
typedef struct {
uint32_t v;
} float32;
/* The cast ensures an error if the wrong type is passed. */
#define float32_val(x) (((float32)(x)).v)
typedef struct {
uint64_t v;
} float64;
#define float64_val(x) (((float64)(x)).v)
#else
#define float32_val(x) (x)
#define float64_val(x) (x)
#define make_float32(x) (x)
#define make_float64(x) (x)
#endif
#ifdef FLOATX80
typedef struct {
} floatx80;
#endif
#ifdef FLOAT128
typedef struct {
#ifdef WORDS_BIGENDIAN
#else
#endif
} float128;
#endif
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
enum {
};
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
enum {
float_round_down = 1,
float_round_up = 2,
};
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
enum {
float_flag_invalid = 1,
float_flag_divbyzero = 4,
float_flag_overflow = 8,
float_flag_underflow = 16,
float_flag_inexact = 32
};
typedef struct float_status {
signed char float_detect_tininess;
signed char float_rounding_mode;
signed char float_exception_flags;
#ifdef FLOATX80
signed char floatx80_rounding_precision;
#endif
} float_status;
{
return STATUS(float_exception_flags);
}
#ifdef FLOATX80
#endif
/*----------------------------------------------------------------------------
| exception flags.
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
#ifdef FLOATX80
#endif
#ifdef FLOAT128
#endif
#ifdef FLOATX80
#endif
#ifdef FLOAT128
#endif
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
#ifdef FLOATX80
#endif
#ifdef FLOAT128
#endif
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
int float32_is_nan( float32 );
int float32_is_signaling_nan( float32 );
{
}
{
}
#define float32_zero make_float32(0)
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
#ifdef FLOATX80
#endif
#ifdef FLOAT128
#endif
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
int float64_is_nan( float64 a );
int float64_is_signaling_nan( float64 );
{
}
{
}
#define float64_zero make_float64(0)
#ifdef FLOATX80
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
#ifdef FLOAT128
#endif
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
int floatx80_is_nan( floatx80 );
int floatx80_is_signaling_nan( floatx80 );
{
a.high &= 0x7fff;
return a;
}
{
a.high ^= 0x8000;
return a;
}
#endif
#ifdef FLOAT128
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
#ifdef FLOATX80
#endif
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
int float128_is_nan( float128 );
int float128_is_signaling_nan( float128 );
{
a.high &= 0x7fffffffffffffffLL;
return a;
}
{
a.high ^= 0x8000000000000000LL;
return a;
}
#endif
#else /* CONFIG_SOFTFLOAT */
#include "softfloat-native.h"
#endif /* !CONFIG_SOFTFLOAT */
#endif /* !SOFTFLOAT_H */