Module Name: src Committed By: martin Date: Fri Feb 23 18:13:54 UTC 2024
Modified Files: src/lib/libm/arch/x86_64 [netbsd-9]: fenv.c src/tests/lib/libm [netbsd-9]: t_fenv.c Log Message: Pull up following revision(s) (requested by riastradh in ticket #1801): tests/lib/libm/t_fenv.c: revision 1.14 tests/lib/libm/t_fenv.c: revision 1.15 lib/libm/arch/x86_64/fenv.c: revision 1.11 fenv(3): Add test for PR port-amd64/57949. fenv(3): Fix fetestexcept to avoid side effects on trap state. PR port-amd64/57949 To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.7.14.1 src/lib/libm/arch/x86_64/fenv.c cvs rdiff -u -r1.6 -r1.6.2.1 src/tests/lib/libm/t_fenv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libm/arch/x86_64/fenv.c diff -u src/lib/libm/arch/x86_64/fenv.c:1.7 src/lib/libm/arch/x86_64/fenv.c:1.7.14.1 --- src/lib/libm/arch/x86_64/fenv.c:1.7 Wed Mar 22 23:11:09 2017 +++ src/lib/libm/arch/x86_64/fenv.c Fri Feb 23 18:13:54 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: fenv.c,v 1.7 2017/03/22 23:11:09 chs Exp $ */ +/* $NetBSD: fenv.c,v 1.7.14.1 2024/02/23 18:13:54 martin Exp $ */ /*- * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: fenv.c,v 1.7 2017/03/22 23:11:09 chs Exp $"); +__RCSID("$NetBSD: fenv.c,v 1.7.14.1 2024/02/23 18:13:54 martin Exp $"); #include "namespace.h" @@ -259,7 +259,6 @@ fesetexceptflag(const fexcept_t *flagp, int fetestexcept(int excepts) { - fenv_t fenv; uint32_t mxcsr; uint16_t status; int ex; @@ -268,17 +267,10 @@ fetestexcept(int excepts) ex = excepts & FE_ALL_EXCEPT; - /* Store the current x87 floating-point environment */ - memset(&fenv, 0, sizeof(fenv)); - - __fnstenv(&fenv); __fnstsw(&status); - - /* Store the MXCSR register state */ - __stmxcsr(&fenv.mxcsr); __stmxcsr(&mxcsr); - return ((fenv.x87.status | fenv.mxcsr) & ex); + return ((status | mxcsr) & ex); } /* Index: src/tests/lib/libm/t_fenv.c diff -u src/tests/lib/libm/t_fenv.c:1.6 src/tests/lib/libm/t_fenv.c:1.6.2.1 --- src/tests/lib/libm/t_fenv.c:1.6 Thu Apr 25 20:48:54 2019 +++ src/tests/lib/libm/t_fenv.c Fri Feb 23 18:13:54 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_fenv.c,v 1.6 2019/04/25 20:48:54 kamil Exp $ */ +/* $NetBSD: t_fenv.c,v 1.6.2.1 2024/02/23 18:13:54 martin Exp $ */ /*- * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> -__RCSID("$NetBSD: t_fenv.c,v 1.6 2019/04/25 20:48:54 kamil Exp $"); +__RCSID("$NetBSD: t_fenv.c,v 1.6.2.1 2024/02/23 18:13:54 martin Exp $"); #include <atf-c.h> @@ -185,12 +185,40 @@ ATF_TC_BODY(feenableexcept, tc) ATF_CHECK(fpgetmask() == FP_X_INV); } +ATF_TC(fetestexcept_trap); +ATF_TC_HEAD(fetestexcept_trap, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Verify fetestexcept doesn't affect the trapped excpetions"); +} +ATF_TC_BODY(fetestexcept_trap, tc) +{ + int except; + + fedisableexcept(FE_ALL_EXCEPT); + ATF_CHECK_EQ_MSG((except = fegetexcept()), 0, + "fegetexcept()=0x%x", except); + + (void)fetestexcept(FE_ALL_EXCEPT); + ATF_CHECK_EQ_MSG((except = fegetexcept()), 0, + "fegetexcept()=0x%x", except); + + feenableexcept(FE_ALL_EXCEPT); + ATF_CHECK_EQ_MSG((except = fegetexcept()), FE_ALL_EXCEPT, + "fegetexcept()=0x%x FE_ALL_EXCEPT=0x%x", except, FE_ALL_EXCEPT); + + (void)fetestexcept(FE_ALL_EXCEPT); + ATF_CHECK_EQ_MSG((except = fegetexcept()), FE_ALL_EXCEPT, + "fegetexcept()=0x%x FE_ALL_EXCEPT=0x%x", except, FE_ALL_EXCEPT); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, fegetround); ATF_TP_ADD_TC(tp, fesetround); ATF_TP_ADD_TC(tp, fegetexcept); ATF_TP_ADD_TC(tp, feenableexcept); + ATF_TP_ADD_TC(tp, fetestexcept_trap); return atf_no_error(); }