This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Avoid spurious failures from <fenv.h> fallback functions


Many of the fallback implementations of various <fenv.h> functions in
math/ indicate failure even when the semantics of the function mean
there is actually nothing to do in the case where exceptions and
rounding modes aren't supported.  I've filed bug 15654 for this issue.

This patch changes them to indicate success where semantically
appropriate.  This is intended to match what the implementations for
Tile and MicroBlaze do (but covers more functions).  However, the
fallback functions still use stub_warning, which seems appropriate
when there isn't substantive support for the underlying
functionality.  Tested for MIPS64 soft-float (specifically, this fixes
the stdlib/bug-getcontext failure previously seen in that case).

Kaz, Thomas, note that there is no SH version of fgetexcptflg.c.  This
looks like an oversight, given that all the other <fenv.h> functions
have SH implementations.  Neither old nor new stub version would
really be correct for SH; there should be a real implementation.
Filed as bug 15655.

Other than for Tile and MicroBlaze (with partial sets of their own
fallback functions) and SH (as noted above), it appears that these
fallback functions are only used as a set (all used together or none
used at all), in cases lacking hardware support for exceptions or
rounding modes.

2013-06-20  Joseph Myers  <joseph@codesourcery.com>

	[BZ #15654]
	* math/fedisblxcpt.c (fedisableexcept): Return 0.
	* math/feenablxcpt.c (feenableexcept): Return 0 for argument 0.
	* math/fegetenv.c (__fegetenv): Return 0.
	* math/fegetexcept.c (fegetexcept): Return 0.
	* math/fegetround.c (fegetround) [FE_TONEAREST]: Return
	FE_TONEAREST.
	* math/feholdexcpt.c (feholdexcept): Return 0.
	* math/fesetenv.c (__fesetenv): Return 0.
	* math/fesetround.c (fesetround) [FE_TONEAREST]: Return 0 for
	argument FE_TONEAREST.
	* math/feupdateenv.c (__feupdateenv): Return 0.
	* math/fgetexcptflg.c (__fegetexceptflag): Return 0.

diff --git a/math/fedisblxcpt.c b/math/fedisblxcpt.c
index 9b6ef27..9b8374a 100644
--- a/math/fedisblxcpt.c
+++ b/math/fedisblxcpt.c
@@ -22,7 +22,7 @@
 int
 fedisableexcept (int excepts)
 {
-  /* Signal failure.  */
-  return -1;
+  /* All exception traps are disabled.  */
+  return 0;
 }
 stub_warning (fedisableexcept)
diff --git a/math/feenablxcpt.c b/math/feenablxcpt.c
index d8620a0..e57d4e3 100644
--- a/math/feenablxcpt.c
+++ b/math/feenablxcpt.c
@@ -22,7 +22,10 @@
 int
 feenableexcept (int excepts)
 {
-  /* Signal failure.  */
-  return -1;
+  /* Signal failure if any exception traps are to be enabled.  */
+  if (excepts != 0)
+    return -1;
+  else
+    return 0;
 }
 stub_warning (feenableexcept)
diff --git a/math/fegetenv.c b/math/fegetenv.c
index 14bb801..29229dc 100644
--- a/math/fegetenv.c
+++ b/math/fegetenv.c
@@ -23,8 +23,8 @@
 int
 __fegetenv (fenv_t *envp)
 {
-  /* This always fails.  */
-  return 1;
+  /* Nothing to do.  */
+  return 0;
 }
 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
 strong_alias (__fegetenv, __old_fegetenv)
diff --git a/math/fegetexcept.c b/math/fegetexcept.c
index 42aaf93..9075160 100644
--- a/math/fegetexcept.c
+++ b/math/fegetexcept.c
@@ -22,7 +22,7 @@
 int
 fegetexcept (void)
 {
-  /* Signal failure.  */
-  return -1;
+  /* All exception traps are disabled.  */
+  return 0;
 }
 stub_warning (fegetexcept)
diff --git a/math/fegetround.c b/math/fegetround.c
index deb3c5d..24bbd16 100644
--- a/math/fegetround.c
+++ b/math/fegetround.c
@@ -22,6 +22,10 @@
 int
 fegetround (void)
 {
+#ifdef FE_TONEAREST
+  return FE_TONEAREST;
+#else
   return 0;
+#endif
 }
 stub_warning (fegetround)
diff --git a/math/feholdexcpt.c b/math/feholdexcpt.c
index b4e3260..c830afb 100644
--- a/math/feholdexcpt.c
+++ b/math/feholdexcpt.c
@@ -22,7 +22,8 @@
 int
 feholdexcept (fenv_t *envp)
 {
-  return 1;		/* Signal failure.  */
+  /* No exception traps to disable and no state to save.  */
+  return 0;
 }
 libm_hidden_def (feholdexcept)
 stub_warning (feholdexcept)
diff --git a/math/fesetenv.c b/math/fesetenv.c
index 058700f..7361958 100644
--- a/math/fesetenv.c
+++ b/math/fesetenv.c
@@ -23,8 +23,8 @@
 int
 __fesetenv (const fenv_t *envp)
 {
-  /* This always fails.  */
-  return 1;
+  /* Nothing to do.  */
+  return 0;
 }
 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
 strong_alias (__fesetenv, __old_fesetenv)
diff --git a/math/fesetround.c b/math/fesetround.c
index 0e06217..1895a20 100644
--- a/math/fesetround.c
+++ b/math/fesetround.c
@@ -22,7 +22,11 @@
 int
 fesetround (int round)
 {
+#ifdef FE_TONEAREST
+  return (round == FE_TONEAREST) ? 0 : 1;
+#else
   return 1;	/* Signal we are unable to set the direction.  */
+#endif
 }
 libm_hidden_def (fesetround)
 stub_warning (fesetround)
diff --git a/math/feupdateenv.c b/math/feupdateenv.c
index e0350b3..5a39521 100644
--- a/math/feupdateenv.c
+++ b/math/feupdateenv.c
@@ -23,8 +23,8 @@
 int
 __feupdateenv (const fenv_t *envp)
 {
-  /* This always fails.  */
-  return 1;
+  /* Nothing to do.  */
+  return 0;
 }
 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
 strong_alias (__feupdateenv, __old_feupdateenv)
diff --git a/math/fgetexcptflg.c b/math/fgetexcptflg.c
index 1512864..764be42 100644
--- a/math/fgetexcptflg.c
+++ b/math/fgetexcptflg.c
@@ -23,8 +23,8 @@
 int
 __fegetexceptflag (fexcept_t *flagp, int excepts)
 {
-  /* This always fails.  */
-  return 1;
+  /* Nothing to do.  */
+  return 0;
 }
 #if SHLIB_COMPAT (libm, GLIBC_2_1, GLIBC_2_2)
 strong_alias (__fegetexceptflag, __old_fegetexceptflag)

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]