[PATCH v2 6/8] float128: Add private _Float128 declarations for libm.
Gabriel F. T. Gomes
gftg@linux.vnet.ibm.com
Fri Apr 28 21:36:00 GMT 2017
From: "Paul E. Murphy" <murphyp@linux.vnet.ibm.com>
Add the necessary bits to the private headers to support
building the _Float128 libm functions.
A local override for float.h is provided to include the
missing *FLT128 macros implied by TS 18661-3 for this
type when compiling prior to GCC 7.
* 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.
* include/complex.h (__kernel_casinhf128): New declaration.
* include/float.h: New file.
* include/math.h (__finitef128): Add a hidden def.
(__isinff128): Likewise.
(__isnanf128): Likewise.
(__fpclassify): Likewise.
(__issignalling): Likewise.
(__expf128): Likewise.
(__expm1f128): Likewise.
* sysdeps/generic/fix-fp-int-convert-overflow.h:
(FIX_FLT128_LONG_CONVERT_OVERFLOW): New macro.
(FIX_FLT128_LLONG_CONVERT_OVERFLOW): Likewise.
* sysdeps/generic/math-type-macros-float128.h: New file.
* sysdeps/generic/math_private.h: Include math_private_calls.h
for _Float128.
(__isinff128): New inline implementation used when GCC < 7.0,
since in this case __builtin_isinf_sign is broken.
(fabsf128): New inline implementation that calls the builtin.
(signbitf128): Likewise.
(__EXPR_FLT128): New macro.
(min_of_type): Optionally include _Float128 types too.
* sysdeps/generic/math_private_calls.h (__kernel_sincos):
Declare for _Float128.
(__kernel_rem_pio2): Likewise.
* sysdeps/ieee754/ldbl-opt/s_sin.c:
(__DECL_SIMD_sincos_disablef128): New macro.
---
bits/libm-simd-decl-stubs.h | 6 +++
include/complex.h | 7 ++++
include/float.h | 31 +++++++++++++++
include/math.h | 13 +++++++
sysdeps/generic/fix-fp-int-convert-overflow.h | 2 +
sysdeps/generic/math-type-macros-float128.h | 43 ++++++++++++++++++++
sysdeps/generic/math_private.h | 56 ++++++++++++++++++++++++++-
sysdeps/generic/math_private_calls.h | 4 +-
sysdeps/ieee754/ldbl-opt/s_sin.c | 1 +
9 files changed, 160 insertions(+), 3 deletions(-)
create mode 100644 include/float.h
create mode 100644 sysdeps/generic/math-type-macros-float128.h
diff --git a/bits/libm-simd-decl-stubs.h b/bits/libm-simd-decl-stubs.h
index 7328eb2..6794b9f 100644
--- a/bits/libm-simd-decl-stubs.h
+++ b/bits/libm-simd-decl-stubs.h
@@ -36,24 +36,30 @@
#define __DECL_SIMD_cos
#define __DECL_SIMD_cosf
#define __DECL_SIMD_cosl
+#define __DECL_SIMD_cosf128
#define __DECL_SIMD_sin
#define __DECL_SIMD_sinf
#define __DECL_SIMD_sinl
+#define __DECL_SIMD_sinf128
#define __DECL_SIMD_sincos
#define __DECL_SIMD_sincosf
#define __DECL_SIMD_sincosl
+#define __DECL_SIMD_sincosf128
#define __DECL_SIMD_log
#define __DECL_SIMD_logf
#define __DECL_SIMD_logl
+#define __DECL_SIMD_logf128
#define __DECL_SIMD_exp
#define __DECL_SIMD_expf
#define __DECL_SIMD_expl
+#define __DECL_SIMD_expf128
#define __DECL_SIMD_pow
#define __DECL_SIMD_powf
#define __DECL_SIMD_powl
+#define __DECL_SIMD_powf128
#endif
diff --git a/include/complex.h b/include/complex.h
index 082e71f..8eec3a0 100644
--- a/include/complex.h
+++ b/include/complex.h
@@ -8,6 +8,13 @@
extern complex float __kernel_casinhf (complex float z, int adj);
extern complex double __kernel_casinh (complex double z, int adj);
extern complex long double __kernel_casinhl (complex long double z, int adj);
+# if __USE_FLOAT128
+# ifdef __CFLOAT128
+extern __CFLOAT128 __kernel_casinhf128 (__CFLOAT128 z, int adj);
+# else
+extern _Complex _Float128 __kernel_casinhf128 (_Complex _Float128 z, int adj);
+# endif
+# endif
# endif
#endif
diff --git a/include/float.h b/include/float.h
new file mode 100644
index 0000000..f792158
--- /dev/null
+++ b/include/float.h
@@ -0,0 +1,31 @@
+#ifndef _LIBC_FLOAT_H
+#define _LIBC_FLOAT_H
+
+#ifndef _ISOMAC
+# define __STDC_WANT_IEC_60559_TYPES_EXT__
+#endif
+
+#include_next <float.h>
+
+/* Supplement float.h macros for _Float128 for older compilers
+ which do not yet support the type. These are described in
+ TS 18661-3. */
+#ifndef _ISOMAC
+# include <features.h>
+# include <bits/floatn.h>
+# if !__GNUC_PREREQ (7,0) && __USE_FLOAT128
+# define FLT128_MANT_DIG 113
+# define FLT128_DECIMAL_DIG 36
+# define FLT128_DIG 33
+# define FLT128_MIN_EXP (-16381)
+# define FLT128_MIN_10_EXP (-4931)
+# define FLT128_MAX_EXP 16384
+# define FLT128_MAX_10_EXP 4932
+# define FLT128_MAX 1.18973149535723176508575932662800702e+4932Q
+# define FLT128_EPSILON 1.92592994438723585305597794258492732e-34Q
+# define FLT128_MIN 3.36210314311209350626267781732175260e-4932Q
+# define FLT128_TRUE_MIN 6.47517511943802511092443895822764655e-4966Q
+# endif
+#endif
+
+#endif /* _LIBC_FLOAT_H */
diff --git a/include/math.h b/include/math.h
index a4f5562..a61d6f7 100644
--- a/include/math.h
+++ b/include/math.h
@@ -21,6 +21,12 @@ hidden_proto (__finitel)
hidden_proto (__isinfl)
hidden_proto (__isnanl)
# endif
+
+# if __USE_FLOAT128
+hidden_proto (__finitef128)
+hidden_proto (__isinff128)
+hidden_proto (__isnanf128)
+# endif
# endif
libm_hidden_proto (__fpclassify)
@@ -38,5 +44,12 @@ libm_hidden_proto (__expl)
libm_hidden_proto (__expm1l)
# endif
+# if __USE_FLOAT128
+libm_hidden_proto (__fpclassifyf128)
+libm_hidden_proto (__issignalingf128)
+libm_hidden_proto (__expf128)
+libm_hidden_proto (__expm1f128)
+# endif
+
#endif
#endif
diff --git a/sysdeps/generic/fix-fp-int-convert-overflow.h b/sysdeps/generic/fix-fp-int-convert-overflow.h
index f53eaf0..4b0cd91 100644
--- a/sysdeps/generic/fix-fp-int-convert-overflow.h
+++ b/sysdeps/generic/fix-fp-int-convert-overflow.h
@@ -29,5 +29,7 @@
#define FIX_DBL_LLONG_CONVERT_OVERFLOW 0
#define FIX_LDBL_LONG_CONVERT_OVERFLOW 0
#define FIX_LDBL_LLONG_CONVERT_OVERFLOW 0
+#define FIX_FLT128_LONG_CONVERT_OVERFLOW 0
+#define FIX_FLT128_LLONG_CONVERT_OVERFLOW 0
#endif /* fix-fp-int-convert-overflow.h */
diff --git a/sysdeps/generic/math-type-macros-float128.h b/sysdeps/generic/math-type-macros-float128.h
new file mode 100644
index 0000000..4cd23a0
--- /dev/null
+++ b/sysdeps/generic/math-type-macros-float128.h
@@ -0,0 +1,43 @@
+/* Helper macros for _Float128 variants of type generic functions of libm.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _MATH_TYPE_MACROS_FLOAT128
+#define _MATH_TYPE_MACROS_FLOAT128
+
+#include <math.h>
+#include <complex.h>
+
+#define M_LIT(c) __f128 (c)
+#define M_PFX FLT128
+#define M_SUF(c) c ## f128
+#define FLOAT _Float128
+#define M_STRTO_NAN __strtof128_nan
+
+#ifdef __CFLOAT128
+# define CFLOAT __CFLOAT128
+#else
+# define CFLOAT _Complex _Float128
+#endif
+
+#define M_MLIT(c) c ## f128
+
+
+/* Supply the generic macros. */
+#include <math-type-macros.h>
+
+#endif
diff --git a/sysdeps/generic/math_private.h b/sysdeps/generic/math_private.h
index 4d8a35f..96ed252 100644
--- a/sysdeps/generic/math_private.h
+++ b/sysdeps/generic/math_private.h
@@ -23,6 +23,9 @@
#include <float.h>
#include <get-rounding-mode.h>
+/* Gather machine dependent _Floatn support. */
+#include <bits/floatn.h>
+
/* The original fdlibm code used statements like:
n0 = ((*(int*)&one)>>29)^1; * index of high word *
ix0 = *(n0+(int*)&x); * high word of x *
@@ -211,6 +214,46 @@ do { \
#undef _MSUF_
#undef _Mdouble_
+#if __USE_FLOAT128
+# define _Mdouble_ _Float128
+# define _MSUF_ f128
+# define __MATH_DECLARING_FLOAT128
+# include <math_private_calls.h>
+# undef __MATH_DECLARING_FLOAT128
+# undef _MSUF_
+# undef _Mdouble_
+#endif
+
+#if __USE_FLOAT128
+
+/* __builtin_isinf_sign is broken in GCC < 7 for float128. */
+# if ! __GNUC_PREREQ (7, 0)
+# include <ieee754_float128.h>
+extern inline int
+__isinff128 (_Float128 x)
+{
+ int64_t hx, lx;
+ GET_FLOAT128_WORDS64 (hx, lx, x);
+ lx |= (hx & 0x7fffffffffffffffLL) ^ 0x7fff000000000000LL;
+ lx |= -lx;
+ return ~(lx >> 63) & (hx >> 62);
+}
+# endif
+
+extern inline _Float128
+fabsf128 (_Float128 x)
+{
+ return __builtin_fabsf128 (x);
+}
+extern inline _Float128
+signbitf128 (_Float128 x)
+{
+ return __builtin_signbit (x);
+}
+#endif
+
+
+
/* fdlibm kernel function */
extern double __kernel_standard (double,double,int);
extern float __kernel_standard_f (float,float,int);
@@ -263,13 +306,24 @@ extern void __docos (double __x, double __dx, double __v[]);
})
#endif
+#if __USE_FLOAT128
+# define __EXPR_FLT128(x, yes, no) \
+ __builtin_choose_expr (__builtin_types_compatible_p \
+ (__typeof (x), long double), no, yes)
+#else
+# define __EXPR_FLT128(x, yes, no) no
+#endif
+
+
#define fabs_tg(x) __MATH_TG ((x), (__typeof (x)) __builtin_fabs, (x))
+
#define min_of_type(type) __builtin_choose_expr \
(__builtin_types_compatible_p (type, float), \
FLT_MIN, \
__builtin_choose_expr \
(__builtin_types_compatible_p (type, double), \
- DBL_MIN, LDBL_MIN))
+ DBL_MIN, \
+ __EXPR_FLT128 (x, FLT128_MIN, LDBL_MIN)))
/* If X (which is not a NaN) is subnormal, force an underflow
exception. */
diff --git a/sysdeps/generic/math_private_calls.h b/sysdeps/generic/math_private_calls.h
index 8c1d304..eaff86a 100644
--- a/sysdeps/generic/math_private_calls.h
+++ b/sysdeps/generic/math_private_calls.h
@@ -64,12 +64,12 @@ extern _Mdouble_ __MSUF (__kernel_sin) (_Mdouble_, _Mdouble_, int);
extern _Mdouble_ __MSUF (__kernel_cos) (_Mdouble_, _Mdouble_);
extern _Mdouble_ __MSUF (__kernel_tan) (_Mdouble_, _Mdouble_, int);
-#if defined __MATH_DECLARING_LONG_DOUBLE
+#if defined __MATH_DECLARING_LONG_DOUBLE || defined __MATH_DECLARING_FLOAT128
extern void __MSUF (__kernel_sincos) (_Mdouble_, _Mdouble_,
_Mdouble_ *, _Mdouble_ *, int);
#endif
-#if !defined __MATH_DECLARING_LONG_DOUBLE
+#if !defined __MATH_DECLARING_LONG_DOUBLE || defined __MATH_DECLARING_FLOAT128
extern int __MSUF (__kernel_rem_pio2) (_Mdouble_ *, _Mdouble_ *, int,
int, int, const int32_t *);
#endif
diff --git a/sysdeps/ieee754/ldbl-opt/s_sin.c b/sysdeps/ieee754/ldbl-opt/s_sin.c
index 04e60e2..6932ccc 100644
--- a/sysdeps/ieee754/ldbl-opt/s_sin.c
+++ b/sysdeps/ieee754/ldbl-opt/s_sin.c
@@ -4,6 +4,7 @@
#define __DECL_SIMD_sincos_disable
#define __DECL_SIMD_sincos_disablef
#define __DECL_SIMD_sincos_disablel
+#define __DECL_SIMD_sincos_disablef128
#include <math_ldbl_opt.h>
#undef NAN
#undef sincos
--
2.4.11
More information about the Libc-alpha
mailing list