about summary refs log tree commit diff
path: root/soft-fp/soft-fp.h
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2014-10-09 01:00:41 +0000
committerJoseph Myers <joseph@codesourcery.com>2014-10-09 01:00:41 +0000
commit43059f42dbd6dd3926c33ee0cbc7583f0c3e84b9 (patch)
tree49c139b7c42576c9b0a4fb3b25424761f37ed8c6 /soft-fp/soft-fp.h
parent2d6a47ba4ca899746db7fb5ba75a82f2cda93a91 (diff)
downloadglibc-43059f42dbd6dd3926c33ee0cbc7583f0c3e84b9.tar.gz
glibc-43059f42dbd6dd3926c33ee0cbc7583f0c3e84b9.tar.xz
glibc-43059f42dbd6dd3926c33ee0cbc7583f0c3e84b9.zip
soft-fp: Make extensions of subnormals from XFmode to TFmode signal underflow if traps enabled.
This patch fixes a soft-fp corner case I previously noted in
<https://sourceware.org/ml/libc-alpha/2013-10/msg00349.html>: when
trapping on underflow is enabled, extensions of subnormals from XFmode
to TFmode need to signal underflow because the result is tiny (but
exact, so the underflow flag is not raised unless trapping is
enabled).

To avoid any excess initialization or tests for other cases of
floating-point extensions, a new FP_INIT_TRAPPING_EXCEPTIONS is added
that does the initialization required for this particular case (more
than FP_INIT_EXCEPTIONS, less than FP_INIT_ROUNDMODE, in general), and
FP_NO_EXACT_UNDERFLOW is added to stub out FP_TRAPPING_EXCEPTIONS
tests for those cases of extensions where the test would be dead code,
to avoid any uninitialized variable warnings.

As the relevant case only applies in libgcc, not to any use of soft-fp
in glibc, there is no bug report in Bugzilla and no non-default
definitions of FP_INIT_TRAPPING_EXCEPTIONS are added by the patch.  A
testcase will be added to GCC as part of an update of soft-fp in
libgcc once this patch is in libc.

Tested for powerpc-nofpu that the disassembly of installed shared
libraries is unchanged by this patch.  Bootstrapped GCC with updated
soft-fp with no regressions on x86_64-unknown-linux-gnu and verified
that a test of the relevant case passes where it failed before.

	* soft-fp/op-common.h (FP_EXTEND): When a subnormal input produces
	a subnormal result, set the underflow exception if trapping on
	underflow is enabled.
	* soft-fp/soft-fp.h (FP_INIT_TRAPPING_EXCEPTIONS): New macro.
	(FP_INIT_EXCEPTIONS): Default to FP_INIT_TRAPPING_EXCEPTIONS.
	[FP_NO_EXACT_UNDERFLOW] (FP_TRAPPING_EXCEPTIONS): Undefine and
	redefine to 0.
	* soft-fp/extenddftf2.c (FP_NO_EXACT_UNDERFLOW): Define.
	* soft-fp/extendsfdf2.c (FP_NO_EXACT_UNDERFLOW): Likewise.
	* soft-fp/extendsftf2.c (FP_NO_EXACT_UNDERFLOW): Likewise.
	* soft-fp/extendxftf2.c (__extendxftf2): Use
	FP_INIT_TRAPPING_EXCEPTIONS instead of FP_INIT_ROUNDMODE.
Diffstat (limited to 'soft-fp/soft-fp.h')
-rw-r--r--soft-fp/soft-fp.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/soft-fp/soft-fp.h b/soft-fp/soft-fp.h
index ead9c97874..4018b0ee91 100644
--- a/soft-fp/soft-fp.h
+++ b/soft-fp/soft-fp.h
@@ -108,9 +108,15 @@
 #endif
 
 /* Initialize any machine-specific state used in
+   FP_TRAPPING_EXCEPTIONS or FP_HANDLE_EXCEPTIONS.  */
+#ifndef FP_INIT_TRAPPING_EXCEPTIONS
+# define FP_INIT_TRAPPING_EXCEPTIONS FP_INIT_ROUNDMODE
+#endif
+
+/* Initialize any machine-specific state used in
    FP_HANDLE_EXCEPTIONS.  */
 #ifndef FP_INIT_EXCEPTIONS
-# define FP_INIT_EXCEPTIONS FP_INIT_ROUNDMODE
+# define FP_INIT_EXCEPTIONS FP_INIT_TRAPPING_EXCEPTIONS
 #endif
 
 #ifndef FP_HANDLE_EXCEPTIONS
@@ -162,6 +168,16 @@
 
 #endif
 
+/* A file using soft-fp may define FP_NO_EXACT_UNDERFLOW before
+   including soft-fp.h to indicate that, although a macro used there
+   could allow for the case of exact underflow requiring the underflow
+   exception to be raised if traps are enabled, for the particular
+   arguments used in that file no exact underflow can occur.  */
+#ifdef FP_NO_EXACT_UNDERFLOW
+# undef FP_TRAPPING_EXCEPTIONS
+# define FP_TRAPPING_EXCEPTIONS 0
+#endif
+
 #define _FP_ROUND_NEAREST(wc, X)				\
   do								\
     {								\