floatformat.h revision 169695
1185304Strasz/* IEEE floating point support declarations, for GDB, the GNU Debugger.
2185304Strasz   Copyright 1991, 1994, 1995, 1997, 2000, 2003, 2005
3196938Strasz   Free Software Foundation, Inc.
4196938Strasz
5196938StraszThis file is part of GDB.
6196938Strasz
7196938StraszThis program is free software; you can redistribute it and/or modify
8196938Straszit under the terms of the GNU General Public License as published by
9196938Straszthe Free Software Foundation; either version 2 of the License, or
10196938Strasz(at your option) any later version.
11196938Strasz
12196938StraszThis program is distributed in the hope that it will be useful,
13196938Straszbut WITHOUT ANY WARRANTY; without even the implied warranty of
14196938StraszMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15196938StraszGNU General Public License for more details.
16196938Strasz
17196938StraszYou should have received a copy of the GNU General Public License
18196938Straszalong with this program; if not, write to the Free Software
19196938StraszFoundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
20196938Strasz
21196938Strasz#if !defined (FLOATFORMAT_H)
22196938Strasz#define FLOATFORMAT_H 1
23196938Strasz
24196938Strasz#include "ansidecl.h"
25196938Strasz
26196938Strasz/* A floatformat consists of a sign bit, an exponent and a mantissa.  Once the
27196938Strasz   bytes are concatenated according to the byteorder flag, then each of those
28196938Strasz   fields is contiguous.  We number the bits with 0 being the most significant
29196938Strasz   (i.e. BITS_BIG_ENDIAN type numbering), and specify which bits each field
30197436Strasz   contains with the *_start and *_len fields.  */
31185304Strasz
32185304Strasz/* What is the order of the bytes?  */
33185304Strasz
34185304Straszenum floatformat_byteorders {
35185304Strasz  /* Standard little endian byte order.
36185304Strasz     EX: 1.2345678e10 => 00 00 80 c5 e0 fe 06 42 */
37185304Strasz  floatformat_little,
38185304Strasz
39185304Strasz  /* Standard big endian byte order.
40185304Strasz     EX: 1.2345678e10 => 42 06 fe e0 c5 80 00 00 */
41185304Strasz  floatformat_big,
42185304Strasz
43185304Strasz  /* Little endian byte order but big endian word order.
44185304Strasz     EX: 1.2345678e10 => e0 fe 06 42 00 00 80 c5 */
45185304Strasz  floatformat_littlebyte_bigword,
46185304Strasz
47219266Strasz  /* VAX byte order.  Little endian byte order with 16-bit words.  The
48185304Strasz     following example is an illustration of the byte order only; VAX
49185304Strasz     doesn't have a fully IEEE compliant floating-point format.
50185304Strasz     EX: 1.2345678e10 => 80 c5 00 00 06 42 e0 fe */
51185304Strasz  floatformat_vax
52185304Strasz};
53185304Strasz
54185304Straszenum floatformat_intbit { floatformat_intbit_yes, floatformat_intbit_no };
55185304Strasz
56185304Straszstruct floatformat
57185304Strasz{
58185304Strasz  enum floatformat_byteorders byteorder;
59185304Strasz  unsigned int totalsize;	/* Total size of number in bits */
60185304Strasz
61185304Strasz  /* Sign bit is always one bit long.  1 means negative, 0 means positive.  */
62185304Strasz  unsigned int sign_start;
63185304Strasz
64185304Strasz  unsigned int exp_start;
65185304Strasz  unsigned int exp_len;
66185304Strasz  /* Bias added to a "true" exponent to form the biased exponent.  It
67185304Strasz     is intentionally signed as, otherwize, -exp_bias can turn into a
68185304Strasz     very large number (e.g., given the exp_bias of 0x3fff and a 64
69185304Strasz     bit long, the equation (long)(1 - exp_bias) evaluates to
70185304Strasz     4294950914) instead of -16382).  */
71185304Strasz  int exp_bias;
72185304Strasz  /* Exponent value which indicates NaN.  This is the actual value stored in
73185304Strasz     the float, not adjusted by the exp_bias.  This usually consists of all
74185304Strasz     one bits.  */
75185304Strasz  unsigned int exp_nan;
76185304Strasz
77185304Strasz  unsigned int man_start;
78185304Strasz  unsigned int man_len;
79185304Strasz
80185304Strasz  /* Is the integer bit explicit or implicit?  */
81185304Strasz  enum floatformat_intbit intbit;
82185304Strasz
83185304Strasz  /* Internal name for debugging. */
84185304Strasz  const char *name;
85185304Strasz
86  /* Validator method.  */
87  int (*is_valid) (const struct floatformat *fmt, const void *from);
88};
89
90/* floatformats for IEEE single and double, big and little endian.  */
91
92extern const struct floatformat floatformat_ieee_single_big;
93extern const struct floatformat floatformat_ieee_single_little;
94extern const struct floatformat floatformat_ieee_double_big;
95extern const struct floatformat floatformat_ieee_double_little;
96
97/* floatformat for ARM IEEE double, little endian bytes and big endian words */
98
99extern const struct floatformat floatformat_ieee_double_littlebyte_bigword;
100
101/* floatformats for VAX.  */
102
103extern const struct floatformat floatformat_vax_f;
104extern const struct floatformat floatformat_vax_d;
105extern const struct floatformat floatformat_vax_g;
106
107/* floatformats for various extendeds.  */
108
109extern const struct floatformat floatformat_i387_ext;
110extern const struct floatformat floatformat_m68881_ext;
111extern const struct floatformat floatformat_i960_ext;
112extern const struct floatformat floatformat_m88110_ext;
113extern const struct floatformat floatformat_m88110_harris_ext;
114extern const struct floatformat floatformat_arm_ext_big;
115extern const struct floatformat floatformat_arm_ext_littlebyte_bigword;
116/* IA-64 Floating Point register spilt into memory.  */
117extern const struct floatformat floatformat_ia64_spill_big;
118extern const struct floatformat floatformat_ia64_spill_little;
119extern const struct floatformat floatformat_ia64_quad_big;
120extern const struct floatformat floatformat_ia64_quad_little;
121
122/* Convert from FMT to a double.
123   FROM is the address of the extended float.
124   Store the double in *TO.  */
125
126extern void
127floatformat_to_double (const struct floatformat *, const void *, double *);
128
129/* The converse: convert the double *FROM to FMT
130   and store where TO points.  */
131
132extern void
133floatformat_from_double (const struct floatformat *, const double *, void *);
134
135/* Return non-zero iff the data at FROM is a valid number in format FMT.  */
136
137extern int
138floatformat_is_valid (const struct floatformat *fmt, const void *from);
139
140#endif	/* defined (FLOATFORMAT_H) */
141