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