aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2018-02-09 21:18:52 +0000
committerJoseph Myers <joseph@codesourcery.com>2018-02-09 21:18:52 +0000
commit63716ab270df6846233e82c8b7ef494be90b2c45 (patch)
treeb52c6737c0781ee02499a17453e8467ae490c739
parentbfd475876f4b71474a640fc2d4c6904e03f3fedc (diff)
downloadglibc-63716ab270df6846233e82c8b7ef494be90b2c45.zip
glibc-63716ab270df6846233e82c8b7ef494be90b2c45.tar.gz
glibc-63716ab270df6846233e82c8b7ef494be90b2c45.tar.bz2
Add build infrastructure for narrowing libm functions.
TS 18661-1 defines libm functions that carry out an operation (+ - * / sqrt fma) on their arguments and return a result rounded to a (usually) narrower type, as if the original result were computed to infinite precision and then rounded directly to the result type without any intermediate rounding to the argument type. For example, fadd, faddl and daddl for addition. These are the last remaining TS 18661-1 functions left to be added to glibc. TS 18661-3 extends this to corresponding functions for _FloatN and _FloatNx types. As functions parametrized by two rather than one varying floating-point types, these functions require infrastructure in glibc that was not required for previous libm functions. This patch provides such infrastructure - excluding test support, and actual function implementations, which will be in subsequent patches. Declaring the functions uses a header bits/mathcalls-narrow.h, which is included many times, for each relevant pair of types. This will end up containing macro calls of the form __MATHCALL_NARROW (__MATHCALL_NAME (add), __MATHCALL_REDIR_NAME (add), 2); for each family of narrowing functions. (The structure of this macro call, with the calls to __MATHCALL_NAME and __MATHCALL_REDIR_NAME there rather than in the definition of __MATHCALL_NARROW, arises from the names such as "add" *not* themselves being reserved identifiers - meaning it's necessary to avoid any indirection that would result in a user-defined "add" macro being expanded.) Whereas for existing functions declaring long double functions is disabled if _LIBC in the case where they alias double functions, to facilitate defining the long double functions as aliases of the double ones, there is no such logic for the narrowing functions in this patch. Rather, the files defining such functions are expected to use #define to hide the original declarations of the alias names, to avoid errors about defining aliases with incompatible types. math/Makefile support is added for building the functions (listed in libm-narrow-fns, currently empty) for all relevant pairs of types. An internal header math-narrow.h is added for macros shared between multiple function implementations - currently a ROUND_TO_ODD macro to facilitate writing functions using the round-to-odd implementation approach, and alias macros to create all the required function aliases. libc_feholdexcept_setroundf128 and libc_feupdateenv_testf128 are added for use when required (only for x86_64). float128_private.h support is added for ldbl-128 narrowing functions to be used for _Float128. Certain things are specifically omitted from this patch and the immediate followups. tgmath.h support is deferred; there remain unresolved questions about how the type-generic macros for these functions are supposed to work, especially in the case of arguments of integer type. The math.h / bits/mathcalls-narrow.h logic, and the logic for determining what functions / aliases to define, will need some adjustments to support the sqrt and fma functions, where e.g. f32xsqrtf64 can just be an alias for sqrt rather than a separate function. TS 18661-1 defines FP_FAST_* macros but no support is included for defining them (they won't in general be true without architecture-specific optimized function versions). For each of the function groups (add sub mul div sqrt fma) there are always six functions present (e.g. fadd, faddl, daddl, f32addf64, f32addf32x, f32xaddf64). When _Float64x and _Float128 are supported, there are seven more (e.g. f32addf64x, f32addf128, f64addf64x, f64addf128, f32xaddf64x, f32xaddf128, f64xaddf128). In addition, in the ldbl-opt case there are function names such as __nldbl_daddl (an alias for f32xaddf64, which is not a reserved name in TS 18661-1, only in TS 18661-3), for calls to daddl to be mapped to in the -mlong-double-64 case. (Calls to faddl just get mapped to fadd, and for sqrt and fma there won't be __nldbl_* functions because dsqrtl and dfmal can just be mapped to sqrt and fma with -mlong-double-64.) While there are six or thirteen functions present in each group (plus __nldbl_* names only as an ABI, not an API), not all are distinct; they fall in various groups of aliases. There are two distinct versions built if long double has the same format as double; four if they have distinct formats but there is no _Float64x or _Float128 support; five if long double has binary128 format; seven when _Float128 is distinct from long double. Architecture-specific optimized versions are possible, but not included in my patches. For example, IA64 generally supports narrowing the result of most floating-point instructions; Power ISA 2.07 (POWER8) supports double values as arguments to float instructions, with the results narrowed as expected; Power ISA 3 (POWER9) supports round-to-odd for float128 instructions, so meaning that approach can be used without needing to set and restore the rounding mode and test "inexact". I intend to leave any such optimized versions to the architecture maintainers. Generally in such cases it would also make sense for calls to these functions to be expanded inline (given -fno-math-errno); I put a suggestion for TS 18661-1 built-in functions at <https://gcc.gnu.org/wiki/SummerOfCode>. Tested for x86_64 (this patch in isolation, as well as testing for various configurations in conjunction with further patches). * math/bits/mathcalls-narrow.h: New file. * include/bits/mathcalls-narrow.h: Likewise. * math/math-narrow.h: Likewise. * math/math.h (__MATHCALL_NARROW_ARGS_1): New macro. (__MATHCALL_NARROW_ARGS_2): Likewise. (__MATHCALL_NARROW_ARGS_3): Likewise. (__MATHCALL_NARROW_NORMAL): Likewise. (__MATHCALL_NARROW_REDIR): Likewise. (__MATHCALL_NARROW): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT)]: Repeatedly include <bits/mathcalls-narrow.h> with _Mret_, _Marg_ and __MATHCALL_NAME defined. [__GLIBC_USE (IEC_60559_TYPES_EXT)]: Likewise. * math/Makefile (headers): Add bits/mathcalls-narrow.h. (libm-narrow-fns): New variable. (libm-narrow-types-basic): Likewise. (libm-narrow-types-ldouble-yes): Likewise. (libm-narrow-types-float128-yes): Likewise. (libm-narrow-types-float128-alias-yes): Likewise. (libm-narrow-types): Likewise. (libm-routines): Add narrowing functions. * sysdeps/i386/fpu/fenv_private.h [__x86_64__] (libc_feholdexcept_setroundf128): New macro. [__x86_64__] (libc_feupdateenv_testf128): Likewise. * sysdeps/ieee754/float128/float128_private.h: Include <math/math-narrow.h>. [libc_feholdexcept_setroundf128] (libc_feholdexcept_setroundl): Undefine and redefine. [libc_feupdateenv_testf128] (libc_feupdateenv_testl): Likewise. (libm_alias_float_ldouble): Undefine and redefine. (libm_alias_double_ldouble): Likewise.
-rw-r--r--ChangeLog32
-rw-r--r--include/bits/mathcalls-narrow.h1
-rw-r--r--math/Makefile14
-rw-r--r--math/bits/mathcalls-narrow.h21
-rw-r--r--math/math-narrow.h146
-rw-r--r--math/math.h284
-rw-r--r--sysdeps/i386/fpu/fenv_private.h2
-rw-r--r--sysdeps/ieee754/float128/float128_private.h17
8 files changed, 516 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index ff718e7..7aeb699 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,37 @@
2018-02-09 Joseph Myers <joseph@codesourcery.com>
+ * math/bits/mathcalls-narrow.h: New file.
+ * include/bits/mathcalls-narrow.h: Likewise.
+ * math/math-narrow.h: Likewise.
+ * math/math.h (__MATHCALL_NARROW_ARGS_1): New macro.
+ (__MATHCALL_NARROW_ARGS_2): Likewise.
+ (__MATHCALL_NARROW_ARGS_3): Likewise.
+ (__MATHCALL_NARROW_NORMAL): Likewise.
+ (__MATHCALL_NARROW_REDIR): Likewise.
+ (__MATHCALL_NARROW): Likewise.
+ [__GLIBC_USE (IEC_60559_BFP_EXT)]: Repeatedly include
+ <bits/mathcalls-narrow.h> with _Mret_, _Marg_ and __MATHCALL_NAME
+ defined.
+ [__GLIBC_USE (IEC_60559_TYPES_EXT)]: Likewise.
+ * math/Makefile (headers): Add bits/mathcalls-narrow.h.
+ (libm-narrow-fns): New variable.
+ (libm-narrow-types-basic): Likewise.
+ (libm-narrow-types-ldouble-yes): Likewise.
+ (libm-narrow-types-float128-yes): Likewise.
+ (libm-narrow-types-float128-alias-yes): Likewise.
+ (libm-narrow-types): Likewise.
+ (libm-routines): Add narrowing functions.
+ * sysdeps/i386/fpu/fenv_private.h [__x86_64__]
+ (libc_feholdexcept_setroundf128): New macro.
+ [__x86_64__] (libc_feupdateenv_testf128): Likewise.
+ * sysdeps/ieee754/float128/float128_private.h: Include
+ <math/math-narrow.h>.
+ [libc_feholdexcept_setroundf128] (libc_feholdexcept_setroundl):
+ Undefine and redefine.
+ [libc_feupdateenv_testf128] (libc_feupdateenv_testl): Likewise.
+ (libm_alias_float_ldouble): Undefine and redefine.
+ (libm_alias_double_ldouble): Likewise.
+
* math/Makefile [$(PERL) != no] (libm-test-incs): Remove variable.
2018-02-09 Wilco Dijkstra <wdijkstr@arm.com>
diff --git a/include/bits/mathcalls-narrow.h b/include/bits/mathcalls-narrow.h
new file mode 100644
index 0000000..0c66ecf
--- /dev/null
+++ b/include/bits/mathcalls-narrow.h
@@ -0,0 +1 @@
+#include <math/bits/mathcalls-narrow.h>
diff --git a/math/Makefile b/math/Makefile
index 5538aa2..ee0cd6f 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -29,7 +29,7 @@ headers := math.h bits/mathcalls.h bits/mathinline.h \
bits/libm-simd-decl-stubs.h bits/iscanonical.h \
bits/flt-eval-method.h bits/fp-fast.h bits/fp-logb.h \
bits/long-double.h bits/mathcalls-helper-functions.h \
- bits/floatn.h bits/floatn-common.h
+ bits/floatn.h bits/floatn-common.h bits/mathcalls-narrow.h
# FPU support code.
aux := setfpucw fpu_control
@@ -89,6 +89,16 @@ libm-compat-calls = \
w_lgammaF_r_compat w_lgammaF_compat2 w_expF_compat \
w_lgamma_compatF k_standardF
+libm-narrow-fns =
+libm-narrow-types-basic = s_fF s_f32xFf64
+libm-narrow-types-ldouble-yes = s_fFl s_dFl
+libm-narrow-types-float128-yes = s_f32Ff128 s_f64Ff128 s_f64xFf128
+libm-narrow-types-float128-alias-yes = s_f64xFf128
+libm-narrow-types = $(libm-narrow-types-basic) \
+ $(libm-narrow-types-ldouble-$(long-double-fcts)) \
+ $(libm-narrow-types-float128-$(float128-fcts)) \
+ $(libm-narrow-types-float128-alias-$(float128-alias-fcts))
+
# Type specific routine support.
#
# The following three variables control what is included for each type:
@@ -148,6 +158,8 @@ libm-routines = $(strip $(libm-support) \
$(libm-compat-calls)) \
$(call type-foreach, $(libm-calls)) \
$(foreach t, $(types), $(type-$(t)-routines))) \
+ $(foreach f,$(libm-narrow-fns), \
+ $(subst F,$(f),$(libm-narrow-types)))
# These functions are in libc instead of libm because __printf_fp
# calls them, so any program using printf will need them linked in,
diff --git a/math/bits/mathcalls-narrow.h b/math/bits/mathcalls-narrow.h
new file mode 100644
index 0000000..0f1f051
--- /dev/null
+++ b/math/bits/mathcalls-narrow.h
@@ -0,0 +1,21 @@
+/* Declare functions returning a narrower type.
+ Copyright (C) 2018 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_H
+# error "Never include <bits/mathcalls-narrow.h> directly; include <math.h> instead."
+#endif
diff --git a/math/math-narrow.h b/math/math-narrow.h
new file mode 100644
index 0000000..1a3a5c5
--- /dev/null
+++ b/math/math-narrow.h
@@ -0,0 +1,146 @@
+/* Helper macros for functions returning a narrower type.
+ Copyright (C) 2018 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_NARROW_H
+#define _MATH_NARROW_H 1
+
+#include <bits/floatn.h>
+#include <bits/long-double.h>
+#include <errno.h>
+#include <fenv.h>
+#include <ieee754.h>
+#include <math_private.h>
+
+/* Carry out a computation using round-to-odd. The computation is
+ EXPR; the union type in which to store the result is UNION and the
+ subfield of the "ieee" field of that union with the low part of the
+ mantissa is MANTISSA; SUFFIX is the suffix for the libc_fe* macros
+ to ensure that the correct rounding mode is used, for platforms
+ with multiple rounding modes where those macros set only the
+ relevant mode. This macro does not work correctly if the sign of
+ an exact zero result depends on the rounding mode, so that case
+ must be checked for separately. */
+#define ROUND_TO_ODD(EXPR, UNION, SUFFIX, MANTISSA) \
+ ({ \
+ fenv_t env; \
+ UNION u; \
+ \
+ libc_feholdexcept_setround ## SUFFIX (&env, FE_TOWARDZERO); \
+ u.d = (EXPR); \
+ math_force_eval (u.d); \
+ u.ieee.MANTISSA \
+ |= libc_feupdateenv_test ## SUFFIX (&env, FE_INEXACT) != 0; \
+ \
+ u.d; \
+ })
+
+/* The following macros declare aliases for a narrowing function. The
+ sole argument is the base name of a family of functions, such as
+ "add". If any platform changes long double format after the
+ introduction of narrowing functions, in a way requiring symbol
+ versioning compatibility, additional variants of these macros will
+ be needed. */
+
+#define libm_alias_float_double_main(func) \
+ weak_alias (__f ## func, f ## func) \
+ weak_alias (__f ## func, f32 ## func ## f64) \
+ weak_alias (__f ## func, f32 ## func ## f32x)
+
+#ifdef NO_LONG_DOUBLE
+# define libm_alias_float_double(func) \
+ libm_alias_float_double_main (func) \
+ weak_alias (__f ## func, f ## func ## l)
+#else
+# define libm_alias_float_double(func) \
+ libm_alias_float_double_main (func)
+#endif
+
+#define libm_alias_float32x_float64_main(func) \
+ weak_alias (__f32x ## func ## f64, f32x ## func ## f64)
+
+#ifdef NO_LONG_DOUBLE
+# define libm_alias_float32x_float64(func) \
+ libm_alias_float32x_float64_main (func) \
+ weak_alias (__f32x ## func ## f64, d ## func ## l)
+#elif defined __LONG_DOUBLE_MATH_OPTIONAL
+# define libm_alias_float32x_float64(func) \
+ libm_alias_float32x_float64_main (func) \
+ weak_alias (__f32x ## func ## f64, __nldbl_d ## func ## l)
+#else
+# define libm_alias_float32x_float64(func) \
+ libm_alias_float32x_float64_main (func)
+#endif
+
+#if __HAVE_FLOAT128 && !__HAVE_DISTINCT_FLOAT128
+# define libm_alias_float_ldouble_f128(func) \
+ weak_alias (__f ## func ## l, f32 ## func ## f128)
+# define libm_alias_double_ldouble_f128(func) \
+ weak_alias (__d ## func ## l, f32x ## func ## f128) \
+ weak_alias (__d ## func ## l, f64 ## func ## f128)
+#else
+# define libm_alias_float_ldouble_f128(func)
+# define libm_alias_double_ldouble_f128(func)
+#endif
+
+#if __HAVE_FLOAT64X_LONG_DOUBLE
+# define libm_alias_float_ldouble_f64x(func) \
+ weak_alias (__f ## func ## l, f32 ## func ## f64x)
+# define libm_alias_double_ldouble_f64x(func) \
+ weak_alias (__d ## func ## l, f32x ## func ## f64x) \
+ weak_alias (__d ## func ## l, f64 ## func ## f64x)
+#else
+# define libm_alias_float_ldouble_f64x(func)
+# define libm_alias_double_ldouble_f64x(func)
+#endif
+
+#define libm_alias_float_ldouble(func) \
+ weak_alias (__f ## func ## l, f ## func ## l) \
+ libm_alias_float_ldouble_f128 (func) \
+ libm_alias_float_ldouble_f64x (func)
+
+#define libm_alias_double_ldouble(func) \
+ weak_alias (__d ## func ## l, d ## func ## l) \
+ libm_alias_double_ldouble_f128 (func) \
+ libm_alias_double_ldouble_f64x (func)
+
+#define libm_alias_float64x_float128(func) \
+ weak_alias (__f64x ## func ## f128, f64x ## func ## f128)
+
+#define libm_alias_float32_float128_main(func) \
+ weak_alias (__f32 ## func ## f128, f32 ## func ## f128)
+
+#define libm_alias_float64_float128_main(func) \
+ weak_alias (__f64 ## func ## f128, f64 ## func ## f128) \
+ weak_alias (__f64 ## func ## f128, f32x ## func ## f128)
+
+#if __HAVE_FLOAT64X_LONG_DOUBLE
+# define libm_alias_float32_float128(func) \
+ libm_alias_float32_float128_main (func)
+# define libm_alias_float64_float128(func) \
+ libm_alias_float64_float128_main (func)
+#else
+# define libm_alias_float32_float128(func) \
+ libm_alias_float32_float128_main (func) \
+ weak_alias (__f32 ## func ## f128, f32 ## func ## f64x)
+# define libm_alias_float64_float128(func) \
+ libm_alias_float64_float128_main (func) \
+ weak_alias (__f64 ## func ## f128, f64 ## func ## f64x) \
+ weak_alias (__f64 ## func ## f128, f32x ## func ## f64x)
+#endif
+
+#endif /* math-narrow.h. */
diff --git a/math/math.h b/math/math.h
index 3c515f8..2e26968 100644
--- a/math/math.h
+++ b/math/math.h
@@ -483,6 +483,290 @@ extern long double __REDIRECT_NTH (nexttowardl,
#undef __MATHDECL
#undef __MATHCALL
+/* Declare functions returning a narrower type. */
+#define __MATHCALL_NARROW_ARGS_1 (_Marg_ __x)
+#define __MATHCALL_NARROW_ARGS_2 (_Marg_ __x, _Marg_ __y)
+#define __MATHCALL_NARROW_ARGS_3 (_Marg_ __x, _Marg_ __y, _Marg_ __z)
+#define __MATHCALL_NARROW_NORMAL(func, nargs) \
+ extern _Mret_ func __MATHCALL_NARROW_ARGS_ ## nargs __THROW
+#define __MATHCALL_NARROW_REDIR(func, redir, nargs) \
+ extern _Mret_ __REDIRECT_NTH (func, __MATHCALL_NARROW_ARGS_ ## nargs, \
+ redir)
+#define __MATHCALL_NARROW(func, redir, nargs) \
+ __MATHCALL_NARROW_NORMAL (func, nargs)
+
+#if __GLIBC_USE (IEC_60559_BFP_EXT)
+
+# define _Mret_ float
+# define _Marg_ double
+# define __MATHCALL_NAME(name) f ## name
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+
+# define _Mret_ float
+# define _Marg_ long double
+# define __MATHCALL_NAME(name) f ## name ## l
+# ifdef __LDBL_COMPAT
+# define __MATHCALL_REDIR_NAME(name) f ## name
+# undef __MATHCALL_NARROW
+# define __MATHCALL_NARROW(func, redir, nargs) \
+ __MATHCALL_NARROW_REDIR (func, redir, nargs)
+# endif
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# ifdef __LDBL_COMPAT
+# undef __MATHCALL_REDIR_NAME
+# undef __MATHCALL_NARROW
+# define __MATHCALL_NARROW(func, redir, nargs) \
+ __MATHCALL_NARROW_NORMAL (func, nargs)
+# endif
+
+# define _Mret_ double
+# define _Marg_ long double
+# define __MATHCALL_NAME(name) d ## name ## l
+# ifdef __LDBL_COMPAT
+# define __MATHCALL_REDIR_NAME(name) __nldbl_d ## name ## l
+# undef __MATHCALL_NARROW
+# define __MATHCALL_NARROW(func, redir, nargs) \
+ __MATHCALL_NARROW_REDIR (func, redir, nargs)
+# endif
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# ifdef __LDBL_COMPAT
+# undef __MATHCALL_REDIR_NAME
+# undef __MATHCALL_NARROW
+# define __MATHCALL_NARROW(func, redir, nargs) \
+ __MATHCALL_NARROW_NORMAL (func, nargs)
+# endif
+
+#endif
+
+#if __GLIBC_USE (IEC_60559_TYPES_EXT)
+
+# if __HAVE_FLOAT16 && __HAVE_FLOAT32
+# define _Mret_ _Float16
+# define _Marg_ _Float32
+# define __MATHCALL_NAME(name) f16 ## name ## f32
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT16 && __HAVE_FLOAT32X
+# define _Mret_ _Float16
+# define _Marg_ _Float32x
+# define __MATHCALL_NAME(name) f16 ## name ## f32x
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT16 && __HAVE_FLOAT64
+# define _Mret_ _Float16
+# define _Marg_ _Float64
+# define __MATHCALL_NAME(name) f16 ## name ## f64
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT16 && __HAVE_FLOAT64X
+# define _Mret_ _Float16
+# define _Marg_ _Float64x
+# define __MATHCALL_NAME(name) f16 ## name ## f64x
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT16 && __HAVE_FLOAT128
+# define _Mret_ _Float16
+# define _Marg_ _Float128
+# define __MATHCALL_NAME(name) f16 ## name ## f128
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT16 && __HAVE_FLOAT128X
+# define _Mret_ _Float16
+# define _Marg_ _Float128x
+# define __MATHCALL_NAME(name) f16 ## name ## f128x
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT32 && __HAVE_FLOAT32X
+# define _Mret_ _Float32
+# define _Marg_ _Float32x
+# define __MATHCALL_NAME(name) f32 ## name ## f32x
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT32 && __HAVE_FLOAT64
+# define _Mret_ _Float32
+# define _Marg_ _Float64
+# define __MATHCALL_NAME(name) f32 ## name ## f64
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT32 && __HAVE_FLOAT64X
+# define _Mret_ _Float32
+# define _Marg_ _Float64x
+# define __MATHCALL_NAME(name) f32 ## name ## f64x
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT32 && __HAVE_FLOAT128
+# define _Mret_ _Float32
+# define _Marg_ _Float128
+# define __MATHCALL_NAME(name) f32 ## name ## f128
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT32 && __HAVE_FLOAT128X
+# define _Mret_ _Float32
+# define _Marg_ _Float128x
+# define __MATHCALL_NAME(name) f32 ## name ## f128x
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT32X && __HAVE_FLOAT64
+# define _Mret_ _Float32x
+# define _Marg_ _Float64
+# define __MATHCALL_NAME(name) f32x ## name ## f64
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT32X && __HAVE_FLOAT64X
+# define _Mret_ _Float32x
+# define _Marg_ _Float64x
+# define __MATHCALL_NAME(name) f32x ## name ## f64x
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT32X && __HAVE_FLOAT128
+# define _Mret_ _Float32x
+# define _Marg_ _Float128
+# define __MATHCALL_NAME(name) f32x ## name ## f128
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT32X && __HAVE_FLOAT128X
+# define _Mret_ _Float32x
+# define _Marg_ _Float128x
+# define __MATHCALL_NAME(name) f32x ## name ## f128x
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT64 && __HAVE_FLOAT64X
+# define _Mret_ _Float64
+# define _Marg_ _Float64x
+# define __MATHCALL_NAME(name) f64 ## name ## f64x
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT64 && __HAVE_FLOAT128
+# define _Mret_ _Float64
+# define _Marg_ _Float128
+# define __MATHCALL_NAME(name) f64 ## name ## f128
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT64 && __HAVE_FLOAT128X
+# define _Mret_ _Float64
+# define _Marg_ _Float128x
+# define __MATHCALL_NAME(name) f64 ## name ## f128x
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT64X && __HAVE_FLOAT128
+# define _Mret_ _Float64x
+# define _Marg_ _Float128
+# define __MATHCALL_NAME(name) f64x ## name ## f128
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT64X && __HAVE_FLOAT128X
+# define _Mret_ _Float64x
+# define _Marg_ _Float128x
+# define __MATHCALL_NAME(name) f64x ## name ## f128x
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+# if __HAVE_FLOAT128 && __HAVE_FLOAT128X
+# define _Mret_ _Float128
+# define _Marg_ _Float128x
+# define __MATHCALL_NAME(name) f128 ## name ## f128x
+# include <bits/mathcalls-narrow.h>
+# undef _Mret_
+# undef _Marg_
+# undef __MATHCALL_NAME
+# endif
+
+#endif
+
+#undef __MATHCALL_NARROW_ARGS_1
+#undef __MATHCALL_NARROW_ARGS_2
+#undef __MATHCALL_NARROW_ARGS_3
+#undef __MATHCALL_NARROW_NORMAL
+#undef __MATHCALL_NARROW_REDIR
+#undef __MATHCALL_NARROW
#if defined __USE_MISC || defined __USE_XOPEN
/* This variable is used by `gamma' and `lgamma'. */
diff --git a/sysdeps/i386/fpu/fenv_private.h b/sysdeps/i386/fpu/fenv_private.h
index 38fd0b9..a258f48 100644
--- a/sysdeps/i386/fpu/fenv_private.h
+++ b/sysdeps/i386/fpu/fenv_private.h
@@ -337,6 +337,8 @@ libc_feresetround_387 (fenv_t *e)
x86_64, so that must be set for float128 computations. */
# define SET_RESTORE_ROUNDF128(RM) \
SET_RESTORE_ROUND_GENERIC (RM, libc_feholdsetround_sse, libc_feresetround_sse)
+# define libc_feholdexcept_setroundf128 libc_feholdexcept_setround_sse
+# define libc_feupdateenv_testf128 libc_feupdateenv_test_sse
#endif
/* We have support for rounding mode context. */
diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
index c9d9924..d0d41c3 100644
--- a/sysdeps/ieee754/float128/float128_private.h
+++ b/sysdeps/ieee754/float128/float128_private.h
@@ -54,6 +54,16 @@
# define SET_RESTORE_ROUNDL(RM) SET_RESTORE_ROUNDF128 (RM)
#endif
+#ifdef libc_feholdexcept_setroundf128
+# undef libc_feholdexcept_setroundl
+# define libc_feholdexcept_setroundl(ENV, RM) \
+ libc_feholdexcept_setroundf128 (ENV, RM)
+#endif
+
+#ifdef libc_feupdateenv_testf128
+# undef libc_feupdateenv_testl
+# define libc_feupdateenv_testl(ENV, EX) libc_feupdateenv_testf128 (ENV, EX)
+#endif
/* misc macros from the header below. */
#include <fix-fp-int-convert-overflow.h>
@@ -122,6 +132,13 @@
#define libm_alias_ldouble_r(from, to, r) libm_alias_float128_r (from, to, r)
+#include <math/math-narrow.h>
+#undef libm_alias_float_ldouble
+#define libm_alias_float_ldouble(func) libm_alias_float32_float128 (func)
+#undef libm_alias_double_ldouble
+#define libm_alias_double_ldouble(func) libm_alias_float64_float128 (func)
+
+
/* IEEE function renames. */
#define __ieee754_acoshl __ieee754_acoshf128
#define __ieee754_acosl __ieee754_acosf128