floatn.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Macros to control TS 18661-3 glibc features on x86.
  2. Copyright (C) 2017-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library 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 GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _BITS_FLOATN_H
  16. #define _BITS_FLOATN_H
  17. #include <features.h>
  18. /* Defined to 1 if the current compiler invocation provides a
  19. floating-point type with the IEEE 754 binary128 format, and this
  20. glibc includes corresponding *f128 interfaces for it. The required
  21. libgcc support was added some time after the basic compiler
  22. support, for x86_64 and x86. Intel SYCL compiler doesn't support
  23. _Float128: https://github.com/intel/llvm/issues/16903
  24. */
  25. #if (defined __x86_64__ \
  26. ? __GNUC_PREREQ (4, 3) \
  27. : (defined __GNU__ ? __GNUC_PREREQ (4, 5) : __GNUC_PREREQ (4, 4))) \
  28. || (__glibc_clang_prereq (3, 9) \
  29. && (!defined __INTEL_LLVM_COMPILER \
  30. || !defined SYCL_LANGUAGE_VERSION))
  31. # define __HAVE_FLOAT128 1
  32. #else
  33. # define __HAVE_FLOAT128 0
  34. #endif
  35. /* Defined to 1 if __HAVE_FLOAT128 is 1 and the type is ABI-distinct
  36. from the default float, double and long double types in this glibc. */
  37. #if __HAVE_FLOAT128
  38. # define __HAVE_DISTINCT_FLOAT128 1
  39. #else
  40. # define __HAVE_DISTINCT_FLOAT128 0
  41. #endif
  42. /* Defined to 1 if the current compiler invocation provides a
  43. floating-point type with the right format for _Float64x, and this
  44. glibc includes corresponding *f64x interfaces for it. */
  45. #define __HAVE_FLOAT64X 1
  46. /* Defined to 1 if __HAVE_FLOAT64X is 1 and _Float64x has the format
  47. of long double. Otherwise, if __HAVE_FLOAT64X is 1, _Float64x has
  48. the format of _Float128, which must be different from that of long
  49. double. */
  50. #define __HAVE_FLOAT64X_LONG_DOUBLE 1
  51. #ifndef __ASSEMBLER__
  52. /* Defined to concatenate the literal suffix to be used with _Float128
  53. types, if __HAVE_FLOAT128 is 1. */
  54. # if __HAVE_FLOAT128
  55. # if !__GNUC_PREREQ (7, 0) \
  56. || (defined __cplusplus && !__GNUC_PREREQ (13, 0)) \
  57. || defined __clang__
  58. /* The literal suffix f128 exists only since GCC 7.0. */
  59. # define __f128(x) x##q
  60. # else
  61. # define __f128(x) x##f128
  62. # endif
  63. # endif
  64. /* Defined to a complex binary128 type if __HAVE_FLOAT128 is 1. */
  65. # if __HAVE_FLOAT128
  66. # if !__GNUC_PREREQ (7, 0) \
  67. || (defined __cplusplus && !__GNUC_PREREQ (13, 0)) \
  68. || defined __clang__
  69. /* Add a typedef for older GCC compilers which don't natively support
  70. _Complex _Float128. */
  71. typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
  72. # define __CFLOAT128 __cfloat128
  73. # else
  74. # define __CFLOAT128 _Complex _Float128
  75. # endif
  76. # endif
  77. /* The remaining of this file provides support for older compilers. */
  78. # if __HAVE_FLOAT128
  79. /* The type _Float128 exists only since GCC 7.0. */
  80. # if !__GNUC_PREREQ (7, 0) \
  81. || (defined __cplusplus && !__GNUC_PREREQ (13, 0)) \
  82. || __glibc_clang_prereq (3, 9)
  83. typedef __float128 _Float128;
  84. # endif
  85. /* __builtin_huge_valf128 doesn't exist before GCC 7.0 nor Clang 7.0. */
  86. # if !__GNUC_PREREQ (7, 0) && !__glibc_clang_prereq (7, 0)
  87. # define __builtin_huge_valf128() ((_Float128) __builtin_huge_val ())
  88. # endif
  89. /* Older GCC has only a subset of built-in functions for _Float128 on
  90. x86, and __builtin_infq is not usable in static initializers.
  91. Converting a narrower sNaN to _Float128 produces a quiet NaN, so
  92. attempts to use _Float128 sNaNs will not work properly with older
  93. compilers. */
  94. # if !__GNUC_PREREQ (7, 0) && !defined __clang__
  95. # define __builtin_copysignf128 __builtin_copysignq
  96. # define __builtin_fabsf128 __builtin_fabsq
  97. # define __builtin_inff128() ((_Float128) __builtin_inf ())
  98. # define __builtin_nanf128(x) ((_Float128) __builtin_nan (x))
  99. # define __builtin_nansf128(x) ((_Float128) __builtin_nans (x))
  100. # endif
  101. /* In math/math.h, __MATH_TG will expand signbit to __builtin_signbit*,
  102. e.g.: __builtin_signbitf128, before GCC 6. However, there has never
  103. been a __builtin_signbitf128 in GCC and the type-generic builtin is
  104. only available since GCC 6. signbit is expanded to __builtin_signbit
  105. after Clang 3.3. */
  106. # if !__GNUC_PREREQ (6, 0)
  107. # define __builtin_signbitf128 __signbitf128
  108. # endif
  109. # endif
  110. #endif /* !__ASSEMBLER__. */
  111. #include <bits/floatn-common.h>
  112. #endif /* _BITS_FLOATN_H */