]> sourceware.org Git - glibc.git/commitdiff
soft-fp: Make extensions of subnormals from XFmode to TFmode signal underflow if...
authorJoseph Myers <joseph@codesourcery.com>
Thu, 9 Oct 2014 01:00:41 +0000 (01:00 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Thu, 9 Oct 2014 01:00:41 +0000 (01:00 +0000)
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.

ChangeLog
soft-fp/extenddftf2.c
soft-fp/extendsfdf2.c
soft-fp/extendsftf2.c
soft-fp/extendxftf2.c
soft-fp/op-common.h
soft-fp/soft-fp.h

index b5faff4fe7c1bc8b15764c65bbfae6e480487734..703934d098af6ddbdb2654f7a92f787b2548dd28 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2014-10-09  Joseph Myers  <joseph@codesourcery.com>
 
+       * 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.
+
        * soft-fp/soft-fp.h (FP_CLEAR_EXCEPTIONS): Remove macro.
        * sysdeps/sparc/sparc32/soft-fp/q_itoq.c: Define FP_NO_EXCEPTIONS.
        (_Q_itoq): Do not use FP_DECL_EX, FP_CLEAR_EXCEPTIONS or
index 6984b41a800840f9ddc90d717f623b6b9e805869..17655326d8f3de8114158b14532a26f4c7397e78 100644 (file)
@@ -28,6 +28,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define FP_NO_EXACT_UNDERFLOW
 #include "soft-fp.h"
 #include "double.h"
 #include "quad.h"
index a9b6bfbee787da450911f4979f88d5b5f2c288c0..6224195ce91b793de37321f3c7b7ed4b8e423627 100644 (file)
@@ -28,6 +28,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define FP_NO_EXACT_UNDERFLOW
 #include "soft-fp.h"
 #include "single.h"
 #include "double.h"
index 07fc3679acaf45c5ab840cfe22c546315def3cbd..f67d614d7c90bcd7ed5c0f52ce915169652e567d 100644 (file)
@@ -28,6 +28,7 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define FP_NO_EXACT_UNDERFLOW
 #include "soft-fp.h"
 #include "single.h"
 #include "quad.h"
index 67b909563f2b237534367cb406ffbba2f71976b3..a1386a68e657f7fe4ba1efa99b45d2e24d082617 100644 (file)
@@ -39,7 +39,7 @@ __extendxftf2 (XFtype a)
   FP_DECL_Q (R);
   TFtype r;
 
-  FP_INIT_ROUNDMODE;
+  FP_INIT_TRAPPING_EXCEPTIONS;
   FP_UNPACK_RAW_E (A, a);
 #if (2 * _FP_W_TYPE_SIZE) < _FP_FRACBITS_Q
   FP_EXTEND (Q, E, 4, 4, R, A);
index ec0bc426e367d8725c924a1090b7212857f46456..e3212ecfd54db906c64540b9153be102a02afd55 100644 (file)
                  _FP_FRAC_SLL_##dwc (D, (_FP_FRACBITS_##dfs            \
                                          - _FP_FRACBITS_##sfs));       \
                  D##_e = 0;                                            \
+                 if (FP_TRAPPING_EXCEPTIONS & FP_EX_UNDERFLOW)         \
+                   FP_SET_EXCEPTION (FP_EX_UNDERFLOW);                 \
                }                                                       \
              else                                                      \
                {                                                       \
index ead9c97874939627502e288449f556c85b7d7d39..4018b0ee9142c9f485973f076c55e226a8515847 100644 (file)
 # define FP_INIT_ROUNDMODE do {} while (0)
 #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
 
 #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                                                           \
     {                                                          \
This page took 0.115139 seconds and 5 git commands to generate.