single.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* Software floating-point emulation.
  2. Definitions for IEEE Single Precision.
  3. Copyright (C) 1997-2017 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Richard Henderson (rth@cygnus.com),
  6. Jakub Jelinek (jj@ultra.linux.cz),
  7. David S. Miller (davem@redhat.com) and
  8. Peter Maydell (pmaydell@chiark.greenend.org.uk).
  9. The GNU C Library is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU Lesser General Public
  11. License as published by the Free Software Foundation; either
  12. version 2.1 of the License, or (at your option) any later version.
  13. In addition to the permissions in the GNU Lesser General Public
  14. License, the Free Software Foundation gives you unlimited
  15. permission to link the compiled version of this file into
  16. combinations with other programs, and to distribute those
  17. combinations without any restriction coming from the use of this
  18. file. (The Lesser General Public License restrictions do apply in
  19. other respects; for example, they cover modification of the file,
  20. and distribution when not linked into a combine executable.)
  21. The GNU C Library is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. Lesser General Public License for more details.
  25. You should have received a copy of the GNU Lesser General Public
  26. License along with the GNU C Library; if not, see
  27. <http://www.gnu.org/licenses/>. */
  28. #ifndef SOFT_FP_SINGLE_H
  29. #define SOFT_FP_SINGLE_H 1
  30. #if _FP_W_TYPE_SIZE < 32
  31. # error "Here's a nickel kid. Go buy yourself a real computer."
  32. #endif
  33. #define _FP_FRACTBITS_S _FP_W_TYPE_SIZE
  34. #if _FP_W_TYPE_SIZE < 64
  35. # define _FP_FRACTBITS_DW_S (2 * _FP_W_TYPE_SIZE)
  36. #else
  37. # define _FP_FRACTBITS_DW_S _FP_W_TYPE_SIZE
  38. #endif
  39. #define _FP_FRACBITS_S 24
  40. #define _FP_FRACXBITS_S (_FP_FRACTBITS_S - _FP_FRACBITS_S)
  41. #define _FP_WFRACBITS_S (_FP_WORKBITS + _FP_FRACBITS_S)
  42. #define _FP_WFRACXBITS_S (_FP_FRACTBITS_S - _FP_WFRACBITS_S)
  43. #define _FP_EXPBITS_S 8
  44. #define _FP_EXPBIAS_S 127
  45. #define _FP_EXPMAX_S 255
  46. #define _FP_QNANBIT_S ((_FP_W_TYPE) 1 << (_FP_FRACBITS_S-2))
  47. #define _FP_QNANBIT_SH_S ((_FP_W_TYPE) 1 << (_FP_FRACBITS_S-2+_FP_WORKBITS))
  48. #define _FP_IMPLBIT_S ((_FP_W_TYPE) 1 << (_FP_FRACBITS_S-1))
  49. #define _FP_IMPLBIT_SH_S ((_FP_W_TYPE) 1 << (_FP_FRACBITS_S-1+_FP_WORKBITS))
  50. #define _FP_OVERFLOW_S ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_S))
  51. #define _FP_WFRACBITS_DW_S (2 * _FP_WFRACBITS_S)
  52. #define _FP_WFRACXBITS_DW_S (_FP_FRACTBITS_DW_S - _FP_WFRACBITS_DW_S)
  53. #define _FP_HIGHBIT_DW_S \
  54. ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_DW_S - 1) % _FP_W_TYPE_SIZE)
  55. /* The implementation of _FP_MUL_MEAT_S and _FP_DIV_MEAT_S should be
  56. chosen by the target machine. */
  57. typedef float SFtype __attribute__ ((mode (SF)));
  58. union _FP_UNION_S
  59. {
  60. SFtype flt;
  61. struct _FP_STRUCT_LAYOUT
  62. {
  63. #if __BYTE_ORDER == __BIG_ENDIAN
  64. unsigned sign : 1;
  65. unsigned exp : _FP_EXPBITS_S;
  66. unsigned frac : _FP_FRACBITS_S - (_FP_IMPLBIT_S != 0);
  67. #else
  68. unsigned frac : _FP_FRACBITS_S - (_FP_IMPLBIT_S != 0);
  69. unsigned exp : _FP_EXPBITS_S;
  70. unsigned sign : 1;
  71. #endif
  72. } bits __attribute__ ((packed));
  73. };
  74. #define FP_DECL_S(X) _FP_DECL (1, X)
  75. #define FP_UNPACK_RAW_S(X, val) _FP_UNPACK_RAW_1 (S, X, (val))
  76. #define FP_UNPACK_RAW_SP(X, val) _FP_UNPACK_RAW_1_P (S, X, (val))
  77. #define FP_PACK_RAW_S(val, X) _FP_PACK_RAW_1 (S, (val), X)
  78. #define FP_PACK_RAW_SP(val, X) \
  79. do \
  80. { \
  81. if (!FP_INHIBIT_RESULTS) \
  82. _FP_PACK_RAW_1_P (S, (val), X); \
  83. } \
  84. while (0)
  85. #define FP_UNPACK_S(X, val) \
  86. do \
  87. { \
  88. _FP_UNPACK_RAW_1 (S, X, (val)); \
  89. _FP_UNPACK_CANONICAL (S, 1, X); \
  90. } \
  91. while (0)
  92. #define FP_UNPACK_SP(X, val) \
  93. do \
  94. { \
  95. _FP_UNPACK_RAW_1_P (S, X, (val)); \
  96. _FP_UNPACK_CANONICAL (S, 1, X); \
  97. } \
  98. while (0)
  99. #define FP_UNPACK_SEMIRAW_S(X, val) \
  100. do \
  101. { \
  102. _FP_UNPACK_RAW_1 (S, X, (val)); \
  103. _FP_UNPACK_SEMIRAW (S, 1, X); \
  104. } \
  105. while (0)
  106. #define FP_UNPACK_SEMIRAW_SP(X, val) \
  107. do \
  108. { \
  109. _FP_UNPACK_RAW_1_P (S, X, (val)); \
  110. _FP_UNPACK_SEMIRAW (S, 1, X); \
  111. } \
  112. while (0)
  113. #define FP_PACK_S(val, X) \
  114. do \
  115. { \
  116. _FP_PACK_CANONICAL (S, 1, X); \
  117. _FP_PACK_RAW_1 (S, (val), X); \
  118. } \
  119. while (0)
  120. #define FP_PACK_SP(val, X) \
  121. do \
  122. { \
  123. _FP_PACK_CANONICAL (S, 1, X); \
  124. if (!FP_INHIBIT_RESULTS) \
  125. _FP_PACK_RAW_1_P (S, (val), X); \
  126. } \
  127. while (0)
  128. #define FP_PACK_SEMIRAW_S(val, X) \
  129. do \
  130. { \
  131. _FP_PACK_SEMIRAW (S, 1, X); \
  132. _FP_PACK_RAW_1 (S, (val), X); \
  133. } \
  134. while (0)
  135. #define FP_PACK_SEMIRAW_SP(val, X) \
  136. do \
  137. { \
  138. _FP_PACK_SEMIRAW (S, 1, X); \
  139. if (!FP_INHIBIT_RESULTS) \
  140. _FP_PACK_RAW_1_P (S, (val), X); \
  141. } \
  142. while (0)
  143. #define FP_ISSIGNAN_S(X) _FP_ISSIGNAN (S, 1, X)
  144. #define FP_NEG_S(R, X) _FP_NEG (S, 1, R, X)
  145. #define FP_ADD_S(R, X, Y) _FP_ADD (S, 1, R, X, Y)
  146. #define FP_SUB_S(R, X, Y) _FP_SUB (S, 1, R, X, Y)
  147. #define FP_MUL_S(R, X, Y) _FP_MUL (S, 1, R, X, Y)
  148. #define FP_DIV_S(R, X, Y) _FP_DIV (S, 1, R, X, Y)
  149. #define FP_SQRT_S(R, X) _FP_SQRT (S, 1, R, X)
  150. #define _FP_SQRT_MEAT_S(R, S, T, X, Q) _FP_SQRT_MEAT_1 (R, S, T, X, (Q))
  151. #if _FP_W_TYPE_SIZE < 64
  152. # define FP_FMA_S(R, X, Y, Z) _FP_FMA (S, 1, 2, R, X, Y, Z)
  153. #else
  154. # define FP_FMA_S(R, X, Y, Z) _FP_FMA (S, 1, 1, R, X, Y, Z)
  155. #endif
  156. #define FP_CMP_S(r, X, Y, un, ex) _FP_CMP (S, 1, (r), X, Y, (un), (ex))
  157. #define FP_CMP_EQ_S(r, X, Y, ex) _FP_CMP_EQ (S, 1, (r), X, Y, (ex))
  158. #define FP_CMP_UNORD_S(r, X, Y, ex) _FP_CMP_UNORD (S, 1, (r), X, Y, (ex))
  159. #define FP_TO_INT_S(r, X, rsz, rsg) _FP_TO_INT (S, 1, (r), X, (rsz), (rsg))
  160. #define FP_TO_INT_ROUND_S(r, X, rsz, rsg) \
  161. _FP_TO_INT_ROUND (S, 1, (r), X, (rsz), (rsg))
  162. #define FP_FROM_INT_S(X, r, rs, rt) _FP_FROM_INT (S, 1, X, (r), (rs), rt)
  163. #define _FP_FRAC_HIGH_S(X) _FP_FRAC_HIGH_1 (X)
  164. #define _FP_FRAC_HIGH_RAW_S(X) _FP_FRAC_HIGH_1 (X)
  165. #if _FP_W_TYPE_SIZE < 64
  166. # define _FP_FRAC_HIGH_DW_S(X) _FP_FRAC_HIGH_2 (X)
  167. #else
  168. # define _FP_FRAC_HIGH_DW_S(X) _FP_FRAC_HIGH_1 (X)
  169. #endif
  170. #endif /* !SOFT_FP_SINGLE_H */