Module Name: src Committed By: martin Date: Fri Oct 11 19:01:12 UTC 2024
Modified Files: src/distrib/sets/lists/debug [netbsd-10]: mi src/distrib/sets/lists/tests [netbsd-10]: mi src/include [netbsd-10]: math.h src/tests/lib/libm [netbsd-10]: Makefile Added Files: src/tests/lib/libm [netbsd-10]: t_errhandling.c Log Message: Pull up following revision(s) (requested by riastradh in ticket #950): include/math.h: revision 1.71 include/math.h: revision 1.72 distrib/sets/lists/debug/mi: revision 1.448 tests/lib/libm/t_errhandling.c: revision 1.1 tests/lib/libm/t_errhandling.c: revision 1.2 tests/lib/libm/t_errhandling.c: revision 1.3 distrib/sets/lists/tests/mi: revision 1.1337 tests/lib/libm/Makefile: revision 1.50 math.h: Define FP_FAST_FMA, FP_FAST_FMAF, FP_FAST_FMAL. These are not strictly necessary to define, really, so we haven't exactly been nonconformant. But they tell programs when they can enable fast paths by using the fma(3) family of functions. PR standards/56234: missing C99 frobs in <math.h> math.h: Add math_errhandling, MATH_ERRNO, MATH_ERREXCEPT. XXX Should maybe put a __math_errhandling in machine/math.h, but only VAX uses MATH_ERRNO and that's not likely to change any time soon, so this will serve for now with less churn. PR standards/56234: missing C99 frobs in <math.h> math.h: Add missing file for math_errhandling test. PR standards/56234: missing C99 frobs in <math.h> Add __TEST_FENV define to fix vax build libm/t_errhandling.c: Put __TEST_FENV before any #includes. This pattern avoids any potential problem with transitive inclusions of fenv.h. (No change here because nothing else this file includes transitively pulls in fenv.h, but being in the habit of doing it this way avoids a class of problems.) PR standards/56234: missing C99 frobs in <math.h> To generate a diff of this commit: cvs rdiff -u -r1.394.2.11 -r1.394.2.12 src/distrib/sets/lists/debug/mi cvs rdiff -u -r1.1238.2.13 -r1.1238.2.14 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.67 -r1.67.2.1 src/include/math.h cvs rdiff -u -r1.48.2.1 -r1.48.2.2 src/tests/lib/libm/Makefile cvs rdiff -u -r0 -r1.3.2.2 src/tests/lib/libm/t_errhandling.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/debug/mi diff -u src/distrib/sets/lists/debug/mi:1.394.2.11 src/distrib/sets/lists/debug/mi:1.394.2.12 --- src/distrib/sets/lists/debug/mi:1.394.2.11 Wed Oct 9 13:25:10 2024 +++ src/distrib/sets/lists/debug/mi Fri Oct 11 19:01:11 2024 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.394.2.11 2024/10/09 13:25:10 martin Exp $ +# $NetBSD: mi,v 1.394.2.12 2024/10/11 19:01:11 martin Exp $ ./etc/mtree/set.debug comp-sys-root ./usr/lib comp-sys-usr compatdir ./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib,compatfile @@ -2306,6 +2306,7 @@ ./usr/libdata/debug/usr/tests/lib/libm/t_cos.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_cosh.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_erf.debug tests-lib-debug debug,atf,compattestfile +./usr/libdata/debug/usr/tests/lib/libm/t_errhandling.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_exp.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_fe_round.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_fenv.debug tests-lib-debug debug,atf,compattestfile Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1238.2.13 src/distrib/sets/lists/tests/mi:1.1238.2.14 --- src/distrib/sets/lists/tests/mi:1.1238.2.13 Wed Oct 9 13:25:12 2024 +++ src/distrib/sets/lists/tests/mi Fri Oct 11 19:01:12 2024 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1238.2.13 2024/10/09 13:25:12 martin Exp $ +# $NetBSD: mi,v 1.1238.2.14 2024/10/11 19:01:12 martin Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -3914,6 +3914,7 @@ ./usr/tests/lib/libm/t_cos tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_cosh tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_erf tests-lib-tests compattestfile,atf +./usr/tests/lib/libm/t_errhandling tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_exp tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_fe_round tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_fenv tests-lib-tests compattestfile,atf Index: src/include/math.h diff -u src/include/math.h:1.67 src/include/math.h:1.67.2.1 --- src/include/math.h:1.67 Sat Aug 27 08:31:59 2022 +++ src/include/math.h Fri Oct 11 19:01:11 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: math.h,v 1.67 2022/08/27 08:31:59 christos Exp $ */ +/* $NetBSD: math.h,v 1.67.2.1 2024/10/11 19:01:11 martin Exp $ */ /* * ==================================================== @@ -21,16 +21,6 @@ #include <sys/cdefs.h> #include <sys/featuretest.h> -/* - * Missing for C99 support: - * - MATH_ERRNO - * - MATH_ERREXCEPT - * - FP_FAST_FMA - * - FP_FAST_FMAF - * - FP_FAST_FMAL - * - math_errhandling - */ - union __float_u { unsigned char __dummy[sizeof(float)]; float __val; @@ -143,9 +133,32 @@ extern const union __float_u __nanf; #define _FP_LOMD 0x80 /* range for machine-specific classes */ #define _FP_HIMD 0xff +/* 7.12#7 fast fma(3) feature test macros */ +#if __GNUC_PREREQ__(4, 4) +# ifdef __FP_FAST_FMA +# define FP_FAST_FMA 1 +# endif +# ifdef __FP_FAST_FMAF +# define FP_FAST_FMAF 1 +# endif +# ifdef __FP_FAST_FMAL +# define FP_FAST_FMAL 1 +# endif +#endif + +/* 7.12#8 ilogb exceptional input result value macros */ #define FP_ILOGB0 INT_MIN #define FP_ILOGBNAN INT_MAX +/* 7.12#9 error handling (__math_errhandling from machine/math.h) */ +#define MATH_ERRNO 1 +#define MATH_ERREXCEPT 2 +#ifdef __vax__ /* XXX !__HAVE_FENV */ +#define math_errhandling MATH_ERRNO +#else +#define math_errhandling MATH_ERREXCEPT +#endif + #endif /* C99 || _XOPEN_SOURCE >= 600 */ /* Index: src/tests/lib/libm/Makefile diff -u src/tests/lib/libm/Makefile:1.48.2.1 src/tests/lib/libm/Makefile:1.48.2.2 --- src/tests/lib/libm/Makefile:1.48.2.1 Wed Oct 2 12:46:13 2024 +++ src/tests/lib/libm/Makefile Fri Oct 11 19:01:12 2024 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.48.2.1 2024/10/02 12:46:13 martin Exp $ +# $NetBSD: Makefile,v 1.48.2.2 2024/10/11 19:01:12 martin Exp $ .include <bsd.own.mk> @@ -25,6 +25,7 @@ TESTS_C+= t_ceil TESTS_C+= t_cos TESTS_C+= t_cosh TESTS_C+= t_erf +TESTS_C+= t_errhandling TESTS_C+= t_exp TESTS_C+= t_fenv TESTS_C+= t_fe_round Added files: Index: src/tests/lib/libm/t_errhandling.c diff -u /dev/null src/tests/lib/libm/t_errhandling.c:1.3.2.2 --- /dev/null Fri Oct 11 19:01:12 2024 +++ src/tests/lib/libm/t_errhandling.c Fri Oct 11 19:01:12 2024 @@ -0,0 +1,97 @@ +/* $NetBSD: t_errhandling.c,v 1.3.2.2 2024/10/11 19:01:12 martin Exp $ */ + +/*- + * Copyright (c) 2024 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#define __TEST_FENV + +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_errhandling.c,v 1.3.2.2 2024/10/11 19:01:12 martin Exp $"); + +#include <atf-c.h> +#include <errno.h> +#include <fenv.h> +#include <math.h> + +ATF_TC(log); +ATF_TC_HEAD(log, tc) +{ + atf_tc_set_md_var(tc, "descr", "log of invalid"); +} +ATF_TC_BODY(log, tc) +{ + static const struct { +#ifdef __HAVE_FENV + double x; + int e; +#define C(x, e) { x, e } +#else + double x; +#define C(x, e) { x } +#endif + } cases[] = { + C(0, FE_DIVBYZERO), + C(-0., FE_DIVBYZERO), + C(-1, FE_INVALID), + C(-HUGE_VAL, FE_INVALID), + }; + volatile double y; +#ifdef __HAVE_FENV + int except; +#endif + unsigned i; + + for (i = 0; i < __arraycount(cases); i++) { + const volatile double x = cases[i].x; + +#ifdef __HAVE_FENV + feclearexcept(FE_ALL_EXCEPT); +#endif + errno = 0; + y = log(x); + if (math_errhandling & MATH_ERREXCEPT) { +#ifdef __HAVE_FENV + ATF_CHECK_MSG(((except = fetestexcept(FE_ALL_EXCEPT)) & + cases[i].e) != 0, + "expected=0x%x actual=0x%x", cases[i].e, except); +#else + atf_tc_fail_nonfatal("MATH_ERREXCEPT but no fenv.h"); +#endif + } + if (math_errhandling & MATH_ERRNO) + ATF_CHECK_EQ_MSG(errno, EDOM, "errno=%d", errno); + } + + __USE(y); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, log); + + return atf_no_error(); +}