floatn.h 5.4 KB

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