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