quad.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* Software floating-point emulation.
  2. Definitions for IEEE Quad Precision.
  3. Copyright (C) 1997,1998,1999,2006,2007 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. #if _FP_W_TYPE_SIZE < 32
  29. #error "Here's a nickel, kid. Go buy yourself a real computer."
  30. #endif
  31. #if _FP_W_TYPE_SIZE < 64
  32. #define _FP_FRACTBITS_Q (4*_FP_W_TYPE_SIZE)
  33. #else
  34. #define _FP_FRACTBITS_Q (2*_FP_W_TYPE_SIZE)
  35. #endif
  36. #define _FP_FRACBITS_Q 113
  37. #define _FP_FRACXBITS_Q (_FP_FRACTBITS_Q - _FP_FRACBITS_Q)
  38. #define _FP_WFRACBITS_Q (_FP_WORKBITS + _FP_FRACBITS_Q)
  39. #define _FP_WFRACXBITS_Q (_FP_FRACTBITS_Q - _FP_WFRACBITS_Q)
  40. #define _FP_EXPBITS_Q 15
  41. #define _FP_EXPBIAS_Q 16383
  42. #define _FP_EXPMAX_Q 32767
  43. #define _FP_QNANBIT_Q \
  44. ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-2) % _FP_W_TYPE_SIZE)
  45. #define _FP_QNANBIT_SH_Q \
  46. ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-2+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
  47. #define _FP_IMPLBIT_Q \
  48. ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-1) % _FP_W_TYPE_SIZE)
  49. #define _FP_IMPLBIT_SH_Q \
  50. ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-1+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
  51. #define _FP_OVERFLOW_Q \
  52. ((_FP_W_TYPE)1 << (_FP_WFRACBITS_Q % _FP_W_TYPE_SIZE))
  53. typedef float TFtype __attribute__((mode(TF)));
  54. #if _FP_W_TYPE_SIZE < 64
  55. union _FP_UNION_Q
  56. {
  57. TFtype flt;
  58. struct
  59. {
  60. #if __BYTE_ORDER == __BIG_ENDIAN
  61. unsigned sign : 1;
  62. unsigned exp : _FP_EXPBITS_Q;
  63. unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
  64. unsigned long frac2 : _FP_W_TYPE_SIZE;
  65. unsigned long frac1 : _FP_W_TYPE_SIZE;
  66. unsigned long frac0 : _FP_W_TYPE_SIZE;
  67. #else
  68. unsigned long frac0 : _FP_W_TYPE_SIZE;
  69. unsigned long frac1 : _FP_W_TYPE_SIZE;
  70. unsigned long frac2 : _FP_W_TYPE_SIZE;
  71. unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
  72. unsigned exp : _FP_EXPBITS_Q;
  73. unsigned sign : 1;
  74. #endif /* not bigendian */
  75. } bits __attribute__((packed));
  76. };
  77. #define FP_DECL_Q(X) _FP_DECL(4,X)
  78. #define FP_UNPACK_RAW_Q(X,val) _FP_UNPACK_RAW_4(Q,X,val)
  79. #define FP_UNPACK_RAW_QP(X,val) _FP_UNPACK_RAW_4_P(Q,X,val)
  80. #define FP_PACK_RAW_Q(val,X) _FP_PACK_RAW_4(Q,val,X)
  81. #define FP_PACK_RAW_QP(val,X) \
  82. do { \
  83. if (!FP_INHIBIT_RESULTS) \
  84. _FP_PACK_RAW_4_P(Q,val,X); \
  85. } while (0)
  86. #define FP_UNPACK_Q(X,val) \
  87. do { \
  88. _FP_UNPACK_RAW_4(Q,X,val); \
  89. _FP_UNPACK_CANONICAL(Q,4,X); \
  90. } while (0)
  91. #define FP_UNPACK_QP(X,val) \
  92. do { \
  93. _FP_UNPACK_RAW_4_P(Q,X,val); \
  94. _FP_UNPACK_CANONICAL(Q,4,X); \
  95. } while (0)
  96. #define FP_UNPACK_SEMIRAW_Q(X,val) \
  97. do { \
  98. _FP_UNPACK_RAW_4(Q,X,val); \
  99. _FP_UNPACK_SEMIRAW(Q,4,X); \
  100. } while (0)
  101. #define FP_UNPACK_SEMIRAW_QP(X,val) \
  102. do { \
  103. _FP_UNPACK_RAW_4_P(Q,X,val); \
  104. _FP_UNPACK_SEMIRAW(Q,4,X); \
  105. } while (0)
  106. #define FP_PACK_Q(val,X) \
  107. do { \
  108. _FP_PACK_CANONICAL(Q,4,X); \
  109. _FP_PACK_RAW_4(Q,val,X); \
  110. } while (0)
  111. #define FP_PACK_QP(val,X) \
  112. do { \
  113. _FP_PACK_CANONICAL(Q,4,X); \
  114. if (!FP_INHIBIT_RESULTS) \
  115. _FP_PACK_RAW_4_P(Q,val,X); \
  116. } while (0)
  117. #define FP_PACK_SEMIRAW_Q(val,X) \
  118. do { \
  119. _FP_PACK_SEMIRAW(Q,4,X); \
  120. _FP_PACK_RAW_4(Q,val,X); \
  121. } while (0)
  122. #define FP_PACK_SEMIRAW_QP(val,X) \
  123. do { \
  124. _FP_PACK_SEMIRAW(Q,4,X); \
  125. if (!FP_INHIBIT_RESULTS) \
  126. _FP_PACK_RAW_4_P(Q,val,X); \
  127. } while (0)
  128. #define FP_ISSIGNAN_Q(X) _FP_ISSIGNAN(Q,4,X)
  129. #define FP_NEG_Q(R,X) _FP_NEG(Q,4,R,X)
  130. #define FP_ADD_Q(R,X,Y) _FP_ADD(Q,4,R,X,Y)
  131. #define FP_SUB_Q(R,X,Y) _FP_SUB(Q,4,R,X,Y)
  132. #define FP_MUL_Q(R,X,Y) _FP_MUL(Q,4,R,X,Y)
  133. #define FP_DIV_Q(R,X,Y) _FP_DIV(Q,4,R,X,Y)
  134. #define FP_SQRT_Q(R,X) _FP_SQRT(Q,4,R,X)
  135. #define _FP_SQRT_MEAT_Q(R,S,T,X,Q) _FP_SQRT_MEAT_4(R,S,T,X,Q)
  136. #define FP_CMP_Q(r,X,Y,un) _FP_CMP(Q,4,r,X,Y,un)
  137. #define FP_CMP_EQ_Q(r,X,Y) _FP_CMP_EQ(Q,4,r,X,Y)
  138. #define FP_CMP_UNORD_Q(r,X,Y) _FP_CMP_UNORD(Q,4,r,X,Y)
  139. #define FP_TO_INT_Q(r,X,rsz,rsg) _FP_TO_INT(Q,4,r,X,rsz,rsg)
  140. #define FP_FROM_INT_Q(X,r,rs,rt) _FP_FROM_INT(Q,4,X,r,rs,rt)
  141. #define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_4(X)
  142. #define _FP_FRAC_HIGH_RAW_Q(X) _FP_FRAC_HIGH_4(X)
  143. #else /* not _FP_W_TYPE_SIZE < 64 */
  144. union _FP_UNION_Q
  145. {
  146. TFtype flt /* __attribute__((mode(TF))) */ ;
  147. struct {
  148. _FP_W_TYPE a, b;
  149. } longs;
  150. struct {
  151. #if __BYTE_ORDER == __BIG_ENDIAN
  152. unsigned sign : 1;
  153. unsigned exp : _FP_EXPBITS_Q;
  154. _FP_W_TYPE frac1 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0) - _FP_W_TYPE_SIZE;
  155. _FP_W_TYPE frac0 : _FP_W_TYPE_SIZE;
  156. #else
  157. _FP_W_TYPE frac0 : _FP_W_TYPE_SIZE;
  158. _FP_W_TYPE frac1 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0) - _FP_W_TYPE_SIZE;
  159. unsigned exp : _FP_EXPBITS_Q;
  160. unsigned sign : 1;
  161. #endif
  162. } bits;
  163. };
  164. #define FP_DECL_Q(X) _FP_DECL(2,X)
  165. #define FP_UNPACK_RAW_Q(X,val) _FP_UNPACK_RAW_2(Q,X,val)
  166. #define FP_UNPACK_RAW_QP(X,val) _FP_UNPACK_RAW_2_P(Q,X,val)
  167. #define FP_PACK_RAW_Q(val,X) _FP_PACK_RAW_2(Q,val,X)
  168. #define FP_PACK_RAW_QP(val,X) \
  169. do { \
  170. if (!FP_INHIBIT_RESULTS) \
  171. _FP_PACK_RAW_2_P(Q,val,X); \
  172. } while (0)
  173. #define FP_UNPACK_Q(X,val) \
  174. do { \
  175. _FP_UNPACK_RAW_2(Q,X,val); \
  176. _FP_UNPACK_CANONICAL(Q,2,X); \
  177. } while (0)
  178. #define FP_UNPACK_QP(X,val) \
  179. do { \
  180. _FP_UNPACK_RAW_2_P(Q,X,val); \
  181. _FP_UNPACK_CANONICAL(Q,2,X); \
  182. } while (0)
  183. #define FP_UNPACK_SEMIRAW_Q(X,val) \
  184. do { \
  185. _FP_UNPACK_RAW_2(Q,X,val); \
  186. _FP_UNPACK_SEMIRAW(Q,2,X); \
  187. } while (0)
  188. #define FP_UNPACK_SEMIRAW_QP(X,val) \
  189. do { \
  190. _FP_UNPACK_RAW_2_P(Q,X,val); \
  191. _FP_UNPACK_SEMIRAW(Q,2,X); \
  192. } while (0)
  193. #define FP_PACK_Q(val,X) \
  194. do { \
  195. _FP_PACK_CANONICAL(Q,2,X); \
  196. _FP_PACK_RAW_2(Q,val,X); \
  197. } while (0)
  198. #define FP_PACK_QP(val,X) \
  199. do { \
  200. _FP_PACK_CANONICAL(Q,2,X); \
  201. if (!FP_INHIBIT_RESULTS) \
  202. _FP_PACK_RAW_2_P(Q,val,X); \
  203. } while (0)
  204. #define FP_PACK_SEMIRAW_Q(val,X) \
  205. do { \
  206. _FP_PACK_SEMIRAW(Q,2,X); \
  207. _FP_PACK_RAW_2(Q,val,X); \
  208. } while (0)
  209. #define FP_PACK_SEMIRAW_QP(val,X) \
  210. do { \
  211. _FP_PACK_SEMIRAW(Q,2,X); \
  212. if (!FP_INHIBIT_RESULTS) \
  213. _FP_PACK_RAW_2_P(Q,val,X); \
  214. } while (0)
  215. #define FP_ISSIGNAN_Q(X) _FP_ISSIGNAN(Q,2,X)
  216. #define FP_NEG_Q(R,X) _FP_NEG(Q,2,R,X)
  217. #define FP_ADD_Q(R,X,Y) _FP_ADD(Q,2,R,X,Y)
  218. #define FP_SUB_Q(R,X,Y) _FP_SUB(Q,2,R,X,Y)
  219. #define FP_MUL_Q(R,X,Y) _FP_MUL(Q,2,R,X,Y)
  220. #define FP_DIV_Q(R,X,Y) _FP_DIV(Q,2,R,X,Y)
  221. #define FP_SQRT_Q(R,X) _FP_SQRT(Q,2,R,X)
  222. #define _FP_SQRT_MEAT_Q(R,S,T,X,Q) _FP_SQRT_MEAT_2(R,S,T,X,Q)
  223. #define FP_CMP_Q(r,X,Y,un) _FP_CMP(Q,2,r,X,Y,un)
  224. #define FP_CMP_EQ_Q(r,X,Y) _FP_CMP_EQ(Q,2,r,X,Y)
  225. #define FP_CMP_UNORD_Q(r,X,Y) _FP_CMP_UNORD(Q,2,r,X,Y)
  226. #define FP_TO_INT_Q(r,X,rsz,rsg) _FP_TO_INT(Q,2,r,X,rsz,rsg)
  227. #define FP_FROM_INT_Q(X,r,rs,rt) _FP_FROM_INT(Q,2,X,r,rs,rt)
  228. #define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_2(X)
  229. #define _FP_FRAC_HIGH_RAW_Q(X) _FP_FRAC_HIGH_2(X)
  230. #endif /* not _FP_W_TYPE_SIZE < 64 */