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