diff options
| author | Joseph Myers <josmyers@redhat.com> | 2025-03-27 10:44:44 +0000 |
|---|---|---|
| committer | Joseph Myers <josmyers@redhat.com> | 2025-03-27 10:44:44 +0000 |
| commit | 75ad83f564b822de0f1f5fb6ed29f105373d3c49 (patch) | |
| tree | 8da7ed5af54d8d514ca355cf37ac6958d1424e68 /sysdeps | |
| parent | be61b9493d38032519e596f282f9695667402c8d (diff) | |
| download | glibc-75ad83f564b822de0f1f5fb6ed29f105373d3c49.tar.xz glibc-75ad83f564b822de0f1f5fb6ed29f105373d3c49.zip | |
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')
41 files changed, 256 insertions, 4 deletions
diff --git a/sysdeps/generic/math-type-macros-double.h b/sysdeps/generic/math-type-macros-double.h index 1e84d3ff57..f03aea116b 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 4aac524a2f..445535ae71 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 ad2310b995..f64c1d38ea 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 931d5ecd35..00309cb9be 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 e3224a060a..21c5fee02f 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 diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Versions b/sysdeps/ieee754/ldbl-128ibm-compat/Versions index b93723ef75..cd39b6a756 100644 --- a/sysdeps/ieee754/ldbl-128ibm-compat/Versions +++ b/sysdeps/ieee754/ldbl-128ibm-compat/Versions @@ -154,6 +154,7 @@ libm { __tanpiieee128; } GLIBC_2.42 { + __pownieee128; __powrieee128; __rsqrtieee128; } diff --git a/sysdeps/ieee754/ldbl-opt/Makefile b/sysdeps/ieee754/ldbl-opt/Makefile index 67fd5a0ddc..beaed6133a 100644 --- a/sysdeps/ieee754/ldbl-opt/Makefile +++ b/sysdeps/ieee754/ldbl-opt/Makefile @@ -166,6 +166,7 @@ libnldbl-calls = \ obstack_vprintf \ obstack_vprintf_chk \ pow \ + pown \ powr \ printf \ printf_chk \ @@ -376,6 +377,7 @@ CFLAGS-nldbl-nexttoward.c = -fno-builtin-nexttoward -fno-builtin-nexttowardl CFLAGS-nldbl-nexttowardf.c = -fno-builtin-nexttowardf CFLAGS-nldbl-nextup.c = -fno-builtin-nextupl CFLAGS-nldbl-pow.c = -fno-builtin-powl +CFLAGS-nldbl-pown.c = -fno-builtin-pownl CFLAGS-nldbl-powr.c = -fno-builtin-powrl CFLAGS-nldbl-remainder.c = -fno-builtin-remainderl -fno-builtin-dreml CFLAGS-nldbl-remquo.c = -fno-builtin-remquol diff --git a/sysdeps/ieee754/ldbl-opt/nldbl-pown.c b/sysdeps/ieee754/ldbl-opt/nldbl-pown.c new file mode 100644 index 0000000000..7f7e02bfef --- /dev/null +++ b/sysdeps/ieee754/ldbl-opt/nldbl-pown.c @@ -0,0 +1,8 @@ +#include "nldbl-compat.h" + +double +attribute_hidden +pownl (double x, long long int y) +{ + return pown (x, y); +} diff --git a/sysdeps/loongarch/math_private.h b/sysdeps/loongarch/fenv_private.h index f15eb60acd..7614e7c6e1 100644 --- a/sysdeps/loongarch/math_private.h +++ b/sysdeps/loongarch/fenv_private.h @@ -16,11 +16,11 @@ License along with the GNU C Library; if not, see <https://www.gnu.org/licenses/>. */ -#ifndef LOONGARCH_MATH_PRIVATE_H -#define LOONGARCH_MATH_PRIVATE_H 1 +#ifndef LOONGARCH_FENV_PRIVATE_H +#define LOONGARCH_FENV_PRIVATE_H 1 /* Inline functions to speed up the math library implementation. The - default versions of these routines are in generic/math_private.h + default versions of these routines are in generic/fenv_private.h and call fesetround, feholdexcept, etc. These routines use inlined code instead. */ @@ -243,6 +243,6 @@ libc_feholdsetround_loongarch_ctx (struct rm_ctx *ctx, int round) #endif -#include_next <math_private.h> +#include_next <fenv_private.h> #endif diff --git a/sysdeps/mach/hurd/i386/libm.abilist b/sysdeps/mach/hurd/i386/libm.abilist index 436ce76f77..8d76dd84f4 100644 --- a/sysdeps/mach/hurd/i386/libm.abilist +++ b/sysdeps/mach/hurd/i386/libm.abilist @@ -1277,6 +1277,14 @@ GLIBC_2.41 tanpif32x F GLIBC_2.41 tanpif64 F GLIBC_2.41 tanpif64x F GLIBC_2.41 tanpil F +GLIBC_2.42 pown F +GLIBC_2.42 pownf F +GLIBC_2.42 pownf128 F +GLIBC_2.42 pownf32 F +GLIBC_2.42 pownf32x F +GLIBC_2.42 pownf64 F +GLIBC_2.42 pownf64x F +GLIBC_2.42 pownl F GLIBC_2.42 powr F GLIBC_2.42 powrf F GLIBC_2.42 powrf128 F diff --git a/sysdeps/mach/hurd/x86_64/libm.abilist b/sysdeps/mach/hurd/x86_64/libm.abilist index 14fe8361c7..12ae364926 100644 --- a/sysdeps/mach/hurd/x86_64/libm.abilist +++ b/sysdeps/mach/hurd/x86_64/libm.abilist @@ -1134,6 +1134,14 @@ GLIBC_2.41 tanpif32x F GLIBC_2.41 tanpif64 F GLIBC_2.41 tanpif64x F GLIBC_2.41 tanpil F +GLIBC_2.42 pown F +GLIBC_2.42 pownf F +GLIBC_2.42 pownf128 F +GLIBC_2.42 pownf32 F +GLIBC_2.42 pownf32x F +GLIBC_2.42 pownf64 F +GLIBC_2.42 pownf64x F +GLIBC_2.42 pownl F GLIBC_2.42 powr F GLIBC_2.42 powrf F GLIBC_2.42 powrf128 F diff --git a/sysdeps/unix/sysv/linux/aarch64/libm.abilist b/sysdeps/unix/sysv/linux/aarch64/libm.abilist index 75ae1682f6..4fdeb0d13d 100644 --- a/sysdeps/unix/sysv/linux/aarch64/libm.abilist +++ b/sysdeps/unix/sysv/linux/aarch64/libm.abilist @@ -1245,6 +1245,14 @@ GLIBC_2.41 tanpif32x F GLIBC_2.41 tanpif64 F GLIBC_2.41 tanpif64x F GLIBC_2.41 tanpil F +GLIBC_2.42 pown F +GLIBC_2.42 pownf F +GLIBC_2.42 pownf128 F +GLIBC_2.42 pownf32 F +GLIBC_2.42 pownf32x F +GLIBC_2.42 pownf64 F +GLIBC_2.42 pownf64x F +GLIBC_2.42 pownl F GLIBC_2.42 powr F GLIBC_2.42 powrf F GLIBC_2.42 powrf128 F diff --git a/sysdeps/unix/sysv/linux/alpha/libm.abilist b/sysdeps/unix/sysv/linux/alpha/libm.abilist index 98406fa8d6..06cec45c17 100644 --- a/sysdeps/unix/sysv/linux/alpha/libm.abilist +++ b/sysdeps/unix/sysv/linux/alpha/libm.abilist @@ -1404,6 +1404,14 @@ GLIBC_2.41 tanpif32x F GLIBC_2.41 tanpif64 F GLIBC_2.41 tanpif64x F GLIBC_2.41 tanpil F +GLIBC_2.42 pown F +GLIBC_2.42 pownf F +GLIBC_2.42 pownf128 F +GLIBC_2.42 pownf32 F +GLIBC_2.42 pownf32x F +GLIBC_2.42 pownf64 F +GLIBC_2.42 pownf64x F +GLIBC_2.42 pownl F GLIBC_2.42 powr F GLIBC_2.42 powrf F GLIBC_2.42 powrf128 F diff --git a/sysdeps/unix/sysv/linux/arc/libm.abilist b/sysdeps/unix/sysv/linux/arc/libm.abilist index 5dc92d8890..ab3f09cf46 100644 --- a/sysdeps/unix/sysv/linux/arc/libm.abilist +++ b/sysdeps/unix/sysv/linux/arc/libm.abilist @@ -829,6 +829,12 @@ GLIBC_2.41 tanpif32 F GLIBC_2.41 tanpif32x F GLIBC_2.41 tanpif64 F GLIBC_2.41 tanpil F +GLIBC_2.42 pown F +GLIBC_2.42 pownf F +GLIBC_2.42 pownf32 F +GLIBC_2.42 pownf32x F +GLIBC_2.42 pownf64 F +GLIBC_2.42 pownl F GLIBC_2.42 powr F GLIBC_2.42 powrf F GLIBC_2.42 powrf32 F diff --git a/sysdeps/unix/sysv/linux/arm/be/libm.abilist b/sysdeps/unix/sysv/linux/arm/be/libm.abilist index 9f5659220d..efa90f9f75 100644 --- a/sysdeps/unix/sysv/linux/arm/be/libm.abilist +++ b/sysdeps/unix/sysv/linux/arm/be/libm.abilist @@ -920,6 +920,12 @@ GLIBC_2.41 tanpif32 F GLIBC_2.41 tanpif32x F GLIBC_2.41 tanpif64 F GLIBC_2.41 tanpil F +GLIBC_2.42 pown F +GLIBC_2.42 pownf F +GLIBC_2.42 pownf32 F +GLIBC_2.42 pownf32x F +GLIBC_2.42 pownf64 F +GLIBC_2.42 pownl F GLIBC_2.42 powr F GLIBC_2.42 powrf F GLIBC_2.42 powrf32 F diff --git a/sysdeps/unix/sysv/linux/arm/le/libm.abilist b/sysdeps/unix/sysv/linux/arm/le/libm.abilist index 9f5659220d..efa90f9f75 100644 --- a/sysdeps/unix/sysv/linux/arm/le/libm.abilist +++ b/sysdeps/unix/sysv/linux/arm/le/libm.abilist @@ -920,6 +920,12 @@ GLIBC_2.41 tanpif32 F GLIBC_2.41 tanpif32x F GLIBC_2.41 tanpif64 F GLIBC_2.41 tanpil F +GLIBC_2.42 pown F +GLIBC_2.42 pownf F +GLIBC_2.42 pownf32 F +GLIBC_2.42 pownf32x F +GLIBC_2.42 pownf64 F +GLIBC_2.42 pownl F GLIBC_2.42 powr F GLIBC_2.42 powrf F GLIBC_2.42 powrf32 F diff --git a/sysdeps/unix/sysv/linux/csky/libm.abilist b/sysdeps/unix/sysv/linux/csky/libm.abilist index ed35c4186e..8ae4be4e90 100644 --- a/sysdeps/unix/sysv/linux/csky/libm.abilist +++ b/sysdeps/unix/sysv/linux/csky/libm.abilist @@ -895,6 +895,12 @@ GLIBC_2.41 tanpif32 F GLIBC_2.41 tanpif32x F GLIBC_2.41 tanpif64 F GLIBC_2.41 tanpil F +GLIBC_2.42 pown F +GLIBC_2.42 pownf F +GLIBC_2.42 pownf32 F +GLIBC_2.42 pownf32x F +GLIBC_2.42 pownf64 F +GLIBC_2.42 pownl F GLIBC_2.42 powr F GLIBC_2.42 powrf F GLIBC_2.42 powrf32 F |
