1/* IEEE floating point support declarations, for GDB, the GNU Debugger.
2   Copyright 1991, 1994, 1995, 1997, 2000, 2003, 2005, 2010
3   Free Software Foundation, Inc.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
20
21#if !defined (FLOATFORMAT_H)
22#define FLOATFORMAT_H 1
23
24#include "ansidecl.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/* A floatformat consists of a sign bit, an exponent and a mantissa.  Once the
31   bytes are concatenated according to the byteorder flag, then each of those
32   fields is contiguous.  We number the bits with 0 being the most significant
33   (i.e. BITS_BIG_ENDIAN type numbering), and specify which bits each field
34   contains with the *_start and *_len fields.  */
35
36/* What is the order of the bytes?  */
37
38enum floatformat_byteorders {
39  /* Standard little endian byte order.
40     EX: 1.2345678e10 => 00 00 80 c5 e0 fe 06 42 */
41  floatformat_little,
42
43  /* Standard big endian byte order.
44     EX: 1.2345678e10 => 42 06 fe e0 c5 80 00 00 */
45  floatformat_big,
46
47  /* Little endian byte order but big endian word order.
48     EX: 1.2345678e10 => e0 fe 06 42 00 00 80 c5 */
49  floatformat_littlebyte_bigword,
50
51  /* VAX byte order.  Little endian byte order with 16-bit words.  The
52     following example is an illustration of the byte order only; VAX
53     doesn't have a fully IEEE compliant floating-point format.
54     EX: 1.2345678e10 => 80 c5 00 00 06 42 e0 fe */
55  floatformat_vax
56};
57
58enum floatformat_intbit { floatformat_intbit_yes, floatformat_intbit_no };
59
60struct floatformat
61{
62  enum floatformat_byteorders byteorder;
63  unsigned int totalsize;	/* Total size of number in bits */
64
65  /* Sign bit is always one bit long.  1 means negative, 0 means positive.  */
66  unsigned int sign_start;
67
68  unsigned int exp_start;
69  unsigned int exp_len;
70  /* Bias added to a "true" exponent to form the biased exponent.  It
71     is intentionally signed as, otherwize, -exp_bias can turn into a
72     very large number (e.g., given the exp_bias of 0x3fff and a 64
73     bit long, the equation (long)(1 - exp_bias) evaluates to
74     4294950914) instead of -16382).  */
75  int exp_bias;
76  /* Exponent value which indicates NaN.  This is the actual value stored in
77     the float, not adjusted by the exp_bias.  This usually consists of all
78     one bits.  */
79  unsigned int exp_nan;
80
81  unsigned int man_start;
82  unsigned int man_len;
83
84  /* Is the integer bit explicit or implicit?  */
85  enum floatformat_intbit intbit;
86
87  /* Internal name for debugging. */
88  const char *name;
89
90  /* Validator method.  */
91  int (*is_valid) (const struct floatformat *fmt, const void *from);
92
93  /* Is the format actually the sum of two smaller floating point
94     formats (IBM long double, as described in
95     gcc/config/rs6000/darwin-ldouble-format)?  If so, this is the
96     smaller format in question, and the fields sign_start through
97     intbit describe the first half.  If not, this is NULL.  */
98  const struct floatformat *split_half;
99};
100
101/* floatformats for IEEE single and double, big and little endian.  */
102
103extern const struct floatformat floatformat_ieee_half_big;
104extern const struct floatformat floatformat_ieee_half_little;
105extern const struct floatformat floatformat_ieee_single_big;
106extern const struct floatformat floatformat_ieee_single_little;
107extern const struct floatformat floatformat_ieee_double_big;
108extern const struct floatformat floatformat_ieee_double_little;
109
110/* floatformat for ARM IEEE double, little endian bytes and big endian words */
111
112extern const struct floatformat floatformat_ieee_double_littlebyte_bigword;
113
114/* floatformats for VAX.  */
115
116extern const struct floatformat floatformat_vax_f;
117extern const struct floatformat floatformat_vax_d;
118extern const struct floatformat floatformat_vax_g;
119
120/* floatformats for various extendeds.  */
121
122extern const struct floatformat floatformat_i387_ext;
123extern const struct floatformat floatformat_m68881_ext;
124extern const struct floatformat floatformat_i960_ext;
125extern const struct floatformat floatformat_m88110_ext;
126extern const struct floatformat floatformat_m88110_harris_ext;
127extern const struct floatformat floatformat_arm_ext_big;
128extern const struct floatformat floatformat_arm_ext_littlebyte_bigword;
129/* IA-64 Floating Point register spilt into memory.  */
130extern const struct floatformat floatformat_ia64_spill_big;
131extern const struct floatformat floatformat_ia64_spill_little;
132extern const struct floatformat floatformat_ia64_quad_big;
133extern const struct floatformat floatformat_ia64_quad_little;
134/* IBM long double (double+double).  */
135extern const struct floatformat floatformat_ibm_long_double_big;
136extern const struct floatformat floatformat_ibm_long_double_little;
137
138/* Convert from FMT to a double.
139   FROM is the address of the extended float.
140   Store the double in *TO.  */
141
142extern void
143floatformat_to_double (const struct floatformat *, const void *, double *);
144
145/* The converse: convert the double *FROM to FMT
146   and store where TO points.  */
147
148extern void
149floatformat_from_double (const struct floatformat *, const double *, void *);
150
151/* Return non-zero iff the data at FROM is a valid number in format FMT.  */
152
153extern int
154floatformat_is_valid (const struct floatformat *fmt, const void *from);
155
156#ifdef __cplusplus
157}
158#endif
159
160#endif	/* defined (FLOATFORMAT_H) */
161