softfloat.h revision 207151
1#ifndef TESTFLOAT_SPARC64_SOFTFLOAT_H
2#define	TESTFLOAT_SPARC64_SOFTFLOAT_H
3
4/*============================================================================
5
6This C header file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic
7Package, Release 2b.
8
9Written by John R. Hauser.  This work was made possible in part by the
10International Computer Science Institute, located at Suite 600, 1947 Center
11Street, Berkeley, California 94704.  Funding was partially provided by the
12National Science Foundation under grant MIP-9311980.  The original version
13of this code was written as part of a project to build a fixed-point vector
14processor in collaboration with the University of California at Berkeley,
15overseen by Profs. Nelson Morgan and John Wawrzynek.  More information
16is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
17arithmetic/SoftFloat.html'.
18
19THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort has
20been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
21RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
22AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
23COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
24EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
25INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
26OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
27
28Derivative works are acceptable, even for commercial purposes, so long as
29(1) the source code for the derivative work includes prominent notice that
30the work is derivative, and (2) the source code includes prominent notice with
31these four paragraphs for those parts of this code that are retained.
32
33=============================================================================*/
34
35/* $FreeBSD: head/tools/test/testfloat/sparc64/softfloat.h 207151 2010-04-24 12:11:41Z marius $ */
36
37#include <machine/ieeefp.h>
38
39/*----------------------------------------------------------------------------
40| The macro `FLOATX80' must be defined to enable the extended double-precision
41| floating-point format `floatx80'.  If this macro is not defined, the
42| `floatx80' type will not be defined, and none of the functions that either
43| input or output the `floatx80' type will be defined.  The same applies to
44| the `FLOAT128' macro and the quadruple-precision format `float128'.
45*----------------------------------------------------------------------------*/
46#define FLOATX80
47#define FLOAT128
48
49/*----------------------------------------------------------------------------
50| Software IEC/IEEE floating-point types.
51*----------------------------------------------------------------------------*/
52typedef unsigned int float32;
53typedef unsigned long float64;
54#ifdef FLOATX80
55typedef struct {
56    unsigned short high;
57    unsigned long low;
58} floatx80;
59#endif
60#ifdef FLOAT128
61typedef struct {
62    unsigned long high, low;
63} float128;
64#endif
65
66/*----------------------------------------------------------------------------
67| Software IEC/IEEE floating-point underflow tininess-detection mode.
68*----------------------------------------------------------------------------*/
69extern int float_detect_tininess;
70enum {
71    float_tininess_after_rounding  = 0,
72    float_tininess_before_rounding = 1
73};
74
75/*----------------------------------------------------------------------------
76| Software IEC/IEEE floating-point rounding mode.
77*----------------------------------------------------------------------------*/
78extern fp_rnd_t float_rounding_mode;
79enum {
80    float_round_nearest_even = 0,
81    float_round_to_zero      = 1,
82    float_round_up           = 2,
83    float_round_down         = 3
84};
85
86/*----------------------------------------------------------------------------
87| Software IEC/IEEE floating-point exception flags.
88*----------------------------------------------------------------------------*/
89typedef int fp_except;
90extern fp_except float_exception_flags;
91enum {
92    float_flag_inexact   =  1,
93    float_flag_divbyzero =  2,
94    float_flag_underflow =  4,
95    float_flag_overflow  =  8,
96    float_flag_invalid   = 16
97};
98
99/*----------------------------------------------------------------------------
100| Routine to raise any or all of the software IEC/IEEE floating-point
101| exception flags.
102*----------------------------------------------------------------------------*/
103void float_raise( int );
104
105/*----------------------------------------------------------------------------
106| Software IEC/IEEE integer-to-floating-point conversion routines.
107*----------------------------------------------------------------------------*/
108float32 int32_to_float32( int );
109float64 int32_to_float64( int );
110#ifdef FLOATX80
111floatx80 int32_to_floatx80( int );
112#endif
113#ifdef FLOAT128
114float128 int32_to_float128( int );
115#endif
116float32 int64_to_float32( long );
117float64 int64_to_float64( long );
118#ifdef FLOATX80
119floatx80 int64_to_floatx80( long );
120#endif
121#ifdef FLOAT128
122float128 int64_to_float128( long );
123#endif
124
125/*----------------------------------------------------------------------------
126| Software IEC/IEEE single-precision conversion routines.
127*----------------------------------------------------------------------------*/
128int float32_to_int32( float32 );
129int float32_to_int32_round_to_zero( float32 );
130long float32_to_int64( float32 );
131long float32_to_int64_round_to_zero( float32 );
132float64 float32_to_float64( float32 );
133#ifdef FLOATX80
134floatx80 float32_to_floatx80( float32 );
135#endif
136#ifdef FLOAT128
137float128 float32_to_float128( float32 );
138#endif
139
140/*----------------------------------------------------------------------------
141| Software IEC/IEEE single-precision operations.
142*----------------------------------------------------------------------------*/
143float32 float32_round_to_int( float32 );
144float32 float32_add( float32, float32 );
145float32 float32_sub( float32, float32 );
146float32 float32_mul( float32, float32 );
147float32 float32_div( float32, float32 );
148float32 float32_rem( float32, float32 );
149float32 float32_sqrt( float32 );
150int float32_eq( float32, float32 );
151int float32_le( float32, float32 );
152int float32_lt( float32, float32 );
153int float32_eq_signaling( float32, float32 );
154int float32_le_quiet( float32, float32 );
155int float32_lt_quiet( float32, float32 );
156int float32_is_signaling_nan( float32 );
157
158/*----------------------------------------------------------------------------
159| Software IEC/IEEE double-precision conversion routines.
160*----------------------------------------------------------------------------*/
161int float64_to_int32( float64 );
162int float64_to_int32_round_to_zero( float64 );
163long float64_to_int64( float64 );
164long float64_to_int64_round_to_zero( float64 );
165float32 float64_to_float32( float64 );
166#ifdef FLOATX80
167floatx80 float64_to_floatx80( float64 );
168#endif
169#ifdef FLOAT128
170float128 float64_to_float128( float64 );
171#endif
172
173/*----------------------------------------------------------------------------
174| Software IEC/IEEE double-precision operations.
175*----------------------------------------------------------------------------*/
176float64 float64_round_to_int( float64 );
177float64 float64_add( float64, float64 );
178float64 float64_sub( float64, float64 );
179float64 float64_mul( float64, float64 );
180float64 float64_div( float64, float64 );
181float64 float64_rem( float64, float64 );
182float64 float64_sqrt( float64 );
183int float64_eq( float64, float64 );
184int float64_le( float64, float64 );
185int float64_lt( float64, float64 );
186int float64_eq_signaling( float64, float64 );
187int float64_le_quiet( float64, float64 );
188int float64_lt_quiet( float64, float64 );
189int float64_is_signaling_nan( float64 );
190
191#ifdef FLOATX80
192
193/*----------------------------------------------------------------------------
194| Software IEC/IEEE extended double-precision conversion routines.
195*----------------------------------------------------------------------------*/
196int floatx80_to_int32( floatx80 );
197int floatx80_to_int32_round_to_zero( floatx80 );
198long floatx80_to_int64( floatx80 );
199long floatx80_to_int64_round_to_zero( floatx80 );
200float32 floatx80_to_float32( floatx80 );
201float64 floatx80_to_float64( floatx80 );
202#ifdef FLOAT128
203float128 floatx80_to_float128( floatx80 );
204#endif
205
206/*----------------------------------------------------------------------------
207| Software IEC/IEEE extended double-precision rounding precision.  Valid
208| values are 32, 64, and 80.
209*----------------------------------------------------------------------------*/
210extern int floatx80_rounding_precision;
211
212/*----------------------------------------------------------------------------
213| Software IEC/IEEE extended double-precision operations.
214*----------------------------------------------------------------------------*/
215floatx80 floatx80_round_to_int( floatx80 );
216floatx80 floatx80_add( floatx80, floatx80 );
217floatx80 floatx80_sub( floatx80, floatx80 );
218floatx80 floatx80_mul( floatx80, floatx80 );
219floatx80 floatx80_div( floatx80, floatx80 );
220floatx80 floatx80_rem( floatx80, floatx80 );
221floatx80 floatx80_sqrt( floatx80 );
222int floatx80_eq( floatx80, floatx80 );
223int floatx80_le( floatx80, floatx80 );
224int floatx80_lt( floatx80, floatx80 );
225int floatx80_eq_signaling( floatx80, floatx80 );
226int floatx80_le_quiet( floatx80, floatx80 );
227int floatx80_lt_quiet( floatx80, floatx80 );
228int floatx80_is_signaling_nan( floatx80 );
229
230#endif
231
232#ifdef FLOAT128
233
234/*----------------------------------------------------------------------------
235| Software IEC/IEEE quadruple-precision conversion routines.
236*----------------------------------------------------------------------------*/
237int float128_to_int32( float128 );
238int float128_to_int32_round_to_zero( float128 );
239long float128_to_int64( float128 );
240long float128_to_int64_round_to_zero( float128 );
241float32 float128_to_float32( float128 );
242float64 float128_to_float64( float128 );
243#ifdef FLOATX80
244floatx80 float128_to_floatx80( float128 );
245#endif
246
247/*----------------------------------------------------------------------------
248| Software IEC/IEEE quadruple-precision operations.
249*----------------------------------------------------------------------------*/
250float128 float128_round_to_int( float128 );
251float128 float128_add( float128, float128 );
252float128 float128_sub( float128, float128 );
253float128 float128_mul( float128, float128 );
254float128 float128_div( float128, float128 );
255float128 float128_rem( float128, float128 );
256float128 float128_sqrt( float128 );
257int float128_eq( float128, float128 );
258int float128_le( float128, float128 );
259int float128_lt( float128, float128 );
260int float128_eq_signaling( float128, float128 );
261int float128_le_quiet( float128, float128 );
262int float128_lt_quiet( float128, float128 );
263int float128_is_signaling_nan( float128 );
264
265#endif
266
267#endif
268