aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/generic
diff options
context:
space:
mode:
authorJoseph Myers <josmyers@redhat.com>2025-03-27 10:44:44 +0000
committerJoseph Myers <josmyers@redhat.com>2025-03-27 10:44:44 +0000
commit75ad83f564b822de0f1f5fb6ed29f105373d3c49 (patch)
tree8da7ed5af54d8d514ca355cf37ac6958d1424e68 /sysdeps/generic
parentbe61b9493d38032519e596f282f9695667402c8d (diff)
downloadglibc-75ad83f564b822de0f1f5fb6ed29f105373d3c49.zip
glibc-75ad83f564b822de0f1f5fb6ed29f105373d3c49.tar.gz
glibc-75ad83f564b822de0f1f5fb6ed29f105373d3c49.tar.bz2
Implement C23 pown
C23 adds various <math.h> function families originally defined in TS 18661-4. Add the pown functions, which are like pow but with an integer exponent. That exponent has type long long int in C23; it was intmax_t in TS 18661-4, and as with other interfaces changed after their initial appearance in the TS, I don't think we need to support the original version of the interface. The test inputs are based on the subset of test inputs for pow that use integer exponents that fit in long long. As the first such template implementation that saves and restores the rounding mode internally (to avoid possible issues with directed rounding and intermediate overflows or underflows in the wrong rounding mode), support also needed to be added for using SET_RESTORE_ROUND* in such template function implementations. This required math-type-macros-float128.h to include <fenv_private.h>, so it can tell whether SET_RESTORE_ROUNDF128 is defined. In turn, the include order with <fenv_private.h> included before <math_private.h> broke loongarch builds, showing up that sysdeps/loongarch/math_private.h is really a fenv_private.h file (maybe implemented internally before the consistent split of those headers in 2018?) and needed to be renamed to fenv_private.h to avoid errors with duplicate macro definitions if <math_private.h> is included after <fenv_private.h>. The underlying implementation uses __ieee754_pow functions (called more than once in some cases, where the exponent does not fit in the floating type). I expect a custom implementation for a given format, that only handles integer exponents but handles larger exponents directly, could be faster and more accurate in some cases. I encourage searching for worst cases for ulps error for these implementations (necessarily non-exhaustively, given the size of the input space). Tested for x86_64 and x86, and with build-many-glibcs.py.
Diffstat (limited to 'sysdeps/generic')
-rw-r--r--sysdeps/generic/math-type-macros-double.h2
-rw-r--r--sysdeps/generic/math-type-macros-float.h2
-rw-r--r--sysdeps/generic/math-type-macros-float128.h9
-rw-r--r--sysdeps/generic/math-type-macros-ldouble.h2
-rw-r--r--sysdeps/generic/math-type-macros.h1
5 files changed, 16 insertions, 0 deletions
diff --git a/sysdeps/generic/math-type-macros-double.h b/sysdeps/generic/math-type-macros-double.h
index 1e84d3f..f03aea1 100644
--- a/sysdeps/generic/math-type-macros-double.h
+++ b/sysdeps/generic/math-type-macros-double.h
@@ -28,6 +28,8 @@
#define M_STRTO_NAN __strtod_nan
#define M_USE_BUILTIN(c) USE_ ##c ##_BUILTIN
+#define M_SET_RESTORE_ROUND(RM) SET_RESTORE_ROUND (RM)
+
#include <libm-alias-double.h>
#include <math-nan-payload-double.h>
diff --git a/sysdeps/generic/math-type-macros-float.h b/sysdeps/generic/math-type-macros-float.h
index 4aac524..445535a 100644
--- a/sysdeps/generic/math-type-macros-float.h
+++ b/sysdeps/generic/math-type-macros-float.h
@@ -30,6 +30,8 @@
/* GNU extension float constant macros. */
#define M_MLIT(c) c ## f
+#define M_SET_RESTORE_ROUND(RM) SET_RESTORE_ROUNDF (RM)
+
#include <libm-alias-float.h>
#include <math-nan-payload-float.h>
diff --git a/sysdeps/generic/math-type-macros-float128.h b/sysdeps/generic/math-type-macros-float128.h
index ad2310b..f64c1d3 100644
--- a/sysdeps/generic/math-type-macros-float128.h
+++ b/sysdeps/generic/math-type-macros-float128.h
@@ -19,6 +19,8 @@
#ifndef _MATH_TYPE_MACROS_FLOAT128
#define _MATH_TYPE_MACROS_FLOAT128
+#include <fenv_private.h>
+
#define M_LIT(c) __f128 (c)
#define M_PFX FLT128
#define M_SUF(c) c ## f128
@@ -30,6 +32,13 @@
#define M_MLIT(c) c ## f128
+/* fenv_private.h may not define SET_RESTORE_ROUNDF128. */
+#ifdef SET_RESTORE_ROUNDF128
+# define M_SET_RESTORE_ROUND(RM) SET_RESTORE_ROUNDF128 (RM)
+#else
+# define M_SET_RESTORE_ROUND(RM) SET_RESTORE_ROUNDL (RM)
+#endif
+
#include <libm-alias-float128.h>
#include <math-nan-payload-float128.h>
diff --git a/sysdeps/generic/math-type-macros-ldouble.h b/sysdeps/generic/math-type-macros-ldouble.h
index 931d5ec..00309cb 100644
--- a/sysdeps/generic/math-type-macros-ldouble.h
+++ b/sysdeps/generic/math-type-macros-ldouble.h
@@ -28,6 +28,8 @@
#define M_STRTO_NAN __strtold_nan
#define M_USE_BUILTIN(c) USE_ ##c ##L_BUILTIN
+#define M_SET_RESTORE_ROUND(RM) SET_RESTORE_ROUNDL (RM)
+
#include <libm-alias-ldouble.h>
#include <math-nan-payload-ldouble.h>
diff --git a/sysdeps/generic/math-type-macros.h b/sysdeps/generic/math-type-macros.h
index e3224a0..21c5fee 100644
--- a/sysdeps/generic/math-type-macros.h
+++ b/sysdeps/generic/math-type-macros.h
@@ -33,6 +33,7 @@
M_STRTO_NAN - Resolves to the internal libc function which
converts a string into the appropriate FLOAT nan
value.
+ M_SET_RESTORE_ROUND - Resolves to a SET_RESTORE_ROUND call for M_TYPE.
declare_mgen_alias(from,to)
This exposes the appropriate symbol(s) for a