floatn-common.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /* Macros to control TS 18661-3 glibc features where the same
  2. definitions are appropriate for all platforms.
  3. Copyright (C) 2017-2019 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef _BITS_FLOATN_COMMON_H
  17. #define _BITS_FLOATN_COMMON_H
  18. #include <features.h>
  19. #include <bits/long-double.h>
  20. /* This header should be included at the bottom of each bits/floatn.h.
  21. It defines the following macros for each _FloatN and _FloatNx type,
  22. where the same definitions, or definitions based only on the macros
  23. in bits/floatn.h, are appropriate for all glibc configurations. */
  24. /* Defined to 1 if the current compiler invocation provides a
  25. floating-point type with the right format for this type, and this
  26. glibc includes corresponding *fN or *fNx interfaces for it. */
  27. #define __HAVE_FLOAT16 0
  28. #define __HAVE_FLOAT32 1
  29. #define __HAVE_FLOAT64 1
  30. #define __HAVE_FLOAT32X 1
  31. #define __HAVE_FLOAT128X 0
  32. /* Defined to 1 if the corresponding __HAVE_<type> macro is 1 and the
  33. type is the first with its format in the sequence of (the default
  34. choices for) float, double, long double, _Float16, _Float32,
  35. _Float64, _Float128, _Float32x, _Float64x, _Float128x for this
  36. glibc; that is, if functions present once per floating-point format
  37. rather than once per type are present for this type.
  38. All configurations supported by glibc have _Float32 the same format
  39. as float, _Float64 and _Float32x the same format as double, the
  40. _Float64x the same format as either long double or _Float128. No
  41. configurations support _Float128x or, as of GCC 7, have compiler
  42. support for a type meeting the requirements for _Float128x. */
  43. #define __HAVE_DISTINCT_FLOAT16 __HAVE_FLOAT16
  44. #define __HAVE_DISTINCT_FLOAT32 0
  45. #define __HAVE_DISTINCT_FLOAT64 0
  46. #define __HAVE_DISTINCT_FLOAT32X 0
  47. #define __HAVE_DISTINCT_FLOAT64X 0
  48. #define __HAVE_DISTINCT_FLOAT128X __HAVE_FLOAT128X
  49. /* Defined to 1 if the corresponding _FloatN type is not binary compatible
  50. with the corresponding ISO C type in the current compilation unit as
  51. opposed to __HAVE_DISTINCT_FLOATN, which indicates the default types built
  52. in glibc. */
  53. #define __HAVE_FLOAT128_UNLIKE_LDBL (__HAVE_DISTINCT_FLOAT128 \
  54. && __LDBL_MANT_DIG__ != 113)
  55. /* Defined to 1 if any _FloatN or _FloatNx types that are not
  56. ABI-distinct are however distinct types at the C language level (so
  57. for the purposes of __builtin_types_compatible_p and _Generic). */
  58. #if __GNUC_PREREQ (7, 0) && !defined __cplusplus
  59. # define __HAVE_FLOATN_NOT_TYPEDEF 1
  60. #else
  61. # define __HAVE_FLOATN_NOT_TYPEDEF 0
  62. #endif
  63. #ifndef __ASSEMBLER__
  64. /* Defined to concatenate the literal suffix to be used with _FloatN
  65. or _FloatNx types, if __HAVE_<type> is 1. The corresponding
  66. literal suffixes exist since GCC 7, for C only. */
  67. # if __HAVE_FLOAT16
  68. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  69. /* No corresponding suffix available for this type. */
  70. # define __f16(x) ((_Float16) x##f)
  71. # else
  72. # define __f16(x) x##f16
  73. # endif
  74. # endif
  75. # if __HAVE_FLOAT32
  76. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  77. # define __f32(x) x##f
  78. # else
  79. # define __f32(x) x##f32
  80. # endif
  81. # endif
  82. # if __HAVE_FLOAT64
  83. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  84. # ifdef __NO_LONG_DOUBLE_MATH
  85. # define __f64(x) x##l
  86. # else
  87. # define __f64(x) x
  88. # endif
  89. # else
  90. # define __f64(x) x##f64
  91. # endif
  92. # endif
  93. # if __HAVE_FLOAT32X
  94. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  95. # define __f32x(x) x
  96. # else
  97. # define __f32x(x) x##f32x
  98. # endif
  99. # endif
  100. # if __HAVE_FLOAT64X
  101. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  102. # if __HAVE_FLOAT64X_LONG_DOUBLE
  103. # define __f64x(x) x##l
  104. # else
  105. # define __f64x(x) __f128 (x)
  106. # endif
  107. # else
  108. # define __f64x(x) x##f64x
  109. # endif
  110. # endif
  111. # if __HAVE_FLOAT128X
  112. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  113. # error "_Float128X supported but no constant suffix"
  114. # else
  115. # define __f128x(x) x##f128x
  116. # endif
  117. # endif
  118. /* Defined to a complex type if __HAVE_<type> is 1. */
  119. # if __HAVE_FLOAT16
  120. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  121. typedef _Complex float __cfloat16 __attribute__ ((__mode__ (__HC__)));
  122. # define __CFLOAT16 __cfloat16
  123. # else
  124. # define __CFLOAT16 _Complex _Float16
  125. # endif
  126. # endif
  127. # if __HAVE_FLOAT32
  128. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  129. # define __CFLOAT32 _Complex float
  130. # else
  131. # define __CFLOAT32 _Complex _Float32
  132. # endif
  133. # endif
  134. # if __HAVE_FLOAT64
  135. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  136. # ifdef __NO_LONG_DOUBLE_MATH
  137. # define __CFLOAT64 _Complex long double
  138. # else
  139. # define __CFLOAT64 _Complex double
  140. # endif
  141. # else
  142. # define __CFLOAT64 _Complex _Float64
  143. # endif
  144. # endif
  145. # if __HAVE_FLOAT32X
  146. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  147. # define __CFLOAT32X _Complex double
  148. # else
  149. # define __CFLOAT32X _Complex _Float32x
  150. # endif
  151. # endif
  152. # if __HAVE_FLOAT64X
  153. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  154. # if __HAVE_FLOAT64X_LONG_DOUBLE
  155. # define __CFLOAT64X _Complex long double
  156. # else
  157. # define __CFLOAT64X __CFLOAT128
  158. # endif
  159. # else
  160. # define __CFLOAT64X _Complex _Float64x
  161. # endif
  162. # endif
  163. # if __HAVE_FLOAT128X
  164. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  165. # error "_Float128X supported but no complex type"
  166. # else
  167. # define __CFLOAT128X _Complex _Float128x
  168. # endif
  169. # endif
  170. /* The remaining of this file provides support for older compilers. */
  171. # if __HAVE_FLOAT16
  172. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  173. typedef float _Float16 __attribute__ ((__mode__ (__HF__)));
  174. # endif
  175. # if !__GNUC_PREREQ (7, 0)
  176. # define __builtin_huge_valf16() ((_Float16) __builtin_huge_val ())
  177. # define __builtin_inff16() ((_Float16) __builtin_inf ())
  178. # define __builtin_nanf16(x) ((_Float16) __builtin_nan (x))
  179. # define __builtin_nansf16(x) ((_Float16) __builtin_nans (x))
  180. # endif
  181. # endif
  182. # if __HAVE_FLOAT32
  183. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  184. typedef float _Float32;
  185. # endif
  186. # if !__GNUC_PREREQ (7, 0)
  187. # define __builtin_huge_valf32() (__builtin_huge_valf ())
  188. # define __builtin_inff32() (__builtin_inff ())
  189. # define __builtin_nanf32(x) (__builtin_nanf (x))
  190. # define __builtin_nansf32(x) (__builtin_nansf (x))
  191. # endif
  192. # endif
  193. # if __HAVE_FLOAT64
  194. /* If double, long double and _Float64 all have the same set of
  195. values, TS 18661-3 requires the usual arithmetic conversions on
  196. long double and _Float64 to produce _Float64. For this to be the
  197. case when building with a compiler without a distinct _Float64
  198. type, _Float64 must be a typedef for long double, not for
  199. double. */
  200. # ifdef __NO_LONG_DOUBLE_MATH
  201. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  202. typedef long double _Float64;
  203. # endif
  204. # if !__GNUC_PREREQ (7, 0)
  205. # define __builtin_huge_valf64() (__builtin_huge_vall ())
  206. # define __builtin_inff64() (__builtin_infl ())
  207. # define __builtin_nanf64(x) (__builtin_nanl (x))
  208. # define __builtin_nansf64(x) (__builtin_nansl (x))
  209. # endif
  210. # else
  211. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  212. typedef double _Float64;
  213. # endif
  214. # if !__GNUC_PREREQ (7, 0)
  215. # define __builtin_huge_valf64() (__builtin_huge_val ())
  216. # define __builtin_inff64() (__builtin_inf ())
  217. # define __builtin_nanf64(x) (__builtin_nan (x))
  218. # define __builtin_nansf64(x) (__builtin_nans (x))
  219. # endif
  220. # endif
  221. # endif
  222. # if __HAVE_FLOAT32X
  223. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  224. typedef double _Float32x;
  225. # endif
  226. # if !__GNUC_PREREQ (7, 0)
  227. # define __builtin_huge_valf32x() (__builtin_huge_val ())
  228. # define __builtin_inff32x() (__builtin_inf ())
  229. # define __builtin_nanf32x(x) (__builtin_nan (x))
  230. # define __builtin_nansf32x(x) (__builtin_nans (x))
  231. # endif
  232. # endif
  233. # if __HAVE_FLOAT64X
  234. # if __HAVE_FLOAT64X_LONG_DOUBLE
  235. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  236. typedef long double _Float64x;
  237. # endif
  238. # if !__GNUC_PREREQ (7, 0)
  239. # define __builtin_huge_valf64x() (__builtin_huge_vall ())
  240. # define __builtin_inff64x() (__builtin_infl ())
  241. # define __builtin_nanf64x(x) (__builtin_nanl (x))
  242. # define __builtin_nansf64x(x) (__builtin_nansl (x))
  243. # endif
  244. # else
  245. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  246. typedef _Float128 _Float64x;
  247. # endif
  248. # if !__GNUC_PREREQ (7, 0)
  249. # define __builtin_huge_valf64x() (__builtin_huge_valf128 ())
  250. # define __builtin_inff64x() (__builtin_inff128 ())
  251. # define __builtin_nanf64x(x) (__builtin_nanf128 (x))
  252. # define __builtin_nansf64x(x) (__builtin_nansf128 (x))
  253. # endif
  254. # endif
  255. # endif
  256. # if __HAVE_FLOAT128X
  257. # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
  258. # error "_Float128x supported but no type"
  259. # endif
  260. # if !__GNUC_PREREQ (7, 0)
  261. # define __builtin_huge_valf128x() ((_Float128x) __builtin_huge_val ())
  262. # define __builtin_inff128x() ((_Float128x) __builtin_inf ())
  263. # define __builtin_nanf128x(x) ((_Float128x) __builtin_nan (x))
  264. # define __builtin_nansf128x(x) ((_Float128x) __builtin_nans (x))
  265. # endif
  266. # endif
  267. #endif /* !__ASSEMBLER__. */
  268. #endif /* _BITS_FLOATN_COMMON_H */