diff options
author | Joseph Myers <josmyers@redhat.com> | 2024-06-17 13:47:09 +0000 |
---|---|---|
committer | Joseph Myers <josmyers@redhat.com> | 2024-06-17 13:47:09 +0000 |
commit | bb014f50c4a0c8d8db1ba5af55c104e430b5533d (patch) | |
tree | a1ca91748bb999691442701c3b786ebc3372114f /math | |
parent | ca38eff28015f376c020b4dfad5351e45be8d090 (diff) | |
download | glibc-bb014f50c4a0c8d8db1ba5af55c104e430b5533d.zip glibc-bb014f50c4a0c8d8db1ba5af55c104e430b5533d.tar.gz glibc-bb014f50c4a0c8d8db1ba5af55c104e430b5533d.tar.bz2 |
Implement C23 logp1
C23 adds various <math.h> function families originally defined in TS
18661-4. Add the logp1 functions (aliases for log1p functions - the
name is intended to be more consistent with the new log2p1 and
log10p1, where clearly it would have been very confusing to name those
functions log21p and log101p). As aliases rather than new functions,
the content of this patch is somewhat different from those actually
adding new functions.
Tests are shared with log1p, so this patch *does* mechanically update
all affected libm-test-ulps files to expect the same errors for both
functions.
The vector versions of log1p on aarch64 and x86_64 are *not* updated
to have logp1 aliases (and thus there are no corresponding header,
tests, abilist or ulps changes for vector functions either). It would
be reasonable for such vector aliases and corresponding changes to
other files to be made separately. For now, the log1p tests instead
avoid testing logp1 in the vector case (a Makefile change is needed to
avoid problems with grep, used in generating the .c files for vector
function tests, matching more than one ALL_RM_TEST line in a file
testing multiple functions with the same inputs, when it assumes that
the .inc file only has a single such line).
Tested for x86_64 and x86, and with build-many-glibcs.py.
Diffstat (limited to 'math')
-rw-r--r-- | math/Makefile | 9 | ||||
-rw-r--r-- | math/Versions | 2 | ||||
-rw-r--r-- | math/bits/mathcalls.h | 3 | ||||
-rwxr-xr-x | math/gen-tgmath-tests.py | 1 | ||||
-rw-r--r-- | math/libm-test-log1p.inc | 12 | ||||
-rw-r--r-- | math/test-tgmath.c | 12 | ||||
-rw-r--r-- | math/tgmath.h | 3 | ||||
-rw-r--r-- | math/w_log1p_template.c | 2 |
8 files changed, 39 insertions, 5 deletions
diff --git a/math/Makefile b/math/Makefile index 58e5c07..c55976c 100644 --- a/math/Makefile +++ b/math/Makefile @@ -966,6 +966,7 @@ tgmath3-macros = \ log2 \ log2p1 \ logb \ + logp1 \ lrint \ lround \ nearbyint \ @@ -1145,7 +1146,7 @@ $(foreach t,$(libm-tests-vector),$(objpfx)$(t).c): $(objpfx)test-%.c: type_func=$*; \ type=$${type_func%-*}; \ func=$${type_func##*-}; \ - func_args=$$(grep ALL_RM_TEST libm-test-$$func.inc \ + func_args=$$(grep "ALL_RM_TEST ($$func," libm-test-$$func.inc \ | sed 's/.*RUN_TEST_LOOP_//;s/_.*//'); \ ( \ echo "#include <test-$$type.h>"; \ @@ -1375,7 +1376,7 @@ CFLAGS-s_llrint.c += -fno-builtin-llrintl CFLAGS-s_llround.c += -fno-builtin-llroundl CFLAGS-e_log.c += -fno-builtin-logl CFLAGS-w_log10.c += -fno-builtin-log10l -CFLAGS-w_log1p.c += -fno-builtin-log1pl +CFLAGS-w_log1p.c += -fno-builtin-log1pl -fno-builtin-logp1l CFLAGS-e_log2.c += -fno-builtin-log2l CFLAGS-s_log2p1.c += -fno-builtin-log2p1l CFLAGS-s_logb.c += -fno-builtin-logbl @@ -1501,7 +1502,7 @@ CFLAGS-s_llrint.c += -fno-builtin-llrintf32x -fno-builtin-llrintf64 CFLAGS-s_llround.c += -fno-builtin-llroundf32x -fno-builtin-llroundf64 CFLAGS-e_log.c += -fno-builtin-logf32x -fno-builtin-logf64 CFLAGS-w_log10.c += -fno-builtin-log10f32x -fno-builtin-log10f64 -CFLAGS-w_log1p.c += -fno-builtin-log1pf32x -fno-builtin-log1pf64 +CFLAGS-w_log1p.c += -fno-builtin-log1pf32x -fno-builtin-log1pf64 -fno-builtin-logp1f32x -fno-builtin-logp1f64 CFLAGS-e_log2.c += -fno-builtin-log2f32x -fno-builtin-log2f64 CFLAGS-s_log2p1.c += -fno-builtin-log2p1f32x -fno-builtin-log2p1f64 CFLAGS-s_logb.c += -fno-builtin-logbf32x -fno-builtin-logbf64 @@ -1616,7 +1617,7 @@ CFLAGS-s_llrintf.c += -fno-builtin-llrintf32 CFLAGS-s_llroundf.c += -fno-builtin-llroundf32 CFLAGS-e_logf.c += -fno-builtin-logf32 CFLAGS-w_log10f.c += -fno-builtin-log10f32 -CFLAGS-w_log1pf.c += -fno-builtin-log1pf32 +CFLAGS-w_log1pf.c += -fno-builtin-log1pf32 -fno-builtin-logp1f32 CFLAGS-e_log2f.c += -fno-builtin-log2f32 CFLAGS-s_log2p1f.c += -fno-builtin-log2p1f32 CFLAGS-s_logbf.c += -fno-builtin-logbf32 diff --git a/math/Versions b/math/Versions index 46b9b87..f6ddd2f 100644 --- a/math/Versions +++ b/math/Versions @@ -642,7 +642,9 @@ libm { GLIBC_2.40 { # Functions not involving _Float64x or _Float128, for all configurations. log2p1; log2p1f; log2p1l; log2p1f32; log2p1f64; log2p1f32x; + logp1; logp1f; logp1l; logp1f32; logp1f64; logp1f32x; # Functions involving _Float64x or _Float128, for some configurations. log2p1f64x; log2p1f128; + logp1f64x; logp1f128; } } diff --git a/math/bits/mathcalls.h b/math/bits/mathcalls.h index fbfc27a..40f9cf3 100644 --- a/math/bits/mathcalls.h +++ b/math/bits/mathcalls.h @@ -115,6 +115,9 @@ __MATHCALL_VEC (exp10,, (_Mdouble_ __x)); /* Return log2(1 + X). */ __MATHCALL (log2p1,, (_Mdouble_ __x)); + +/* Return log(1 + X). */ +__MATHCALL (logp1,, (_Mdouble_ __x)); #endif #if defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99 diff --git a/math/gen-tgmath-tests.py b/math/gen-tgmath-tests.py index 1131481..307b657 100755 --- a/math/gen-tgmath-tests.py +++ b/math/gen-tgmath-tests.py @@ -744,6 +744,7 @@ class Tests(object): # TS 18661-4 functions. self.add_tests('exp10', 'r', ['r']) self.add_tests('log2p1', 'r', ['r']) + self.add_tests('logp1', 'r', ['r']) # C23 functions. self.add_tests('fmaximum', 'r', ['r', 'r']) self.add_tests('fmaximum_mag', 'r', ['r', 'r']) diff --git a/math/libm-test-log1p.inc b/math/libm-test-log1p.inc index 67ad03f..bcac6ff 100644 --- a/math/libm-test-log1p.inc +++ b/math/libm-test-log1p.inc @@ -40,10 +40,22 @@ log1p_test (void) ALL_RM_TEST (log1p, 0, log1p_test_data, RUN_TEST_LOOP_f_f, END); } +#if !TEST_MATHVEC +static void +logp1_test (void) +{ + /* logp1 uses the same test data as log1p. */ + ALL_RM_TEST (logp1, 0, log1p_test_data, RUN_TEST_LOOP_f_f, END); +} +#endif + static void do_test (void) { log1p_test (); +#if !TEST_MATHVEC + logp1_test (); +#endif } /* diff --git a/math/test-tgmath.c b/math/test-tgmath.c index 141e96b..290e9cb 100644 --- a/math/test-tgmath.c +++ b/math/test-tgmath.c @@ -48,7 +48,7 @@ volatile int count_cdouble; volatile int count_cfloat; volatile int count_cldouble; -#define NCALLS 160 +#define NCALLS 162 #define NCALLS_INT 4 #define NCCALLS 47 @@ -256,6 +256,7 @@ F(compile_test) (void) a = exp10 (exp10 (x)); b = log2 (log2 (a)); a = log2p1 (log2p1 (x)); + a = logp1 (logp1 (x)); a = pow (pow (x, a), pow (c, b)); b = sqrt (sqrt (a)); a = hypot (hypot (x, b), hypot (c, a)); @@ -370,6 +371,7 @@ F(compile_test) (void) a = exp10 (y); a = log2 (y); a = log2p1 (y); + a = logp1 (y); a = pow (y, y); a = sqrt (y); a = hypot (y, y); @@ -652,6 +654,14 @@ TYPE } TYPE +(F(logp1)) (TYPE x) +{ + ++count; + P (); + return x; +} + +TYPE (F(pow)) (TYPE x, TYPE y) { ++count; diff --git a/math/tgmath.h b/math/tgmath.h index d9ee3e3..78fd2f5 100644 --- a/math/tgmath.h +++ b/math/tgmath.h @@ -877,6 +877,9 @@ /* Return log2(1 + X). */ #define log2p1(Val) __TGMATH_UNARY_REAL_ONLY (Val, log2p1) + +/* Return log(1 + X). */ +#define logp1(Val) __TGMATH_UNARY_REAL_ONLY (Val, logp1) #endif diff --git a/math/w_log1p_template.c b/math/w_log1p_template.c index bfdedb0..100f2cd 100644 --- a/math/w_log1p_template.c +++ b/math/w_log1p_template.c @@ -33,3 +33,5 @@ M_DECL_FUNC (__w_log1p) (FLOAT x) return M_SUF (__log1p) (x); } declare_mgen_alias (__w_log1p, log1p) +strong_alias (M_SUF (__w_log1p), M_SUF (__w_logp1)) +declare_mgen_alias (__w_logp1, logp1) |