Skip to content

Commit fcee590

Browse files
Paul E. Murphyinconstante
Paul E. Murphy
authored andcommitted
float128: Add public _Float128 declarations to libm.
This introduces the machine-dependent bits/floatn.h to control the inclusion of _Float128 ABI. * bits/floatn.h: New file. * bits/huge_val_flt128.h: Likewise. * bits/libm-simd-decl-stubs.h (__DECL_SIMD_cosf128): New macro. (__DECL_SIMD_sinf128): Likewise. (__DECL_SIMD_sincosf128): Likewise. (__DECL_SIMD_logf128): Likewise. (__DECL_SIMD_expf128): Likewise. (__DECL_SIMD_powf128): Likewise. * math/Makefile (headers): Install bits/floatn.h and bits/huge_val_flt128.h. * math/bits/cmathcalls.h (_Mdouble_complex_): Only define if not defined. * math/bits/mathcalls.h (pow10, isinf, finite, drem, significand) (isnan, gamma, nexttoward, scalb): Only define if not __MATH_DECLARING_FLOATN. (nextdown, nextup, llogb, roundeven, fromfp, ufromfp, fromfpx) (ufromfpx, fmaxmag, fminmag, totalorder, totalordermag) (canonicalize, getpayload, setpayload, setpayloadsig): Declare for _FloatN even if __STDC_WANT_IEC_60559_BFP_EXT__ is not defined. * math/complex.h: Include bits/libc-header-start.h and bits/floatn.h. Include bits/cmathcalls.h to get the declarations of _Float128 versions of complex functions. [__HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)] (CMPLXF128): Define macro. * math/math.h: Include bits/floatn.h and bits/huge_val_flt128.h. Include bits/mathcalls-helper-functions.h and bits/mathcalls.h to get the declarations of _Float128 versions of math functions. (__MATH_DECLARING_FLOATN): New macro to control declaration of _FloatN types. [__GNUC_PREREQ (6,0)] (signbit): Since GCC 6.0, __builtin_signbit is type-generic, so use it without __MATH_TG. [__HAVE_DISTINCT_FLOAT128] (isinf): This builtin is broken for _Float128 type on GCC < 7.0. Explicitly call __isinff128 for _Float128 type and GCC < 7.0, otherwise use the builtin. [__HAVE_FLOAT128 && defined __USE_GNU] (M_Ef128, M_LOG2Ef128) (M_LOG10Ef128, M_LN2f128, M_LN10f128, M_PIf128, M_PI_2f128) (M_PI_4f128, M_1_PIf128, M_2_PIf128, M_SQRT2f128, M_SQRT1_2f128): New _GNU_SOURCE enabled macros.
1 parent e1d6e08 commit fcee590

File tree

9 files changed

+230
-18
lines changed

9 files changed

+230
-18
lines changed

ChangeLog

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,51 @@
1+
2017-05-14 Paul E. Murphy <[email protected]>
2+
Gabriel F. T. Gomes <[email protected]>
3+
4+
* bits/floatn.h: New file.
5+
* bits/huge_val_flt128.h: Likewise.
6+
7+
* bits/libm-simd-decl-stubs.h (__DECL_SIMD_cosf128): New macro.
8+
(__DECL_SIMD_sinf128): Likewise.
9+
(__DECL_SIMD_sincosf128): Likewise.
10+
(__DECL_SIMD_logf128): Likewise.
11+
(__DECL_SIMD_expf128): Likewise.
12+
(__DECL_SIMD_powf128): Likewise.
13+
14+
* math/Makefile (headers): Install bits/floatn.h and
15+
bits/huge_val_flt128.h.
16+
17+
* math/bits/cmathcalls.h (_Mdouble_complex_): Only define if not
18+
defined.
19+
20+
* math/bits/mathcalls.h (pow10, isinf, finite, drem, significand)
21+
(isnan, gamma, nexttoward, scalb): Only define if not
22+
__MATH_DECLARING_FLOATN.
23+
(nextdown, nextup, llogb, roundeven, fromfp, ufromfp, fromfpx)
24+
(ufromfpx, fmaxmag, fminmag, totalorder, totalordermag)
25+
(canonicalize, getpayload, setpayload, setpayloadsig): Declare for
26+
_FloatN even if __STDC_WANT_IEC_60559_BFP_EXT__ is not defined.
27+
28+
* math/complex.h: Include bits/libc-header-start.h and bits/floatn.h.
29+
Include bits/cmathcalls.h to get the declarations of _Float128
30+
versions of complex functions.
31+
[__HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)] (CMPLXF128):
32+
Define macro.
33+
34+
* math/math.h: Include bits/floatn.h and bits/huge_val_flt128.h.
35+
Include bits/mathcalls-helper-functions.h and bits/mathcalls.h to
36+
get the declarations of _Float128 versions of math functions.
37+
(__MATH_DECLARING_FLOATN): New macro to control declaration of
38+
_FloatN types.
39+
[__GNUC_PREREQ (6,0)] (signbit): Since GCC 6.0, __builtin_signbit
40+
is type-generic, so use it without __MATH_TG.
41+
[__HAVE_DISTINCT_FLOAT128] (isinf): This builtin is broken for
42+
_Float128 type on GCC < 7.0. Explicitly call __isinff128 for
43+
_Float128 type and GCC < 7.0, otherwise use the builtin.
44+
[__HAVE_FLOAT128 && defined __USE_GNU] (M_Ef128, M_LOG2Ef128)
45+
(M_LOG10Ef128, M_LN2f128, M_LN10f128, M_PIf128, M_PI_2f128)
46+
(M_PI_4f128, M_1_PIf128, M_2_PIf128, M_SQRT2f128, M_SQRT1_2f128):
47+
New _GNU_SOURCE enabled macros.
48+
149
2017-05-12 Joseph Myers <[email protected]>
250

351
* sysdeps/sparc/sparc32/fpu/s_signbit.S (signbit): Remove alias.

bits/floatn.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* Macros to control TS 18661-3 glibc features.
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+
/* Defined to 1 if the current compiler invocation provides a
20+
floating-point type with the IEEE 754 binary128 format, and this glibc
21+
includes corresponding *f128 interfaces for it. */
22+
#define __HAVE_FLOAT128 0
23+
24+
/* Defined to 1 if __HAVE_FLOAT128 is 1 and the type is ABI-distinct
25+
from the default float, double and long double types in this glibc. */
26+
#define __HAVE_DISTINCT_FLOAT128 0
27+
28+
/* Defined to concatenate the literal suffix to be used with _Float128
29+
types, if __HAVE_FLOAT128 is 1.
30+
E.g.: #define __f128(x) x##f128. */
31+
#undef __f128
32+
33+
/* Defined to a complex binary128 type if __HAVE_FLOAT128 is 1.
34+
E.g.: #define __CFLOAT128 _Complex _Float128. */
35+
#undef __CFLOAT128

bits/huge_val_flt128.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Default `HUGE_VAL_F128' constant.
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 _MATH_H
20+
# error "Never use <bits/huge_val_flt128.h> directly; include <math.h> instead."
21+
#endif
22+
23+
#define HUGE_VAL_F128 (__builtin_huge_valf128 ())

bits/libm-simd-decl-stubs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,30 @@
3636
#define __DECL_SIMD_cos
3737
#define __DECL_SIMD_cosf
3838
#define __DECL_SIMD_cosl
39+
#define __DECL_SIMD_cosf128
3940

4041
#define __DECL_SIMD_sin
4142
#define __DECL_SIMD_sinf
4243
#define __DECL_SIMD_sinl
44+
#define __DECL_SIMD_sinf128
4345

4446
#define __DECL_SIMD_sincos
4547
#define __DECL_SIMD_sincosf
4648
#define __DECL_SIMD_sincosl
49+
#define __DECL_SIMD_sincosf128
4750

4851
#define __DECL_SIMD_log
4952
#define __DECL_SIMD_logf
5053
#define __DECL_SIMD_logl
54+
#define __DECL_SIMD_logf128
5155

5256
#define __DECL_SIMD_exp
5357
#define __DECL_SIMD_expf
5458
#define __DECL_SIMD_expl
59+
#define __DECL_SIMD_expf128
5560

5661
#define __DECL_SIMD_pow
5762
#define __DECL_SIMD_powf
5863
#define __DECL_SIMD_powl
64+
#define __DECL_SIMD_powf128
5965
#endif

math/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ headers := math.h bits/mathcalls.h bits/mathinline.h bits/huge_val.h \
2929
bits/math-finite.h bits/math-vector.h \
3030
bits/libm-simd-decl-stubs.h bits/iscanonical.h \
3131
bits/flt-eval-method.h bits/fp-fast.h bits/fp-logb.h \
32-
bits/long-double.h bits/mathcalls-helper-functions.h
32+
bits/long-double.h bits/mathcalls-helper-functions.h \
33+
bits/floatn.h bits/huge_val_flt128.h
3334

3435
# FPU support code.
3536
aux := setfpucw fpu_control

math/bits/cmathcalls.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
#error "Never use <bits/cmathcalls.h> directly; include <complex.h> instead."
4545
#endif
4646

47-
#define _Mdouble_complex_ _Mdouble_ _Complex
47+
#ifndef _Mdouble_complex_
48+
# define _Mdouble_complex_ _Mdouble_ _Complex
49+
#endif
4850

4951

5052
/* Trigonometric functions. */

math/bits/mathcalls.h

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ __MATHCALL (exp10,, (_Mdouble_ __x));
115115
#endif
116116
#ifdef __USE_GNU
117117
/* Another name occasionally used. */
118+
# if !__MATH_DECLARING_FLOATN
118119
__MATHCALL (pow10,, (_Mdouble_ __x));
120+
# endif
119121
#endif
120122

121123
#if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
@@ -172,14 +174,16 @@ __MATHCALLX (floor,, (_Mdouble_ __x), (__const__));
172174
__MATHCALL (fmod,, (_Mdouble_ __x, _Mdouble_ __y));
173175

174176
#ifdef __USE_MISC
175-
# if (!defined __cplusplus \
176-
|| __cplusplus < 201103L /* isinf conflicts with C++11. */ \
177-
|| __MATH_DECLARING_DOUBLE == 0) /* isinff or isinfl don't. */
177+
# if ((!defined __cplusplus \
178+
|| __cplusplus < 201103L /* isinf conflicts with C++11. */ \
179+
|| __MATH_DECLARING_DOUBLE == 0)) /* isinff or isinfl don't. */ \
180+
&& !__MATH_DECLARING_FLOATN
178181
/* Return 0 if VALUE is finite or NaN, +1 if it
179182
is +Infinity, -1 if it is -Infinity. */
180183
__MATHDECL_1 (int,isinf,, (_Mdouble_ __value)) __attribute__ ((__const__));
181184
# endif
182185

186+
# if !__MATH_DECLARING_FLOATN
183187
/* Return nonzero if VALUE is finite and not NaN. */
184188
__MATHDECL_1 (int,finite,, (_Mdouble_ __value)) __attribute__ ((__const__));
185189

@@ -189,6 +193,8 @@ __MATHCALL (drem,, (_Mdouble_ __x, _Mdouble_ __y));
189193

190194
/* Return the fractional part of X after dividing out `ilogb (X)'. */
191195
__MATHCALL (significand,, (_Mdouble_ __x));
196+
# endif
197+
192198
#endif /* Use misc. */
193199

194200
#ifdef __USE_ISOC99
@@ -203,9 +209,10 @@ __MATHCALLX (nan,, (const char *__tagb), (__const__));
203209

204210

205211
#if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
206-
# if (!defined __cplusplus \
207-
|| __cplusplus < 201103L /* isnan conflicts with C++11. */ \
208-
|| __MATH_DECLARING_DOUBLE == 0) /* isnanf or isnanl don't. */
212+
# if ((!defined __cplusplus \
213+
|| __cplusplus < 201103L /* isnan conflicts with C++11. */ \
214+
|| __MATH_DECLARING_DOUBLE == 0)) /* isnanf or isnanl don't. */ \
215+
&& !__MATH_DECLARING_FLOATN
209216
/* Return nonzero if VALUE is not a number. */
210217
__MATHDECL_1 (int,isnan,, (_Mdouble_ __value)) __attribute__ ((__const__));
211218
# endif
@@ -235,8 +242,10 @@ __MATHCALL (tgamma,, (_Mdouble_));
235242
#endif
236243

237244
#if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
245+
# if !__MATH_DECLARING_FLOATN
238246
/* Obsolete alias for `lgamma'. */
239247
__MATHCALL (gamma,, (_Mdouble_));
248+
# endif
240249
#endif
241250

242251
#ifdef __USE_MISC
@@ -254,11 +263,11 @@ __MATHCALL (rint,, (_Mdouble_ __x));
254263

255264
/* Return X + epsilon if X < Y, X - epsilon if X > Y. */
256265
__MATHCALLX (nextafter,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
257-
# if defined __USE_ISOC99 && !defined __LDBL_COMPAT
266+
# if defined __USE_ISOC99 && !defined __LDBL_COMPAT && !__MATH_DECLARING_FLOATN
258267
__MATHCALLX (nexttoward,, (_Mdouble_ __x, long double __y), (__const__));
259268
# endif
260269

261-
#if __GLIBC_USE (IEC_60559_BFP_EXT)
270+
# if __GLIBC_USE (IEC_60559_BFP_EXT) || __MATH_DECLARING_FLOATN
262271
/* Return X - epsilon. */
263272
__MATHCALL (nextdown,, (_Mdouble_ __x));
264273
/* Return X + epsilon. */
@@ -277,7 +286,7 @@ __MATHCALL (scalbn,, (_Mdouble_ __x, int __n));
277286
__MATHDECL (int,ilogb,, (_Mdouble_ __x));
278287
#endif
279288

280-
#if __GLIBC_USE (IEC_60559_BFP_EXT)
289+
#if __GLIBC_USE (IEC_60559_BFP_EXT) || __MATH_DECLARING_FLOATN
281290
/* Like ilogb, but returning long int. */
282291
__MATHDECL (long int, llogb,, (_Mdouble_ __x));
283292
#endif
@@ -332,7 +341,7 @@ __MATHCALLX (fmin,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));
332341
__MATHCALL (fma,, (_Mdouble_ __x, _Mdouble_ __y, _Mdouble_ __z));
333342
#endif /* Use ISO C99. */
334343

335-
#if __GLIBC_USE (IEC_60559_BFP_EXT)
344+
#if __GLIBC_USE (IEC_60559_BFP_EXT) || __MATH_DECLARING_FLOATN
336345
/* Round X to nearest integer value, rounding halfway cases to even. */
337346
__MATHCALLX (roundeven,, (_Mdouble_ __x), (__const__));
338347

@@ -385,9 +394,10 @@ __MATHDECL_1 (int, setpayload,, (_Mdouble_ *__x, _Mdouble_ __payload));
385394
__MATHDECL_1 (int, setpayloadsig,, (_Mdouble_ *__x, _Mdouble_ __payload));
386395
#endif
387396

388-
#if defined __USE_MISC || (defined __USE_XOPEN_EXTENDED \
389-
&& __MATH_DECLARING_DOUBLE \
390-
&& !defined __USE_XOPEN2K8)
397+
#if (defined __USE_MISC || (defined __USE_XOPEN_EXTENDED \
398+
&& __MATH_DECLARING_DOUBLE \
399+
&& !defined __USE_XOPEN2K8)) \
400+
&& !__MATH_DECLARING_FLOATN
391401
/* Return X times (2 to the Nth power). */
392402
__MATHCALL (scalb,, (_Mdouble_ __x, _Mdouble_ __n));
393403
#endif

math/complex.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
#ifndef _COMPLEX_H
2323
#define _COMPLEX_H 1
2424

25-
#include <features.h>
25+
#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
26+
#include <bits/libc-header-start.h>
2627

2728
/* Get general and ISO C99 specific information. */
2829
#include <bits/mathdef.h>
2930

31+
/* Gather machine-dependent _FloatN type support. */
32+
#include <bits/floatn.h>
33+
3034
__BEGIN_DECLS
3135

3236
/* We might need to add support for more compilers here. But since ISO
@@ -55,6 +59,10 @@ __BEGIN_DECLS
5559
# define CMPLXL(x, y) __builtin_complex ((long double) (x), (long double) (y))
5660
#endif
5761

62+
#if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
63+
# define CMPLXF128(x, y) __builtin_complex ((_Float128) (x), (_Float128) (y))
64+
#endif
65+
5866
/* The file <bits/cmathcalls.h> contains the prototypes for all the
5967
actual math functions. These macros are used for those prototypes,
6068
so we can easily declare each function as both `name' and `__name',
@@ -84,6 +92,24 @@ __BEGIN_DECLS
8492
#undef _Mdouble_
8593
#undef __MATH_PRECNAME
8694

95+
#if (__HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)) \
96+
&& __GLIBC_USE (IEC_60559_TYPES_EXT)
97+
# ifndef _Mfloat128_
98+
# define _Mfloat128_ _Float128
99+
# endif
100+
/* GCC < 7 requires extra convincing to expose a complex float128 type. */
101+
# ifdef __CFLOAT128
102+
# undef _Mdouble_complex_
103+
# define _Mdouble_complex_ __CFLOAT128
104+
# endif
105+
# define _Mdouble_ _Mfloat128_
106+
# define __MATH_PRECNAME(name) name##f128
107+
# include <bits/cmathcalls.h>
108+
# undef _Mdouble_
109+
# undef __MATH_PRECNAME
110+
# undef _Mdouble_complex_
111+
#endif
112+
87113
/* And the long double versions. It is non-critical to define them
88114
here unconditionally since `long double' is required in ISO C99. */
89115
#if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \

0 commit comments

Comments
 (0)