quad.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* Software floating-point emulation.
  2. Definitions for IEEE Quad Precision.
  3. Copyright (C) 1997,1998,1999 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 Library General Public License as
  11. published by the Free Software Foundation; either version 2 of the
  12. License, or (at your option) any later version.
  13. The GNU C Library is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. Library General Public License for more details.
  17. You should have received a copy of the GNU Library General Public
  18. License along with the GNU C Library; see the file COPYING.LIB. If
  19. not, write to the Free Software Foundation, Inc.,
  20. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  21. #ifndef __MATH_EMU_QUAD_H__
  22. #define __MATH_EMU_QUAD_H__
  23. #if _FP_W_TYPE_SIZE < 32
  24. #error "Here's a nickel, kid. Go buy yourself a real computer."
  25. #endif
  26. #if _FP_W_TYPE_SIZE < 64
  27. #define _FP_FRACTBITS_Q (4*_FP_W_TYPE_SIZE)
  28. #else
  29. #define _FP_FRACTBITS_Q (2*_FP_W_TYPE_SIZE)
  30. #endif
  31. #define _FP_FRACBITS_Q 113
  32. #define _FP_FRACXBITS_Q (_FP_FRACTBITS_Q - _FP_FRACBITS_Q)
  33. #define _FP_WFRACBITS_Q (_FP_WORKBITS + _FP_FRACBITS_Q)
  34. #define _FP_WFRACXBITS_Q (_FP_FRACTBITS_Q - _FP_WFRACBITS_Q)
  35. #define _FP_EXPBITS_Q 15
  36. #define _FP_EXPBIAS_Q 16383
  37. #define _FP_EXPMAX_Q 32767
  38. #define _FP_QNANBIT_Q \
  39. ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-2) % _FP_W_TYPE_SIZE)
  40. #define _FP_IMPLBIT_Q \
  41. ((_FP_W_TYPE)1 << (_FP_FRACBITS_Q-1) % _FP_W_TYPE_SIZE)
  42. #define _FP_OVERFLOW_Q \
  43. ((_FP_W_TYPE)1 << (_FP_WFRACBITS_Q % _FP_W_TYPE_SIZE))
  44. #if _FP_W_TYPE_SIZE < 64
  45. union _FP_UNION_Q
  46. {
  47. long double flt;
  48. struct
  49. {
  50. #if __BYTE_ORDER == __BIG_ENDIAN
  51. unsigned sign : 1;
  52. unsigned exp : _FP_EXPBITS_Q;
  53. unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
  54. unsigned long frac2 : _FP_W_TYPE_SIZE;
  55. unsigned long frac1 : _FP_W_TYPE_SIZE;
  56. unsigned long frac0 : _FP_W_TYPE_SIZE;
  57. #else
  58. unsigned long frac0 : _FP_W_TYPE_SIZE;
  59. unsigned long frac1 : _FP_W_TYPE_SIZE;
  60. unsigned long frac2 : _FP_W_TYPE_SIZE;
  61. unsigned long frac3 : _FP_FRACBITS_Q - (_FP_IMPLBIT_Q != 0)-(_FP_W_TYPE_SIZE * 3);
  62. unsigned exp : _FP_EXPBITS_Q;
  63. unsigned sign : 1;
  64. #endif /* not bigendian */
  65. } bits __attribute__((packed));
  66. };
  67. #define FP_DECL_Q(X) _FP_DECL(4,X)
  68. #define FP_UNPACK_RAW_Q(X,val) _FP_UNPACK_RAW_4(Q,X,val)
  69. #define FP_UNPACK_RAW_QP(X,val) _FP_UNPACK_RAW_4_P(Q,X,val)
  70. #define FP_PACK_RAW_Q(val,X) _FP_PACK_RAW_4(Q,val,X)
  71. #define FP_PACK_RAW_QP(val,X) \
  72. do { \
  73. if (!FP_INHIBIT_RESULTS) \
  74. _FP_PACK_RAW_4_P(Q,val,X); \
  75. } while (0)
  76. #define FP_UNPACK_Q(X,val) \
  77. do { \
  78. _FP_UNPACK_RAW_4(Q,X,val); \
  79. _FP_UNPACK_CANONICAL(Q,4,X); \
  80. } while (0)
  81. #define FP_UNPACK_QP(X,val) \
  82. do { \
  83. _FP_UNPACK_RAW_4_P(Q,X,val); \
  84. _FP_UNPACK_CANONICAL(Q,4,X); \
  85. } while (0)
  86. #define FP_PACK_Q(val,X) \
  87. do { \
  88. _FP_PACK_CANONICAL(Q,4,X); \
  89. _FP_PACK_RAW_4(Q,val,X); \
  90. } while (0)
  91. #define FP_PACK_QP(val,X) \
  92. do { \
  93. _FP_PACK_CANONICAL(Q,4,X); \
  94. if (!FP_INHIBIT_RESULTS) \
  95. _FP_PACK_RAW_4_P(Q,val,X); \
  96. } while (0)
  97. #define FP_ISSIGNAN_Q(X) _FP_ISSIGNAN(Q,4,X)
  98. #define FP_NEG_Q(R,X) _FP_NEG(Q,4,R,X)
  99. #define FP_ADD_Q(R,X,Y) _FP_ADD(Q,4,R,X,Y)
  100. #define FP_SUB_Q(R,X,Y) _FP_SUB(Q,4,R,X,Y)
  101. #define FP_MUL_Q(R,X,Y) _FP_MUL(Q,4,R,X,Y)
  102. #define FP_DIV_Q(R,X,Y) _FP_DIV(Q,4,R,X,Y)
  103. #define FP_SQRT_Q(R,X) _FP_SQRT(Q,4,R,X)
  104. #define _FP_SQRT_MEAT_Q(R,S,T,X,Q) _FP_SQRT_MEAT_4(R,S,T,X,Q)
  105. #define FP_CMP_Q(r,X,Y,un) _FP_CMP(Q,4,r,X,Y,un)
  106. #define FP_CMP_EQ_Q(r,X,Y) _FP_CMP_EQ(Q,4,r,X,Y)
  107. #define FP_TO_INT_Q(r,X,rsz,rsg) _FP_TO_INT(Q,4,r,X,rsz,rsg)
  108. #define FP_TO_INT_ROUND_Q(r,X,rsz,rsg) _FP_TO_INT_ROUND(Q,4,r,X,rsz,rsg)
  109. #define FP_FROM_INT_Q(X,r,rs,rt) _FP_FROM_INT(Q,4,X,r,rs,rt)
  110. #define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_4(X)
  111. #define _FP_FRAC_HIGH_RAW_Q(X) _FP_FRAC_HIGH_4(X)
  112. #else /* not _FP_W_TYPE_SIZE < 64 */
  113. union _FP_UNION_Q
  114. {
  115. long double flt /* __attribute__((mode(TF))) */ ;
  116. struct {
  117. #if __BYTE_ORDER == __BIG_ENDIAN
  118. unsigned sign : 1;
  119. unsigned exp : _FP_EXPBITS_Q;
  120. unsigned long frac1 : _FP_FRACBITS_Q-(_FP_IMPLBIT_Q != 0)-_FP_W_TYPE_SIZE;
  121. unsigned long frac0 : _FP_W_TYPE_SIZE;
  122. #else
  123. unsigned long frac0 : _FP_W_TYPE_SIZE;
  124. unsigned long frac1 : _FP_FRACBITS_Q-(_FP_IMPLBIT_Q != 0)-_FP_W_TYPE_SIZE;
  125. unsigned exp : _FP_EXPBITS_Q;
  126. unsigned sign : 1;
  127. #endif
  128. } bits;
  129. };
  130. #define FP_DECL_Q(X) _FP_DECL(2,X)
  131. #define FP_UNPACK_RAW_Q(X,val) _FP_UNPACK_RAW_2(Q,X,val)
  132. #define FP_UNPACK_RAW_QP(X,val) _FP_UNPACK_RAW_2_P(Q,X,val)
  133. #define FP_PACK_RAW_Q(val,X) _FP_PACK_RAW_2(Q,val,X)
  134. #define FP_PACK_RAW_QP(val,X) \
  135. do { \
  136. if (!FP_INHIBIT_RESULTS) \
  137. _FP_PACK_RAW_2_P(Q,val,X); \
  138. } while (0)
  139. #define FP_UNPACK_Q(X,val) \
  140. do { \
  141. _FP_UNPACK_RAW_2(Q,X,val); \
  142. _FP_UNPACK_CANONICAL(Q,2,X); \
  143. } while (0)
  144. #define FP_UNPACK_QP(X,val) \
  145. do { \
  146. _FP_UNPACK_RAW_2_P(Q,X,val); \
  147. _FP_UNPACK_CANONICAL(Q,2,X); \
  148. } while (0)
  149. #define FP_PACK_Q(val,X) \
  150. do { \
  151. _FP_PACK_CANONICAL(Q,2,X); \
  152. _FP_PACK_RAW_2(Q,val,X); \
  153. } while (0)
  154. #define FP_PACK_QP(val,X) \
  155. do { \
  156. _FP_PACK_CANONICAL(Q,2,X); \
  157. if (!FP_INHIBIT_RESULTS) \
  158. _FP_PACK_RAW_2_P(Q,val,X); \
  159. } while (0)
  160. #define FP_ISSIGNAN_Q(X) _FP_ISSIGNAN(Q,2,X)
  161. #define FP_NEG_Q(R,X) _FP_NEG(Q,2,R,X)
  162. #define FP_ADD_Q(R,X,Y) _FP_ADD(Q,2,R,X,Y)
  163. #define FP_SUB_Q(R,X,Y) _FP_SUB(Q,2,R,X,Y)
  164. #define FP_MUL_Q(R,X,Y) _FP_MUL(Q,2,R,X,Y)
  165. #define FP_DIV_Q(R,X,Y) _FP_DIV(Q,2,R,X,Y)
  166. #define FP_SQRT_Q(R,X) _FP_SQRT(Q,2,R,X)
  167. #define _FP_SQRT_MEAT_Q(R,S,T,X,Q) _FP_SQRT_MEAT_2(R,S,T,X,Q)
  168. #define FP_CMP_Q(r,X,Y,un) _FP_CMP(Q,2,r,X,Y,un)
  169. #define FP_CMP_EQ_Q(r,X,Y) _FP_CMP_EQ(Q,2,r,X,Y)
  170. #define FP_TO_INT_Q(r,X,rsz,rsg) _FP_TO_INT(Q,2,r,X,rsz,rsg)
  171. #define FP_TO_INT_ROUND_Q(r,X,rsz,rsg) _FP_TO_INT_ROUND(Q,2,r,X,rsz,rsg)
  172. #define FP_FROM_INT_Q(X,r,rs,rt) _FP_FROM_INT(Q,2,X,r,rs,rt)
  173. #define _FP_FRAC_HIGH_Q(X) _FP_FRAC_HIGH_2(X)
  174. #define _FP_FRAC_HIGH_RAW_Q(X) _FP_FRAC_HIGH_2(X)
  175. #endif /* not _FP_W_TYPE_SIZE < 64 */
  176. #endif /* __MATH_EMU_QUAD_H__ */