floatformat.h 5.9 KB

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