quadlib.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* Subroutines for long double support.
  2. Copyright (C) 2000-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GCC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /* HPUX TFmode compare requires a library call to _U_Qfcmp. It takes
  20. a magic number as its third argument which indicates what to do.
  21. The return value is an integer to be compared against zero. The
  22. comparison conditions are the same as those listed in Table 8-12
  23. of the PA-RISC 2.0 Architecture book for the fcmp instruction. */
  24. /* Raise FP_INVALID on SNaN as a side effect. */
  25. #define QCMP_INV 1
  26. /* Comparison relations. */
  27. #define QCMP_UNORD 2
  28. #define QCMP_EQ 4
  29. #define QCMP_LT 8
  30. #define QCMP_GT 16
  31. int _U_Qfcmp (long double a, long double b, int);
  32. long _U_Qfcnvfxt_quad_to_sgl (long double);
  33. int _U_Qfeq (long double, long double);
  34. int _U_Qfne (long double, long double);
  35. int _U_Qfgt (long double, long double);
  36. int _U_Qfge (long double, long double);
  37. int _U_Qflt (long double, long double);
  38. int _U_Qfle (long double, long double);
  39. int _U_Qfltgt (long double, long double);
  40. int _U_Qfunle (long double, long double);
  41. int _U_Qfunlt (long double, long double);
  42. int _U_Qfunge (long double, long double);
  43. int _U_Qfungt (long double, long double);
  44. int _U_Qfuneq (long double, long double);
  45. int _U_Qfunord (long double, long double);
  46. int _U_Qford (long double, long double);
  47. int _U_Qfcomp (long double, long double);
  48. long double _U_Qfneg (long double);
  49. long double _U_Qfcopysign (long double, long double);
  50. #ifdef __LP64__
  51. int __U_Qfcnvfxt_quad_to_sgl (long double);
  52. #endif
  53. unsigned int _U_Qfcnvfxt_quad_to_usgl(long double);
  54. long double _U_Qfcnvxf_usgl_to_quad (unsigned int);
  55. unsigned long long _U_Qfcnvfxt_quad_to_udbl(long double);
  56. long double _U_Qfcnvxf_udbl_to_quad (unsigned long long);
  57. int
  58. _U_Qfeq (long double a, long double b)
  59. {
  60. return (_U_Qfcmp (a, b, QCMP_EQ) != 0);
  61. }
  62. int
  63. _U_Qfne (long double a, long double b)
  64. {
  65. return (_U_Qfcmp (a, b, QCMP_EQ) == 0);
  66. }
  67. int
  68. _U_Qfgt (long double a, long double b)
  69. {
  70. return (_U_Qfcmp (a, b, QCMP_INV | QCMP_GT) != 0);
  71. }
  72. int
  73. _U_Qfge (long double a, long double b)
  74. {
  75. return (_U_Qfcmp (a, b, QCMP_INV | QCMP_EQ | QCMP_GT) != 0);
  76. }
  77. int
  78. _U_Qflt (long double a, long double b)
  79. {
  80. return (_U_Qfcmp (a, b, QCMP_INV | QCMP_LT) != 0);
  81. }
  82. int
  83. _U_Qfle (long double a, long double b)
  84. {
  85. return (_U_Qfcmp (a, b, QCMP_INV | QCMP_EQ | QCMP_LT) != 0);
  86. }
  87. int
  88. _U_Qfltgt (long double a, long double b)
  89. {
  90. return (_U_Qfcmp (a, b, QCMP_INV | QCMP_LT | QCMP_GT) != 0);
  91. }
  92. int
  93. _U_Qfunle (long double a, long double b)
  94. {
  95. return (_U_Qfcmp (a, b, QCMP_INV | QCMP_UNORD | QCMP_EQ | QCMP_LT) != 0);
  96. }
  97. int
  98. _U_Qfunlt (long double a, long double b)
  99. {
  100. return (_U_Qfcmp (a, b, QCMP_INV | QCMP_UNORD | QCMP_LT) != 0);
  101. }
  102. int
  103. _U_Qfunge (long double a, long double b)
  104. {
  105. return (_U_Qfcmp (a, b, QCMP_INV | QCMP_UNORD | QCMP_EQ | QCMP_GT) != 0);
  106. }
  107. int
  108. _U_Qfungt (long double a, long double b)
  109. {
  110. return (_U_Qfcmp (a, b, QCMP_INV | QCMP_UNORD | QCMP_GT) != 0);
  111. }
  112. int
  113. _U_Qfuneq (long double a, long double b)
  114. {
  115. return (_U_Qfcmp (a, b, QCMP_INV | QCMP_UNORD | QCMP_EQ) != 0);
  116. }
  117. int
  118. _U_Qfunord (long double a, long double b)
  119. {
  120. return (_U_Qfcmp (a, b, QCMP_INV | QCMP_UNORD) != 0);
  121. }
  122. int
  123. _U_Qford (long double a, long double b)
  124. {
  125. return (_U_Qfcmp (a, b, QCMP_INV | QCMP_EQ | QCMP_LT | QCMP_GT) != 0);
  126. }
  127. int
  128. _U_Qfcomp (long double a, long double b)
  129. {
  130. if (_U_Qfcmp (a, b, QCMP_EQ) == 0)
  131. return 0;
  132. return (_U_Qfcmp (a, b, QCMP_UNORD | QCMP_EQ | QCMP_GT) != 0 ? 1 : -1);
  133. }
  134. /* Negate long double A. */
  135. long double
  136. _U_Qfneg (long double a)
  137. {
  138. union
  139. {
  140. long double ld;
  141. int i[4];
  142. } u;
  143. u.ld = a;
  144. u.i[0] ^= 0x80000000;
  145. return u.ld;
  146. }
  147. /* Return long double A with sign changed to sign of long double B. */
  148. long double
  149. _U_Qfcopysign (long double a, long double b)
  150. {
  151. union
  152. {
  153. long double ld;
  154. int i[4];
  155. } ua, ub;
  156. ua.ld = a;
  157. ub.ld = b;
  158. ua.i[0] &= 0x7fffffff;
  159. ua.i[0] |= (0x80000000 & ub.i[0]);
  160. return ua.ld;
  161. }
  162. #ifdef __LP64__
  163. /* This routine is only necessary for the PA64 port; for reasons unknown
  164. _U_Qfcnvfxt_quad_to_sgl returns the integer in the high 32bits of the
  165. return value. Ugh. */
  166. int
  167. __U_Qfcnvfxt_quad_to_sgl (long double a)
  168. {
  169. return _U_Qfcnvfxt_quad_to_sgl (a) >> 32;
  170. }
  171. #endif
  172. /* HP only has signed conversion in the C library, so need to synthesize
  173. unsigned versions. */
  174. unsigned int
  175. _U_Qfcnvfxt_quad_to_usgl (long double a)
  176. {
  177. extern long long _U_Qfcnvfxt_quad_to_dbl (long double a);
  178. return (unsigned int) _U_Qfcnvfxt_quad_to_dbl (a);
  179. }
  180. long double
  181. _U_Qfcnvxf_usgl_to_quad (unsigned int a)
  182. {
  183. extern long double _U_Qfcnvxf_dbl_to_quad (long long);
  184. return _U_Qfcnvxf_dbl_to_quad ((long long) a);
  185. }
  186. typedef union {
  187. unsigned long long u[2];
  188. long double d[1];
  189. } quad_type;
  190. unsigned long long
  191. _U_Qfcnvfxt_quad_to_udbl (long double a)
  192. {
  193. extern quad_type _U_Qfcnvfxt_quad_to_quad (long double a);
  194. quad_type u;
  195. u = _U_Qfcnvfxt_quad_to_quad(a);
  196. return u.u[1];
  197. }
  198. long double
  199. _U_Qfcnvxf_udbl_to_quad (unsigned long long a)
  200. {
  201. extern long double _U_Qfcnvxf_quad_to_quad (quad_type a);
  202. quad_type u;
  203. u.u[0] = 0;
  204. u.u[1] = a;
  205. return _U_Qfcnvxf_quad_to_quad (u);
  206. }