floatformat.h 5.8 KB

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