From: Andreas Krebbel Date: Wed, 12 Sep 2018 11:13:56 +0000 (+0000) Subject: S/390: Use proper rounding mode for DFP to BFD conversions X-Git-Tag: releases/gcc-7.4.0~165 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c6ebc6f71b74ac6b87a0da7fea1df8a35cbb2e68;p=thirdparty%2Fgcc.git S/390: Use proper rounding mode for DFP to BFD conversions 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 Backport from mainline 2018-09-12 Andreas Krebbel * config/s390/s390.md (PFPO_RND_MODE_DFP, PFPO_RND_MODE_BFP): New constants. ("trunc2") ("trunc2") ("extend2") ("extend2"): Set proper rounding mode according to the target operand type. gcc/testsuite/ChangeLog: 2018-09-12 Andreas Krebbel Backport from mainline 2018-09-12 Andreas Krebbel * gcc.target/s390/dfp_to_bfp_rounding.c: New test. From-SVN: r264236 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2b1bb83986ba..d87df92a4069 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2018-09-12 Andreas Krebbel + + Backport from mainline + 2018-09-12 Andreas Krebbel + + * config/s390/s390.md (PFPO_RND_MODE_DFP, PFPO_RND_MODE_BFP): New + constants. + ("trunc2") + ("trunc2") + ("extend2") + ("extend2"): Set proper rounding mode + according to the target operand type. + 2018-09-04 Max Filippov Backport from mainline diff --git a/gcc/config/s390/s390.md b/gcc/config/s390/s390.md index 1778d60b5dab..9e42a593c179 100644 --- a/gcc/config/s390/s390.md +++ b/gcc/config/s390/s390.md @@ -401,6 +401,10 @@ ; 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 @@ -5354,9 +5358,13 @@ { 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_ << PFPO_OP0_TYPE_SHIFT | - PFPO_OP_TYPE_ << PFPO_OP1_TYPE_SHIFT); + PFPO_OP_TYPE_ << PFPO_OP1_TYPE_SHIFT | + PFPO_RND_MODE_DFP); operands[2] = GEN_INT (flags); }) @@ -5376,9 +5384,13 @@ { 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_ << PFPO_OP0_TYPE_SHIFT | - PFPO_OP_TYPE_ << PFPO_OP1_TYPE_SHIFT); + PFPO_OP_TYPE_ << PFPO_OP1_TYPE_SHIFT | + PFPO_RND_MODE_BFP); operands[2] = GEN_INT (flags); }) @@ -5419,9 +5431,13 @@ { 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_ << PFPO_OP0_TYPE_SHIFT | - PFPO_OP_TYPE_ << PFPO_OP1_TYPE_SHIFT); + PFPO_OP_TYPE_ << PFPO_OP1_TYPE_SHIFT | + PFPO_RND_MODE_DFP); operands[2] = GEN_INT (flags); }) @@ -5441,9 +5457,13 @@ { 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_ << PFPO_OP0_TYPE_SHIFT | - PFPO_OP_TYPE_ << PFPO_OP1_TYPE_SHIFT); + PFPO_OP_TYPE_ << PFPO_OP1_TYPE_SHIFT | + PFPO_RND_MODE_BFP); operands[2] = GEN_INT (flags); }) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 881c64283cff..1f7225246ac7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-09-12 Andreas Krebbel + + Backport from mainline + 2018-09-12 Andreas Krebbel + + * gcc.target/s390/dfp_to_bfp_rounding.c: New test. + 2018-09-07 Janus Weil 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 index 000000000000..9a32abfdea62 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/dfp_to_bfp_rounding.c @@ -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 + +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 (); +}