]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
S/390: Use proper rounding mode for DFP to BFD conversions
authorAndreas Krebbel <krebbel@linux.ibm.com>
Wed, 12 Sep 2018 11:13:56 +0000 (11:13 +0000)
committerAndreas Krebbel <krebbel@gcc.gnu.org>
Wed, 12 Sep 2018 11:13:56 +0000 (11:13 +0000)
According to IEEE 754 2008 4.3 'Rounding-direction attributes' the
rounding mode of the target format needs to be used. By not setting
the value so far we have always used the DFP rounding mode.

gcc/ChangeLog:

2018-09-12  Andreas Krebbel  <krebbel@linux.ibm.com>

Backport from mainline
2018-09-12  Andreas Krebbel  <krebbel@linux.ibm.com>

* config/s390/s390.md (PFPO_RND_MODE_DFP, PFPO_RND_MODE_BFP): New
constants.
("trunc<BFP:mode><DFP_ALL:mode>2")
("trunc<DFP_ALL:mode><BFP:mode>2")
("extend<BFP:mode><DFP_ALL:mode>2")
("extend<DFP_ALL:mode><BFP:mode>2"): Set proper rounding mode
according to the target operand type.

gcc/testsuite/ChangeLog:

2018-09-12  Andreas Krebbel  <krebbel@linux.ibm.com>

Backport from mainline
2018-09-12  Andreas Krebbel  <krebbel@linux.ibm.com>

* gcc.target/s390/dfp_to_bfp_rounding.c: New test.

From-SVN: r264236

gcc/ChangeLog
gcc/config/s390/s390.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/s390/dfp_to_bfp_rounding.c [new file with mode: 0644]

index 2b1bb83986bafb00a0dffd8e2dad34e13ad39a41..d87df92a4069c8fdd5c17cbfd4e226c138800669 100644 (file)
@@ -1,3 +1,16 @@
+2018-09-12  Andreas Krebbel  <krebbel@linux.ibm.com>
+
+       Backport from mainline
+       2018-09-12  Andreas Krebbel  <krebbel@linux.ibm.com>
+
+       * config/s390/s390.md (PFPO_RND_MODE_DFP, PFPO_RND_MODE_BFP): New
+       constants.
+       ("trunc<BFP:mode><DFP_ALL:mode>2")
+       ("trunc<DFP_ALL:mode><BFP:mode>2")
+       ("extend<BFP:mode><DFP_ALL:mode>2")
+       ("extend<DFP_ALL:mode><BFP:mode>2"): Set proper rounding mode
+       according to the target operand type.
+
 2018-09-04  Max Filippov  <jcmvbkbc@gmail.com>
 
        Backport from mainline
index 1778d60b5dabcace62c6b979486a838f351206d9..9e42a593c17991c663f852efc9452b65f4091188 100644 (file)
    ; Bitposition of operand types
    (PFPO_OP0_TYPE_SHIFT          16)
    (PFPO_OP1_TYPE_SHIFT           8)
+   ; Decide whether current DFP or BFD rounding mode should be used
+   ; for the conversion.
+   (PFPO_RND_MODE_DFP             0)
+   (PFPO_RND_MODE_BFP             1)
   ])
 
 ; Immediate operands for tbegin and tbeginc
 {
   HOST_WIDE_INT flags;
 
+  /* According to IEEE 754 2008 4.3 'Rounding-direction attributes' the
+     rounding mode of the target format needs to be used.  */
+
   flags = (PFPO_CONVERT |
            PFPO_OP_TYPE_<DFP_ALL:MODE> << PFPO_OP0_TYPE_SHIFT |
-           PFPO_OP_TYPE_<BFP:MODE> << PFPO_OP1_TYPE_SHIFT);
+           PFPO_OP_TYPE_<BFP:MODE> << PFPO_OP1_TYPE_SHIFT |
+          PFPO_RND_MODE_DFP);
 
   operands[2] = GEN_INT (flags);
 })
 {
   HOST_WIDE_INT flags;
 
+  /* According to IEEE 754 2008 4.3 'Rounding-direction attributes' the
+     rounding mode of the target format needs to be used.  */
+
   flags = (PFPO_CONVERT |
            PFPO_OP_TYPE_<BFP:MODE> << PFPO_OP0_TYPE_SHIFT |
-           PFPO_OP_TYPE_<DFP_ALL:MODE> << PFPO_OP1_TYPE_SHIFT);
+           PFPO_OP_TYPE_<DFP_ALL:MODE> << PFPO_OP1_TYPE_SHIFT |
+          PFPO_RND_MODE_BFP);
 
   operands[2] = GEN_INT (flags);
 })
 {
   HOST_WIDE_INT flags;
 
+  /* According to IEEE 754 2008 4.3 'Rounding-direction attributes' the
+     rounding mode of the target format needs to be used.  */
+
   flags = (PFPO_CONVERT |
            PFPO_OP_TYPE_<DFP_ALL:MODE> << PFPO_OP0_TYPE_SHIFT |
-           PFPO_OP_TYPE_<BFP:MODE> << PFPO_OP1_TYPE_SHIFT);
+           PFPO_OP_TYPE_<BFP:MODE> << PFPO_OP1_TYPE_SHIFT |
+          PFPO_RND_MODE_DFP);
 
   operands[2] = GEN_INT (flags);
 })
 {
   HOST_WIDE_INT flags;
 
+  /* According to IEEE 754 2008 4.3 'Rounding-direction attributes' the
+     rounding mode of the target format needs to be used.  */
+
   flags = (PFPO_CONVERT |
            PFPO_OP_TYPE_<BFP:MODE> << PFPO_OP0_TYPE_SHIFT |
-           PFPO_OP_TYPE_<DFP_ALL:MODE> << PFPO_OP1_TYPE_SHIFT);
+           PFPO_OP_TYPE_<DFP_ALL:MODE> << PFPO_OP1_TYPE_SHIFT |
+          PFPO_RND_MODE_BFP);
 
   operands[2] = GEN_INT (flags);
 })
index 881c64283cff7e1e0d2dff8dc0af798caf9bfeb8..1f7225246ac7f7f1c30e02386bcd9bdd518252a3 100644 (file)
@@ -1,3 +1,10 @@
+2018-09-12  Andreas Krebbel  <krebbel@linux.ibm.com>
+
+       Backport from mainline
+       2018-09-12  Andreas Krebbel  <krebbel@linux.ibm.com>
+
+       * gcc.target/s390/dfp_to_bfp_rounding.c: New test.
+
 2018-09-07  Janus Weil  <janus@gcc.gnu.org>
 
        Backported from trunk
diff --git a/gcc/testsuite/gcc.target/s390/dfp_to_bfp_rounding.c b/gcc/testsuite/gcc.target/s390/dfp_to_bfp_rounding.c
new file mode 100644 (file)
index 0000000..9a32abf
--- /dev/null
@@ -0,0 +1,29 @@
+/* { dg-do run } */
+/* { dg-options "-O3 -mzarch -march=z10" } */
+
+/* According to IEEE 754 2008 4.3 Conversion operations between
+   different radixes must use the rounding mode of the target radix.
+   On S/390 this means passing the right value in GPR0 to PFPO
+   instruction.  */
+
+#include <fenv.h>
+
+double __attribute__((noclone,noinline))
+convert (_Decimal64 in)
+{
+  return (double)in;
+}
+
+int
+main ()
+{
+  fesetround (FE_UPWARD);
+
+  if (convert (1e-325DD) != __DBL_DENORM_MIN__)
+    __builtin_abort ();
+
+  fesetround (FE_DOWNWARD);
+
+  if (convert (-1e-325DD) != -__DBL_DENORM_MIN__)
+    __builtin_abort ();
+}