|
|
1.1 root 1: /* $Id: softfloat-tme.h,v 1.1 2005/02/17 12:17:58 fredette Exp $ */
2:
3: /* ic/ieee754/softfloat-tme.h - this glues tme to SoftFloat: */
4:
5: /*
6: * Copyright (c) 2004 Matt Fredette
7: * All rights reserved.
8: *
9: * Redistribution and use in source and binary forms, with or without
10: * modification, are permitted provided that the following conditions
11: * are met:
12: * 1. Redistributions of source code must retain the above copyright
13: * notice, this list of conditions and the following disclaimer.
14: * 2. Redistributions in binary form must reproduce the above copyright
15: * notice, this list of conditions and the following disclaimer in the
16: * documentation and/or other materials provided with the distribution.
17: * 3. All advertising materials mentioning features or use of this software
18: * must display the following acknowledgement:
19: * This product includes software developed by Matt Fredette.
20: * 4. The name of the author may not be used to endorse or promote products
21: * derived from this software without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26: * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33: * POSSIBILITY OF SUCH DAMAGE.
34: */
35:
36: /*============================================================================
37:
38: This C header file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic
39: Package, Release 2b.
40:
41: This C source fragment is part of the SoftFloat IEC/IEEE Floating-point
42: Arithmetic Package, Release 2b.
43:
44: Written by John R. Hauser. This work was made possible in part by the
45: International Computer Science Institute, located at Suite 600, 1947 Center
46: Street, Berkeley, California 94704. Funding was partially provided by the
47: National Science Foundation under grant MIP-9311980. The original version
48: of this code was written as part of a project to build a fixed-point vector
49: processor in collaboration with the University of California at Berkeley,
50: overseen by Profs. Nelson Morgan and John Wawrzynek. More information
51: is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
52: arithmetic/SoftFloat.html'.
53:
54: THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
55: been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
56: RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
57: AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
58: COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
59: EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
60: INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
61: OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
62:
63: Derivative works are acceptable, even for commercial purposes, so long as
64: (1) the source code for the derivative work includes prominent notice that
65: the work is derivative, and (2) the source code includes prominent notice with
66: these four paragraphs for those parts of this code that are retained.
67:
68: =============================================================================*/
69:
70: #ifndef _IC_IEEE754_SOFTFLOAT_TME_H
71: #define _IC_IEEE754_SOFTFLOAT_TME_H
72:
73: #include <tme/common.h>
74: _TME_RCSID("$Id: softfloat-tme.h,v 1.1 2005/02/17 12:17:58 fredette Exp $");
75:
76: /* includes: */
77: #include <tme/ic/ieee754.h>
78:
79: #ifdef _TME_IEEE754_SOFTFLOAT_GLUE
80:
81: /* create an alternate definition of struct _tme_ieee754_extended80 to
82: use as the SoftFloat 80-bit extended precision type: */
83: #undef TME_FLOAT_FORMAT_IEEE754_EXTENDED80
84: #define tme_float_ieee754_extended80 _floatx80
85: #define tme_float_ieee754_extended80_significand low
86: #define tme_float_ieee754_extended80_sexp high
87:
88: /* actually create the alternate definitions: */
89: #include <tme/generic/float.h>
90:
91: #endif /* _TME_IEEE754_SOFTFLOAT_GLUE */
92:
93: /* if a 64-bit integral type is available: */
94: #ifdef TME_HAVE_INT64_T
95:
96: /* enable SoftFloat support for the extended and quad formats: */
97: #define FLOATX80
98: #define FLOAT128
99:
100: /* the SoftFloat types: */
101: typedef tme_uint32_t float32;
102: typedef tme_uint64_t float64;
103: typedef struct tme_float_ieee754_extended80 floatx80;
104: typedef struct {
105: #ifdef _TME_WORDS_BIGENDIAN
106: tme_uint64_t high;
107: tme_uint64_t low;
108: #else /* !_TME_WORDS_BIGENDIAN */
109: tme_uint64_t low;
110: tme_uint64_t high;
111: #endif /* !_TME_WORDS_BIGENDIAN */
112: } float128;
113:
114: #else /* !TME_HAVE_INT64_T */
115:
116: /* the SoftFloat types: */
117: typedef tme_uint32_t float32;
118: typedef struct {
119: #ifdef _TME_WORDS_BIGENDIAN
120: tme_uint32_t high;
121: tme_uint32_t low;
122: #else /* !_TME_WORDS_BIGENDIAN */
123: tme_uint32_t low;
124: tme_uint32_t high;
125: #endif /* !_TME_WORDS_BIGENDIAN */
126: } float64;
127:
128: #endif /* !TME_HAVE_INT64_T */
129:
130: /* undefine all SoftFloat glue magic: */
131: #undef tme_float_ieee754_extended80
132: #undef tme_float_ieee754_extended80_significand
133: #undef tme_float_ieee754_extended80_sexp
134:
135: /*----------------------------------------------------------------------------
136: | Each of the following `typedef's defines the most convenient type that holds
137: | integers of at least as many bits as specified. For example, `uint8' should
138: | be the most convenient type that can hold unsigned integers of as many as
139: | 8 bits. The `flag' type must be able to hold either a 0 or 1. For most
140: | implementations of C, `flag', `uint8', and `int8' should all be `typedef'ed
141: | to the same as `int'.
142: *----------------------------------------------------------------------------*/
143: typedef tme_uint8_t flag;
144: typedef tme_uint8_t uint8;
145: typedef tme_int8_t int8;
146: typedef int uint16;
147: typedef int int16;
148: typedef tme_uint32_t uint32;
149: typedef tme_int32_t int32;
150: #ifdef TME_HAVE_INT64_T
151: typedef tme_uint64_t uint64;
152: typedef tme_int64_t int64;
153: #endif /* TME_HAVE_INT64_T */
154:
155: /*----------------------------------------------------------------------------
156: | Each of the following `typedef's defines a type that holds integers
157: | of _exactly_ the number of bits specified. For instance, for most
158: | implementation of C, `bits16' and `sbits16' should be `typedef'ed to
159: | `unsigned short int' and `signed short int' (or `short int'), respectively.
160: *----------------------------------------------------------------------------*/
161: typedef tme_uint8_t bits8;
162: typedef tme_int8_t sbits8;
163: typedef tme_uint16_t bits16;
164: typedef tme_int16_t sbits16;
165: typedef tme_uint32_t bits32;
166: typedef tme_int32_t sbits32;
167: #ifdef TME_HAVE_INT64_T
168: typedef tme_uint64_t bits64;
169: typedef tme_int64_t sbits64;
170: #endif /* TME_HAVE_INT64_T */
171:
172: /*----------------------------------------------------------------------------
173: | Software IEC/IEEE integer-to-floating-point conversion routines.
174: *----------------------------------------------------------------------------*/
175: float32 int32_to_float32 _TME_P(( tme_int32_t ));
176: float64 int32_to_float64 _TME_P(( tme_int32_t ));
177: #ifdef FLOATX80
178: floatx80 int32_to_floatx80 _TME_P(( tme_int32_t ));
179: #endif /* FLOATX80 */
180: #ifdef FLOAT128
181: float128 int32_to_float128 _TME_P(( tme_int32_t ));
182: #endif /* FLOAT128 */
183: #ifdef TME_HAVE_INT64_T
184: float32 int64_to_float32 _TME_P(( tme_int64_t ));
185: float64 int64_to_float64 _TME_P(( tme_int64_t ));
186: #endif /* TME_HAVE_INT64_T */
187: #ifdef FLOATX80
188: floatx80 int64_to_floatx80 _TME_P(( tme_int64_t ));
189: #endif /* FLOATX80 */
190: #ifdef FLOAT128
191: float128 int64_to_float128 _TME_P(( tme_int64_t ));
192: #endif /* FLOAT128 */
193:
194: /*----------------------------------------------------------------------------
195: | Software IEC/IEEE single-precision conversion routines.
196: *----------------------------------------------------------------------------*/
197: tme_int32_t float32_to_int32 _TME_P(( float32 ));
198: tme_int32_t float32_to_int32_round_to_zero _TME_P(( float32 ));
199: #ifdef TME_HAVE_INT64_T
200: tme_int64_t float32_to_int64 _TME_P(( float32 ));
201: tme_int64_t float32_to_int64_round_to_zero _TME_P(( float32 ));
202: #endif /* TME_HAVE_INT64_T */
203: float64 float32_to_float64 _TME_P(( float32 ));
204: #ifdef FLOATX80
205: floatx80 float32_to_floatx80 _TME_P(( float32 ));
206: #endif /* FLOATX80 */
207: #ifdef FLOAT128
208: float128 float32_to_float128 _TME_P(( float32 ));
209: #endif /* FLOAT128 */
210:
211: /*----------------------------------------------------------------------------
212: | Software IEC/IEEE single-precision operations.
213: *----------------------------------------------------------------------------*/
214: float32 float32_round_to_int _TME_P(( float32 ));
215: float32 float32_add _TME_P(( float32, float32 ));
216: float32 float32_sub _TME_P(( float32, float32 ));
217: float32 float32_mul _TME_P(( float32, float32 ));
218: float32 float32_div _TME_P(( float32, float32 ));
219: float32 float32_rem _TME_P(( float32, float32 ));
220: float32 float32_sqrt _TME_P(( float32 ));
221: flag float32_eq _TME_P(( float32, float32 ));
222: flag float32_le _TME_P(( float32, float32 ));
223: flag float32_lt _TME_P(( float32, float32 ));
224: flag float32_eq_signaling _TME_P(( float32, float32 ));
225: flag float32_le_quiet _TME_P(( float32, float32 ));
226: flag float32_lt_quiet _TME_P(( float32, float32 ));
227:
228: /*----------------------------------------------------------------------------
229: | Software IEC/IEEE double-precision conversion routines.
230: *----------------------------------------------------------------------------*/
231: tme_int32_t float64_to_int32 _TME_P(( float64 ));
232: tme_int32_t float64_to_int32_round_to_zero _TME_P(( float64 ));
233: #ifdef TME_HAVE_INT64_T
234: tme_int64_t float64_to_int64 _TME_P(( float64 ));
235: tme_int64_t float64_to_int64_round_to_zero _TME_P(( float64 ));
236: #endif /* TME_HAVE_INT64_T */
237: float32 float64_to_float32 _TME_P(( float64 ));
238: #ifdef FLOATX80
239: floatx80 float64_to_floatx80 _TME_P(( float64 ));
240: #endif /* FLOATX80 */
241: #ifdef FLOAT128
242: float128 float64_to_float128 _TME_P(( float64 ));
243: #endif /* FLOAT128 */
244:
245: /*----------------------------------------------------------------------------
246: | Software IEC/IEEE double-precision operations.
247: *----------------------------------------------------------------------------*/
248: float64 float64_round_to_int _TME_P(( float64 ));
249: float64 float64_add _TME_P(( float64, float64 ));
250: float64 float64_sub _TME_P(( float64, float64 ));
251: float64 float64_mul _TME_P(( float64, float64 ));
252: float64 float64_div _TME_P(( float64, float64 ));
253: float64 float64_rem _TME_P(( float64, float64 ));
254: float64 float64_sqrt _TME_P(( float64 ));
255: flag float64_eq _TME_P(( float64, float64 ));
256: flag float64_le _TME_P(( float64, float64 ));
257: flag float64_lt _TME_P(( float64, float64 ));
258: flag float64_eq_signaling _TME_P(( float64, float64 ));
259: flag float64_le_quiet _TME_P(( float64, float64 ));
260: flag float64_lt_quiet _TME_P(( float64, float64 ));
261:
262: #ifdef FLOATX80
263:
264: /*----------------------------------------------------------------------------
265: | Software IEC/IEEE extended double-precision conversion routines.
266: *----------------------------------------------------------------------------*/
267: tme_int32_t floatx80_to_int32 _TME_P(( floatx80 ));
268: tme_int32_t floatx80_to_int32_round_to_zero _TME_P(( floatx80 ));
269: #ifdef TME_HAVE_INT64_T
270: tme_int64_t floatx80_to_int64 _TME_P(( floatx80 ));
271: tme_int64_t floatx80_to_int64_round_to_zero _TME_P(( floatx80 ));
272: #endif /* TME_HAVE_INT64_T */
273: float32 floatx80_to_float32 _TME_P(( floatx80 ));
274: float64 floatx80_to_float64 _TME_P(( floatx80 ));
275: #ifdef FLOAT128
276: float128 floatx80_to_float128 _TME_P(( floatx80 ));
277: #endif /* FLOAT128 */
278:
279: /*----------------------------------------------------------------------------
280: | Software IEC/IEEE extended double-precision operations.
281: *----------------------------------------------------------------------------*/
282: floatx80 floatx80_round_to_int _TME_P(( floatx80 ));
283: floatx80 floatx80_add _TME_P(( floatx80, floatx80 ));
284: floatx80 floatx80_sub _TME_P(( floatx80, floatx80 ));
285: floatx80 floatx80_mul _TME_P(( floatx80, floatx80 ));
286: floatx80 floatx80_div _TME_P(( floatx80, floatx80 ));
287: floatx80 floatx80_rem _TME_P(( floatx80, floatx80 ));
288: floatx80 floatx80_sqrt _TME_P(( floatx80 ));
289: flag floatx80_eq _TME_P(( floatx80, floatx80 ));
290: flag floatx80_le _TME_P(( floatx80, floatx80 ));
291: flag floatx80_lt _TME_P(( floatx80, floatx80 ));
292: flag floatx80_eq_signaling _TME_P(( floatx80, floatx80 ));
293: flag floatx80_le_quiet _TME_P(( floatx80, floatx80 ));
294: flag floatx80_lt_quiet _TME_P(( floatx80, floatx80 ));
295:
296: #endif /* FLOATX80 */
297:
298: #ifdef FLOAT128
299:
300: /*----------------------------------------------------------------------------
301: | Software IEC/IEEE quadruple-precision conversion routines.
302: *----------------------------------------------------------------------------*/
303: tme_int32_t float128_to_int32 _TME_P(( float128 ));
304: tme_int32_t float128_to_int32_round_to_zero _TME_P(( float128 ));
305: tme_int64_t float128_to_int64 _TME_P(( float128 ));
306: tme_int64_t float128_to_int64_round_to_zero _TME_P(( float128 ));
307: float32 float128_to_float32 _TME_P(( float128 ));
308: float64 float128_to_float64 _TME_P(( float128 ));
309: #ifdef FLOATX80
310: floatx80 float128_to_floatx80 _TME_P(( float128 ));
311: #endif
312:
313: /*----------------------------------------------------------------------------
314: | Software IEC/IEEE quadruple-precision operations.
315: *----------------------------------------------------------------------------*/
316: float128 float128_round_to_int _TME_P(( float128 ));
317: float128 float128_add _TME_P(( float128, float128 ));
318: float128 float128_sub _TME_P(( float128, float128 ));
319: float128 float128_mul _TME_P(( float128, float128 ));
320: float128 float128_div _TME_P(( float128, float128 ));
321: float128 float128_rem _TME_P(( float128, float128 ));
322: float128 float128_sqrt _TME_P(( float128 ));
323: flag float128_eq _TME_P(( float128, float128 ));
324: flag float128_le _TME_P(( float128, float128 ));
325: flag float128_lt _TME_P(( float128, float128 ));
326: flag float128_eq_signaling _TME_P(( float128, float128 ));
327: flag float128_le_quiet _TME_P(( float128, float128 ));
328: flag float128_lt_quiet _TME_P(( float128, float128 ));
329:
330: #endif /* FLOAT128 */
331:
332: #endif /* _IC_IEEE754_SOFTFLOAT_TME_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.