NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: port-amd64/57949: fetestexcept disables all floating-point exception traps as a side effect



The attached patch should fix this -- I'll commit once the releng
testbed has confirmed my test is working to detect the problem.
From 8af3bc587abd07af6d32acf4f5dc7803ac28ec23 Mon Sep 17 00:00:00 2001
From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
Date: Mon, 19 Feb 2024 23:24:13 +0000
Subject: [PATCH] fenv(3): Fix fetestexcept to avoid side effects on trap
 state.

PR port-amd64/57949
---
 lib/libm/arch/x86_64/fenv.c | 10 +---------
 tests/lib/libm/t_fenv.c     |  3 ---
 2 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/lib/libm/arch/x86_64/fenv.c b/lib/libm/arch/x86_64/fenv.c
index cd09c8bbd597..7d1816c15a72 100644
--- a/lib/libm/arch/x86_64/fenv.c
+++ b/lib/libm/arch/x86_64/fenv.c
@@ -259,7 +259,6 @@ fesetexceptflag(const fexcept_t *flagp, int excepts)
 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);
 }
 
 /*
diff --git a/tests/lib/libm/t_fenv.c b/tests/lib/libm/t_fenv.c
index 038da828c7c6..deacead62b6f 100644
--- a/tests/lib/libm/t_fenv.c
+++ b/tests/lib/libm/t_fenv.c
@@ -364,9 +364,6 @@ ATF_TC_BODY(fetestexcept_trap, tc)
 	    "fegetexcept()=0x%x FE_ALL_EXCEPT=0x%x", except, FE_ALL_EXCEPT);
 
 	(void)fetestexcept(FE_ALL_EXCEPT);
-#ifdef __x86_64__
-	atf_tc_expect_fail("PR port-amd64/57949");
-#endif
 	ATF_CHECK_EQ_MSG((except = fegetexcept()), FE_ALL_EXCEPT,
 	    "fegetexcept()=0x%x FE_ALL_EXCEPT=0x%x", except, FE_ALL_EXCEPT);
 }


Home | Main Index | Thread Index | Old Index