1/* Macros to control TS 18661-3 glibc features on x86.
2 Copyright (C) 2017-2019 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 <http://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. */
29#if (defined __x86_64__ \
30 ? __GNUC_PREREQ (4, 3) \
31 : (defined __GNU__ ? __GNUC_PREREQ (4, 5) : __GNUC_PREREQ (4, 4)))
32# define __HAVE_FLOAT128 1
33#else
34# define __HAVE_FLOAT128 0
35#endif
36
37/* Defined to 1 if __HAVE_FLOAT128 is 1 and the type is ABI-distinct
38 from the default float, double and long double types in this glibc. */
39#if __HAVE_FLOAT128
40# define __HAVE_DISTINCT_FLOAT128 1
41#else
42# define __HAVE_DISTINCT_FLOAT128 0
43#endif
44
45/* Defined to 1 if the current compiler invocation provides a
46 floating-point type with the right format for _Float64x, and this
47 glibc includes corresponding *f64x interfaces for it. */
48#define __HAVE_FLOAT64X 1
49
50/* Defined to 1 if __HAVE_FLOAT64X is 1 and _Float64x has the format
51 of long double. Otherwise, if __HAVE_FLOAT64X is 1, _Float64x has
52 the format of _Float128, which must be different from that of long
53 double. */
54#define __HAVE_FLOAT64X_LONG_DOUBLE 1
55
56#ifndef __ASSEMBLER__
57
58/* Defined to concatenate the literal suffix to be used with _Float128
59 types, if __HAVE_FLOAT128 is 1. */
60# if __HAVE_FLOAT128
61# if !__GNUC_PREREQ (7, 0) || defined __cplusplus
62/* The literal suffix f128 exists only since GCC 7.0. */
63# define __f128(x) x##q
64# else
65# define __f128(x) x##f128
66# endif
67# endif
68
69/* Defined to a complex binary128 type if __HAVE_FLOAT128 is 1. */
70# if __HAVE_FLOAT128
71# if !__GNUC_PREREQ (7, 0) || defined __cplusplus
72/* Add a typedef for older GCC compilers which don't natively support
73 _Complex _Float128. */
74typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
75# define __CFLOAT128 __cfloat128
76# else
77# define __CFLOAT128 _Complex _Float128
78# endif
79# endif
80
81/* The remaining of this file provides support for older compilers. */
82# if __HAVE_FLOAT128
83
84/* The type _Float128 exists only since GCC 7.0. */
85# if !__GNUC_PREREQ (7, 0) || defined __cplusplus
86typedef __float128 _Float128;
87# endif
88
89/* __builtin_huge_valf128 doesn't exist before GCC 7.0. */
90# if !__GNUC_PREREQ (7, 0)
91# define __builtin_huge_valf128() ((_Float128) __builtin_huge_val ())
92# endif
93
94/* Older GCC has only a subset of built-in functions for _Float128 on
95 x86, and __builtin_infq is not usable in static initializers.
96 Converting a narrower sNaN to _Float128 produces a quiet NaN, so
97 attempts to use _Float128 sNaNs will not work properly with older
98 compilers. */
99# if !__GNUC_PREREQ (7, 0)
100# define __builtin_copysignf128 __builtin_copysignq
101# define __builtin_fabsf128 __builtin_fabsq
102# define __builtin_inff128() ((_Float128) __builtin_inf ())
103# define __builtin_nanf128(x) ((_Float128) __builtin_nan (x))
104# define __builtin_nansf128(x) ((_Float128) __builtin_nans (x))
105# endif
106
107/* In math/math.h, __MATH_TG will expand signbit to __builtin_signbit*,
108 e.g.: __builtin_signbitf128, before GCC 6. However, there has never
109 been a __builtin_signbitf128 in GCC and the type-generic builtin is
110 only available since GCC 6. */
111# if !__GNUC_PREREQ (6, 0)
112# define __builtin_signbitf128 __signbitf128
113# endif
114
115# endif
116
117#endif /* !__ASSEMBLER__. */
118
119#include <bits/floatn-common.h>
120
121#endif /* _BITS_FLOATN_H */
122