|
|
1.1 root 1:
2: /*============================================================================
3:
4: This C header file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic
5: Package, Release 2b.
6:
7: Written by John R. Hauser. This work was made possible in part by the
8: International Computer Science Institute, located at Suite 600, 1947 Center
9: Street, Berkeley, California 94704. Funding was partially provided by the
10: National Science Foundation under grant MIP-9311980. The original version
11: of this code was written as part of a project to build a fixed-point vector
12: processor in collaboration with the University of California at Berkeley,
13: overseen by Profs. Nelson Morgan and John Wawrzynek. More information
14: is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
15: arithmetic/SoftFloat.html'.
16:
17: THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
18: been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
19: RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
20: AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
21: COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
22: EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
23: INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
24: OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
25:
26: Derivative works are acceptable, even for commercial purposes, so long as
27: (1) the source code for the derivative work includes prominent notice that
28: the work is derivative, and (2) the source code includes prominent notice with
29: these four paragraphs for those parts of this code that are retained.
30:
31: =============================================================================*/
32:
33: #ifndef SOFTFLOAT_H
34: #define SOFTFLOAT_H
35: /*----------------------------------------------------------------------------
36: | The macro `FLOATX80' must be defined to enable the extended double-precision
37: | floating-point format `floatx80'. If this macro is not defined, the
38: | `floatx80' type will not be defined, and none of the functions that either
39: | input or output the `floatx80' type will be defined. The same applies to
40: | the `FLOAT128' macro and the quadruple-precision format `float128'.
41: *----------------------------------------------------------------------------*/
42: #define FLOATX80
43: #define FLOAT128
44:
45: /*----------------------------------------------------------------------------
46: | Software IEC/IEEE floating-point types.
47: *----------------------------------------------------------------------------*/
48:
49: #include "mamesf.h"
50:
51: typedef bits32 float32;
52: typedef bits64 float64;
53: #ifdef FLOATX80
54: typedef struct {
55: bits16 high;
56: bits64 low;
57: } floatx80;
58: #endif
59: #ifdef FLOAT128
60: typedef struct {
61: bits64 high, low;
62: } float128;
63: #endif
64:
65: /*----------------------------------------------------------------------------
66: | Primitive arithmetic functions, including multi-word arithmetic, and
67: | division and square root approximations. (Can be specialized to target if
68: | desired.)
69: *----------------------------------------------------------------------------*/
70: #include "softfloat-macros.h"
71:
72: /*----------------------------------------------------------------------------
73: | Software IEC/IEEE floating-point underflow tininess-detection mode.
74: *----------------------------------------------------------------------------*/
75: #if 0
76: extern int8 float_detect_tininess;
77: #endif
78: enum {
79: float_tininess_after_rounding = 0,
80: float_tininess_before_rounding = 1
81: };
82:
83: /*----------------------------------------------------------------------------
84: | Software IEC/IEEE floating-point rounding mode.
85: *----------------------------------------------------------------------------*/
86: #if 0
87: extern int8 float_rounding_mode;
88: #ifdef SOFTFLOAT_I860
89: extern int8 float_rounding_mode2;
90: #endif
91: #endif
92: enum {
93: float_round_nearest_even = 0,
94: float_round_to_zero = 1,
95: float_round_down = 2,
96: float_round_up = 3
97: };
98:
99: /*----------------------------------------------------------------------------
100: | Software IEC/IEEE floating-point exception flags.
101: *----------------------------------------------------------------------------*/
102: #if 0
103: extern int8 float_exception_flags;
104: #ifdef SOFTFLOAT_I860
105: extern int8 float_exception_flags2;
106: #endif
107: #endif
108: enum {
109: float_flag_invalid = 0x01, float_flag_denormal = 0x02, float_flag_divbyzero = 0x04, float_flag_overflow = 0x08,
110: float_flag_underflow = 0x10, float_flag_inexact = 0x20, float_flag_signaling = 0x40, float_flag_decimal = 0x80
111: };
112:
113: /*----------------------------------------------------------------------------
114: | Variables for storing sign, exponent and significand of internal extended
115: | double-precision floating-point value for external use.
116: *----------------------------------------------------------------------------*/
117: #if 0
118: extern flag floatx80_internal_sign;
119: extern int32 floatx80_internal_exp;
120: extern bits64 floatx80_internal_sig0;
121: extern bits64 floatx80_internal_sig1;
122: extern int8 floatx80_internal_precision;
123: extern int8 floatx80_internal_mode;
124: #endif
125:
126:
127: typedef struct {
128: int8 float_detect_tininess;
129: int8 float_exception_flags;
130: int8 float_rounding_mode;
131: #ifdef FLOATX80
132: int8 floatx80_rounding_precision;
133: flag floatx80_internal_sign;
134: int32 floatx80_internal_exp;
135: bits64 floatx80_internal_sig0;
136: bits64 floatx80_internal_sig1;
137: int8 floatx80_internal_precision;
138: int8 floatx80_internal_mode;
139: #endif
140: } float_ctrl;
141:
142: void float_init( float_ctrl* c );
143: int8 get_float_rounding_mode( float_ctrl* c );
144: void set_float_rounding_mode( int8 mode, float_ctrl* c );
145: int8 get_float_rounding_precision( float_ctrl* c );
146: void set_float_rounding_precision( int8 precision, float_ctrl* c );
147: int8 get_float_exception_flags( float_ctrl* c );
148: void set_float_exception_flags( int8 flags, float_ctrl* c );
149: int8 get_float_detect_tininess( float_ctrl* c );
150: void set_float_detect_tininess( int8 mode, float_ctrl* c );
151:
152: /*----------------------------------------------------------------------------
153: | Function for getting sign, exponent and significand of extended
154: | double-precision floating-point intermediate result for external use.
155: *----------------------------------------------------------------------------*/
156: floatx80 getFloatInternalOverflow( float_ctrl* c );
157: floatx80 getFloatInternalUnderflow( float_ctrl* c );
158: floatx80 getFloatInternalRoundedAll( float_ctrl* c );
159: floatx80 getFloatInternalRoundedSome( float_ctrl* c );
160: floatx80 getFloatInternalUnrounded( float_ctrl* c );
161: floatx80 getFloatInternalFloatx80( float_ctrl* c );
162: bits64 getFloatInternalGRS( float_ctrl* c );
163:
164: /*----------------------------------------------------------------------------
165: | Routine to raise any or all of the software IEC/IEEE floating-point
166: | exception flags.
167: *----------------------------------------------------------------------------*/
168: void float_raise( int8, float_ctrl* c );
169: #if 0
170: #ifdef SOFTFLOAT_I860
171: void float_raise2( int8 );
172: #endif
173: #endif
174:
175: /*----------------------------------------------------------------------------
176: | The pattern for a default generated single-precision NaN.
177: *----------------------------------------------------------------------------*/
178: #define float32_default_nan 0x7FFFFFFF
179:
180: /*----------------------------------------------------------------------------
181: | The pattern for a default generated double-precision NaN.
182: *----------------------------------------------------------------------------*/
183: #define float64_default_nan LIT64( 0x7FFFFFFFFFFFFFFF )
184:
185: #ifdef FLOATX80
186: /*----------------------------------------------------------------------------
187: | The pattern for a default generated extended double-precision NaN. The
188: | `high' and `low' values hold the most- and least-significant bits,
189: | respectively.
190: *----------------------------------------------------------------------------*/
191: #define floatx80_default_nan_high 0x7FFF
192: #define floatx80_default_nan_low LIT64( 0xFFFFFFFFFFFFFFFF )
193: #endif
194: #ifdef FLOAT128
195: /*----------------------------------------------------------------------------
196: | The pattern for a default generated quadruple-precision NaN. The `high' and
197: | `low' values hold the most- and least-significant bits, respectively.
198: *----------------------------------------------------------------------------*/
199: #define float128_default_nan_high LIT64( 0x7FFFFFFFFFFFFFFF )
200: #define float128_default_nan_low LIT64( 0xFFFFFFFFFFFFFFFF )
201: #endif
202: #ifdef FLOATX80
203: /*----------------------------------------------------------------------------
204: | The pattern for a default generated extended double-precision infinity.
205: *----------------------------------------------------------------------------*/
206: #define floatx80_default_infinity_low LIT64( 0x0000000000000000 )
207: #endif
208:
209: /*----------------------------------------------------------------------------
210: | Software IEC/IEEE integer-to-floating-point conversion routines.
211: *----------------------------------------------------------------------------*/
212: float32 int32_to_float32( int32, float_ctrl* );
213: float64 int32_to_float64( int32 );
214: #ifdef FLOATX80
215: floatx80 int32_to_floatx80( int32 );
216: #endif
217: #ifdef FLOAT128
218: float128 int32_to_float128( int32 );
219: #endif
220: float32 int64_to_float32( int64, float_ctrl* );
221: float64 int64_to_float64( int64, float_ctrl* );
222: #ifdef FLOATX80
223: floatx80 int64_to_floatx80( int64 );
224: #endif
225: #ifdef FLOAT128
226: float128 int64_to_float128( int64 );
227: #endif
228:
229: /*----------------------------------------------------------------------------
230: | Software IEC/IEEE single-precision conversion routines.
231: *----------------------------------------------------------------------------*/
232: int32 float32_to_int32( float32, float_ctrl* );
233: int32 float32_to_int32_round_to_zero( float32, float_ctrl* );
234: int64 float32_to_int64( float32, float_ctrl* );
235: int64 float32_to_int64_round_to_zero( float32, float_ctrl* );
236: float64 float32_to_float64( float32, float_ctrl* );
237: #ifdef FLOATX80
238: floatx80 float32_to_floatx80( float32, float_ctrl* );
239: floatx80 float32_to_floatx80_allowunnormal( float32 );
240: #endif
241: #ifdef FLOAT128
242: float128 float32_to_float128( float32, float_ctrl* );
243: #endif
244:
245: /*----------------------------------------------------------------------------
246: | Software IEC/IEEE single-precision operations.
247: *----------------------------------------------------------------------------*/
248: float32 float32_round_to_int( float32, float_ctrl* );
249: float32 float32_add( float32, float32, float_ctrl* );
250: float32 float32_sub( float32, float32, float_ctrl* );
251: float32 float32_mul( float32, float32, float_ctrl* );
252: float32 float32_div( float32, float32, float_ctrl* );
253: float32 float32_rem( float32, float32, float_ctrl* );
254: float32 float32_sqrt( float32, float_ctrl* );
255: flag float32_eq( float32, float32, float_ctrl* );
256: flag float32_le( float32, float32, float_ctrl* );
257: flag float32_lt( float32, float32, float_ctrl* );
258: #ifdef SOFTFLOAT_I860
259: flag float32_gt( float32, float32, float_ctrl* );
260: #endif
261: flag float32_eq_signaling( float32, float32, float_ctrl* );
262: flag float32_le_quiet( float32, float32, float_ctrl* );
263: flag float32_lt_quiet( float32, float32, float_ctrl* );
264: flag float32_is_signaling_nan( float32 );
265:
266: /*----------------------------------------------------------------------------
267: | Software IEC/IEEE double-precision conversion routines.
268: *----------------------------------------------------------------------------*/
269: int32 float64_to_int32( float64, float_ctrl* );
270: int32 float64_to_int32_round_to_zero( float64, float_ctrl* );
271: int64 float64_to_int64( float64, float_ctrl* );
272: int64 float64_to_int64_round_to_zero( float64, float_ctrl* );
273: float32 float64_to_float32( float64, float_ctrl* );
274: #ifdef FLOATX80
275: floatx80 float64_to_floatx80( float64, float_ctrl* );
276: floatx80 float64_to_floatx80_allowunnormal( float64 );
277: #endif
278: #ifdef FLOAT128
279: float128 float64_to_float128( float64, float_ctrl* );
280: #endif
281:
282: /*----------------------------------------------------------------------------
283: | Software IEC/IEEE double-precision operations.
284: *----------------------------------------------------------------------------*/
285: float64 float64_round_to_int( float64, float_ctrl* );
286: float64 float64_add( float64, float64, float_ctrl* );
287: float64 float64_sub( float64, float64, float_ctrl* );
288: float64 float64_mul( float64, float64, float_ctrl* );
289: float64 float64_div( float64, float64, float_ctrl* );
290: float64 float64_rem( float64, float64, float_ctrl* );
291: float64 float64_sqrt( float64, float_ctrl* );
292: flag float64_eq( float64, float64, float_ctrl* );
293: flag float64_le( float64, float64, float_ctrl* );
294: flag float64_lt( float64, float64, float_ctrl* );
295: #ifdef SOFTFLOAT_I860
296: flag float64_gt( float64, float64, float_ctrl* );
297: #endif
298: flag float64_eq_signaling( float64, float64, float_ctrl* );
299: flag float64_le_quiet( float64, float64, float_ctrl* );
300: flag float64_lt_quiet( float64, float64, float_ctrl* );
301: flag float64_is_signaling_nan( float64 );
302:
303: #ifdef FLOATX80
304:
305: /*----------------------------------------------------------------------------
306: | Software IEC/IEEE extended double-precision conversion routines.
307: *----------------------------------------------------------------------------*/
308: int32 floatx80_to_int32( floatx80, float_ctrl* );
309: #ifdef SOFTFLOAT_68K
310: int16 floatx80_to_int16( floatx80, float_ctrl* );
311: int8 floatx80_to_int8( floatx80, float_ctrl* );
312: #endif
313: int32 floatx80_to_int32_round_to_zero( floatx80, float_ctrl* );
314: int64 floatx80_to_int64( floatx80, float_ctrl* );
315: int64 floatx80_to_int64_round_to_zero( floatx80, float_ctrl* );
316: float32 floatx80_to_float32( floatx80, float_ctrl* );
317: float64 floatx80_to_float64( floatx80, float_ctrl* );
318: #ifdef SOFTFLOAT_68K
319: floatx80 floatx80_to_floatx80( floatx80, float_ctrl* );
320: floatx80 floatdecimal_to_floatx80( floatx80, float_ctrl* );
321: floatx80 floatx80_to_floatdecimal( floatx80, int32*, float_ctrl* );
322: #endif
323: #ifdef FLOAT128
324: float128 floatx80_to_float128( floatx80, float_ctrl* );
325: #endif
326: bits64 extractFloatx80Frac( floatx80 a );
327: int32 extractFloatx80Exp( floatx80 a );
328: flag extractFloatx80Sign( floatx80 a );
329:
330: /*----------------------------------------------------------------------------
331: | Software IEC/IEEE extended double-precision rounding precision. Valid
332: | values are 32, 64, and 80.
333: *----------------------------------------------------------------------------*/
334: #if 0
335: extern int8 floatx80_rounding_precision;
336: #endif
337:
338: /*----------------------------------------------------------------------------
339: | Software IEC/IEEE extended double-precision operations.
340: *----------------------------------------------------------------------------*/
341: floatx80 floatx80_round_to_int( floatx80, float_ctrl* );
342: #ifdef SOFTFLOAT_68K
343: floatx80 floatx80_round_to_int_toward_zero( floatx80, float_ctrl* );
344: floatx80 floatx80_round_to_float32( floatx80, float_ctrl* );
345: floatx80 floatx80_round_to_float64( floatx80, float_ctrl* );
346: floatx80 floatx80_round32( floatx80, float_ctrl* );
347: floatx80 floatx80_round64( floatx80, float_ctrl* );
348: floatx80 floatx80_normalize( floatx80 );
349: floatx80 floatx80_denormalize( floatx80, flag );
350: #endif
351: floatx80 floatx80_add( floatx80, floatx80, float_ctrl* );
352: floatx80 floatx80_sub( floatx80, floatx80, float_ctrl* );
353: floatx80 floatx80_mul( floatx80, floatx80, float_ctrl* );
354: floatx80 floatx80_div( floatx80, floatx80, float_ctrl* );
355: #ifndef SOFTFLOAT_68K
356: floatx80 floatx80_rem( floatx80, floatx80, float_ctrl* );
357: #endif
358: floatx80 floatx80_sqrt( floatx80, float_ctrl* );
359:
360: flag floatx80_eq( floatx80, floatx80, float_ctrl* );
361: flag floatx80_le( floatx80, floatx80, float_ctrl* );
362: flag floatx80_lt( floatx80, floatx80, float_ctrl* );
363: flag floatx80_eq_signaling( floatx80, floatx80, float_ctrl* );
364: flag floatx80_le_quiet( floatx80, floatx80, float_ctrl* );
365: flag floatx80_lt_quiet( floatx80, floatx80, float_ctrl* );
366:
367: flag floatx80_is_signaling_nan( floatx80 );
368: flag floatx80_is_nan( floatx80 );
369: #ifdef SOFTFLOAT_68K
370: flag floatx80_is_zero( floatx80 );
371: flag floatx80_is_infinity( floatx80 );
372: flag floatx80_is_negative( floatx80 );
373: flag floatx80_is_denormal( floatx80 );
374: flag floatx80_is_unnormal( floatx80 );
375: flag floatx80_is_normal( floatx80 );
376:
377: // functions are in softfloat.c
378: floatx80 floatx80_move( floatx80 a, float_ctrl* c );
379: floatx80 floatx80_abs( floatx80 a, float_ctrl* c );
380: floatx80 floatx80_neg( floatx80 a, float_ctrl* c );
381: floatx80 floatx80_getexp( floatx80 a, float_ctrl* c );
382: floatx80 floatx80_getman( floatx80 a, float_ctrl* c );
383: floatx80 floatx80_scale(floatx80 a, floatx80 b, float_ctrl* c );
384: floatx80 floatx80_rem( floatx80 a, floatx80 b, bits64 *q, flag *s, float_ctrl* c );
385: floatx80 floatx80_mod( floatx80 a, floatx80 b, bits64 *q, flag *s, float_ctrl* c );
386: floatx80 floatx80_sglmul( floatx80 a, floatx80 b, float_ctrl* c );
387: floatx80 floatx80_sgldiv( floatx80 a, floatx80 b, float_ctrl* c );
388: floatx80 floatx80_cmp( floatx80 a, floatx80 b, float_ctrl* c );
389: floatx80 floatx80_tst( floatx80 a, float_ctrl* c );
390:
391: // functions are in softfloat_fpsp.c
392: floatx80 floatx80_acos(floatx80 a, float_ctrl* c);
393: floatx80 floatx80_asin(floatx80 a, float_ctrl* c);
394: floatx80 floatx80_atan(floatx80 a, float_ctrl* c);
395: floatx80 floatx80_atanh(floatx80 a, float_ctrl* c);
396: floatx80 floatx80_cos(floatx80 a, float_ctrl* c);
397: floatx80 floatx80_cosh(floatx80 a, float_ctrl* c);
398: floatx80 floatx80_etox(floatx80 a, float_ctrl* c);
399: floatx80 floatx80_etoxm1(floatx80 a, float_ctrl* c);
400: floatx80 floatx80_log10(floatx80 a, float_ctrl* c);
401: floatx80 floatx80_log2(floatx80 a, float_ctrl* c);
402: floatx80 floatx80_logn(floatx80 a, float_ctrl* c);
403: floatx80 floatx80_lognp1(floatx80 a, float_ctrl* c);
404: floatx80 floatx80_sin(floatx80 a, float_ctrl* c);
405: floatx80 floatx80_sinh(floatx80 a, float_ctrl* c);
406: floatx80 floatx80_tan(floatx80 a, float_ctrl* c);
407: floatx80 floatx80_tanh(floatx80 a, float_ctrl* c);
408: floatx80 floatx80_tentox(floatx80 a, float_ctrl* c);
409: floatx80 floatx80_twotox(floatx80 a, float_ctrl* c);
410: #endif
411:
412: // functions originally internal to softfloat.c
413: void normalizeFloatx80Subnormal( bits64 aSig, int32 *zExpPtr, bits64 *zSigPtr );
414: floatx80 packFloatx80( flag zSign, int32 zExp, bits64 zSig );
415: floatx80 roundAndPackFloatx80( int8 roundingPrecision, flag zSign, int32 zExp, bits64 zSig0, bits64 zSig1, float_ctrl* c );
416:
417: // functions are in softfloat-specialize.h
418: floatx80 propagateFloatx80NaNOneArg( floatx80 a, float_ctrl* c );
419: floatx80 propagateFloatx80NaN( floatx80 a, floatx80 b, float_ctrl* c );
420:
421: #endif
422:
423: #ifdef FLOAT128
424:
425: /*----------------------------------------------------------------------------
426: | Software IEC/IEEE quadruple-precision conversion routines.
427: *----------------------------------------------------------------------------*/
428: int32 float128_to_int32( float128, float_ctrl* );
429: int32 float128_to_int32_round_to_zero( float128, float_ctrl* );
430: int64 float128_to_int64( float128, float_ctrl* );
431: int64 float128_to_int64_round_to_zero( float128, float_ctrl* );
432: float32 float128_to_float32( float128, float_ctrl* );
433: float64 float128_to_float64( float128, float_ctrl* );
434: #ifdef FLOATX80
435: floatx80 float128_to_floatx80( float128, float_ctrl* );
436: #endif
437:
438: /*----------------------------------------------------------------------------
439: | Software IEC/IEEE quadruple-precision operations.
440: *----------------------------------------------------------------------------*/
441: float128 float128_round_to_int( float128, float_ctrl* );
442: float128 float128_add( float128, float128, float_ctrl* );
443: float128 float128_sub( float128, float128, float_ctrl* );
444: float128 float128_mul( float128, float128, float_ctrl* );
445: float128 float128_div( float128, float128, float_ctrl* );
446: float128 float128_rem( float128, float128, float_ctrl* );
447: float128 float128_sqrt( float128, float_ctrl* );
448: flag float128_eq( float128, float128, float_ctrl* );
449: flag float128_le( float128, float128, float_ctrl* );
450: flag float128_lt( float128, float128, float_ctrl* );
451: flag float128_eq_signaling( float128, float128, float_ctrl* );
452: flag float128_le_quiet( float128, float128, float_ctrl* );
453: flag float128_lt_quiet( float128, float128, float_ctrl* );
454: flag float128_is_signaling_nan( float128 );
455:
456: // functions originally internal to softfloat.c
457: float128 packFloat128( flag zSign, int32 zExp, bits64 zSig0, bits64 zSig1 );
458: float128 roundAndPackFloat128( flag zSign, int32 zExp, bits64 zSig0, bits64 zSig1, bits64 zSig2, float_ctrl* c );
459: float128 normalizeRoundAndPackFloat128( flag zSign, int32 zExp, bits64 zSig0, bits64 zSig1, float_ctrl* c );
460:
461: #endif
462:
463: #endif //SOFTFLOAT_H
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.