1/* Macros to control TS 18661-3 glibc features on x86.
2 Copyright (C) 2017 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 concatenate the literal suffix to be used with _Float128
46 types, if __HAVE_FLOAT128 is 1. */
47#if __HAVE_FLOAT128
48# if !__GNUC_PREREQ (7, 0) || defined __cplusplus
49/* The literal suffix f128 exists only since GCC 7.0. */
50# define __f128(x) x##q
51# else
52# define __f128(x) x##f128
53# endif
54#endif
55
56/* Defined to a complex binary128 type if __HAVE_FLOAT128 is 1. */
57#if __HAVE_FLOAT128
58# if !__GNUC_PREREQ (7, 0) || defined __cplusplus
59/* Add a typedef for older GCC compilers which don't natively support
60 _Complex _Float128. */
61typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__TC__)));
62# define __CFLOAT128 __cfloat128
63# else
64# define __CFLOAT128 _Complex _Float128
65# endif
66#endif
67
68/* The remaining of this file provides support for older compilers. */
69#if __HAVE_FLOAT128
70
71/* The type _Float128 exists only since GCC 7.0. */
72# if !__GNUC_PREREQ (7, 0) || defined __cplusplus
73typedef __float128 _Float128;
74# endif
75
76/* __builtin_huge_valf128 doesn't exist before GCC 7.0. */
77# if !__GNUC_PREREQ (7, 0)
78# define __builtin_huge_valf128() ((_Float128) __builtin_huge_val ())
79# endif
80
81/* Older GCC has only a subset of built-in functions for _Float128 on
82 x86, and __builtin_infq is not usable in static initializers.
83 Converting a narrower sNaN to _Float128 produces a quiet NaN, so
84 attempts to use _Float128 sNaNs will not work properly with older
85 compilers. */
86# if !__GNUC_PREREQ (7, 0)
87# define __builtin_copysignf128 __builtin_copysignq
88# define __builtin_fabsf128 __builtin_fabsq
89# define __builtin_inff128() ((_Float128) __builtin_inf ())
90# define __builtin_nanf128(x) ((_Float128) __builtin_nan (x))
91# define __builtin_nansf128(x) ((_Float128) __builtin_nans (x))
92# endif
93
94/* In math/math.h, __MATH_TG will expand signbit to __builtin_signbit*,
95 e.g.: __builtin_signbitf128, before GCC 6. However, there has never
96 been a __builtin_signbitf128 in GCC and the type-generic builtin is
97 only available since GCC 6. */
98# if !__GNUC_PREREQ (6, 0)
99# define __builtin_signbitf128 __signbitf128
100# endif
101
102#endif
103
104#endif /* _BITS_FLOATN_H */
105