half.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* Software floating-point emulation.
  2. Definitions for IEEE Half Precision.
  3. Copyright (C) 1997-2019 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. In addition to the permissions in the GNU Lesser General Public
  10. License, the Free Software Foundation gives you unlimited
  11. permission to link the compiled version of this file into
  12. combinations with other programs, and to distribute those
  13. combinations without any restriction coming from the use of this
  14. file. (The Lesser General Public License restrictions do apply in
  15. other respects; for example, they cover modification of the file,
  16. and distribution when not linked into a combine executable.)
  17. The GNU C Library is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. Lesser General Public License for more details.
  21. You should have received a copy of the GNU Lesser General Public
  22. License along with the GNU C Library; if not, see
  23. <http://www.gnu.org/licenses/>. */
  24. #ifndef SOFT_FP_HALF_H
  25. #define SOFT_FP_HALF_H 1
  26. #if _FP_W_TYPE_SIZE < 32
  27. # error "Here's a nickel kid. Go buy yourself a real computer."
  28. #endif
  29. #define _FP_FRACTBITS_H (_FP_W_TYPE_SIZE)
  30. #define _FP_FRACTBITS_DW_H (_FP_W_TYPE_SIZE)
  31. #define _FP_FRACBITS_H 11
  32. #define _FP_FRACXBITS_H (_FP_FRACTBITS_H - _FP_FRACBITS_H)
  33. #define _FP_WFRACBITS_H (_FP_WORKBITS + _FP_FRACBITS_H)
  34. #define _FP_WFRACXBITS_H (_FP_FRACTBITS_H - _FP_WFRACBITS_H)
  35. #define _FP_EXPBITS_H 5
  36. #define _FP_EXPBIAS_H 15
  37. #define _FP_EXPMAX_H 31
  38. #define _FP_QNANBIT_H ((_FP_W_TYPE) 1 << (_FP_FRACBITS_H-2))
  39. #define _FP_QNANBIT_SH_H ((_FP_W_TYPE) 1 << (_FP_FRACBITS_H-2+_FP_WORKBITS))
  40. #define _FP_IMPLBIT_H ((_FP_W_TYPE) 1 << (_FP_FRACBITS_H-1))
  41. #define _FP_IMPLBIT_SH_H ((_FP_W_TYPE) 1 << (_FP_FRACBITS_H-1+_FP_WORKBITS))
  42. #define _FP_OVERFLOW_H ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_H))
  43. #define _FP_WFRACBITS_DW_H (2 * _FP_WFRACBITS_H)
  44. #define _FP_WFRACXBITS_DW_H (_FP_FRACTBITS_DW_H - _FP_WFRACBITS_DW_H)
  45. #define _FP_HIGHBIT_DW_H \
  46. ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_DW_H - 1) % _FP_W_TYPE_SIZE)
  47. /* The implementation of _FP_MUL_MEAT_H and _FP_DIV_MEAT_H should be
  48. chosen by the target machine. */
  49. typedef float HFtype __attribute__ ((mode (HF)));
  50. union _FP_UNION_H
  51. {
  52. HFtype flt;
  53. struct _FP_STRUCT_LAYOUT
  54. {
  55. #if __BYTE_ORDER == __BIG_ENDIAN
  56. unsigned sign : 1;
  57. unsigned exp : _FP_EXPBITS_H;
  58. unsigned frac : _FP_FRACBITS_H - (_FP_IMPLBIT_H != 0);
  59. #else
  60. unsigned frac : _FP_FRACBITS_H - (_FP_IMPLBIT_H != 0);
  61. unsigned exp : _FP_EXPBITS_H;
  62. unsigned sign : 1;
  63. #endif
  64. } bits;
  65. };
  66. #define FP_DECL_H(X) _FP_DECL (1, X)
  67. #define FP_UNPACK_RAW_H(X, val) _FP_UNPACK_RAW_1 (H, X, (val))
  68. #define FP_UNPACK_RAW_HP(X, val) _FP_UNPACK_RAW_1_P (H, X, (val))
  69. #define FP_PACK_RAW_H(val, X) _FP_PACK_RAW_1 (H, (val), X)
  70. #define FP_PACK_RAW_HP(val, X) \
  71. do \
  72. { \
  73. if (!FP_INHIBIT_RESULTS) \
  74. _FP_PACK_RAW_1_P (H, (val), X); \
  75. } \
  76. while (0)
  77. #define FP_UNPACK_H(X, val) \
  78. do \
  79. { \
  80. _FP_UNPACK_RAW_1 (H, X, (val)); \
  81. _FP_UNPACK_CANONICAL (H, 1, X); \
  82. } \
  83. while (0)
  84. #define FP_UNPACK_HP(X, val) \
  85. do \
  86. { \
  87. _FP_UNPACK_RAW_1_P (H, X, (val)); \
  88. _FP_UNPACK_CANONICAL (H, 1, X); \
  89. } \
  90. while (0)
  91. #define FP_UNPACK_SEMIRAW_H(X, val) \
  92. do \
  93. { \
  94. _FP_UNPACK_RAW_1 (H, X, (val)); \
  95. _FP_UNPACK_SEMIRAW (H, 1, X); \
  96. } \
  97. while (0)
  98. #define FP_UNPACK_SEMIRAW_HP(X, val) \
  99. do \
  100. { \
  101. _FP_UNPACK_RAW_1_P (H, X, (val)); \
  102. _FP_UNPACK_SEMIRAW (H, 1, X); \
  103. } \
  104. while (0)
  105. #define FP_PACK_H(val, X) \
  106. do \
  107. { \
  108. _FP_PACK_CANONICAL (H, 1, X); \
  109. _FP_PACK_RAW_1 (H, (val), X); \
  110. } \
  111. while (0)
  112. #define FP_PACK_HP(val, X) \
  113. do \
  114. { \
  115. _FP_PACK_CANONICAL (H, 1, X); \
  116. if (!FP_INHIBIT_RESULTS) \
  117. _FP_PACK_RAW_1_P (H, (val), X); \
  118. } \
  119. while (0)
  120. #define FP_PACK_SEMIRAW_H(val, X) \
  121. do \
  122. { \
  123. _FP_PACK_SEMIRAW (H, 1, X); \
  124. _FP_PACK_RAW_1 (H, (val), X); \
  125. } \
  126. while (0)
  127. #define FP_PACK_SEMIRAW_HP(val, X) \
  128. do \
  129. { \
  130. _FP_PACK_SEMIRAW (H, 1, X); \
  131. if (!FP_INHIBIT_RESULTS) \
  132. _FP_PACK_RAW_1_P (H, (val), X); \
  133. } \
  134. while (0)
  135. #define FP_TO_INT_H(r, X, rsz, rsg) _FP_TO_INT (H, 1, (r), X, (rsz), (rsg))
  136. #define FP_TO_INT_ROUND_H(r, X, rsz, rsg) \
  137. _FP_TO_INT_ROUND (H, 1, (r), X, (rsz), (rsg))
  138. #define FP_FROM_INT_H(X, r, rs, rt) _FP_FROM_INT (H, 1, X, (r), (rs), rt)
  139. /* HFmode arithmetic is not implemented. */
  140. #define _FP_FRAC_HIGH_H(X) _FP_FRAC_HIGH_1 (X)
  141. #define _FP_FRAC_HIGH_RAW_H(X) _FP_FRAC_HIGH_1 (X)
  142. #define _FP_FRAC_HIGH_DW_H(X) _FP_FRAC_HIGH_1 (X)
  143. #define FP_CMP_EQ_H(r, X, Y, ex) _FP_CMP_EQ (H, 1, (r), X, Y, (ex))
  144. #endif /* !SOFT_FP_HALF_H */