diff options
author | Andreas Krebbel <krebbel@linux.ibm.com> | 2018-09-12 10:58:42 +0000 |
---|---|---|
committer | Andreas Krebbel <krebbel@gcc.gnu.org> | 2018-09-12 10:58:42 +0000 |
commit | ced8d882349226b8c566914826e8f59961240ad1 (patch) | |
tree | 943924130bdc7526d1cfc789e2cefae0cb95d32d /gcc | |
parent | 7e7a6ed74d33c5bf28cd1d8e6e855373aec13b19 (diff) | |
download | gcc-ced8d882349226b8c566914826e8f59961240ad1.zip gcc-ced8d882349226b8c566914826e8f59961240ad1.tar.gz gcc-ced8d882349226b8c566914826e8f59961240ad1.tar.bz2 |
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 <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>
* gcc.target/s390/dfp_to_bfp_rounding.c: New test.
From-SVN: r264234
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/config/s390/s390.md | 28 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/s390/dfp_to_bfp_rounding.c | 29 |
4 files changed, 67 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bd0d866..77ef4bb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +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-12 Jakub Jelinek <jakub@redhat.com> Andreas Krebbel <krebbel@linux.ibm.com> diff --git a/gcc/config/s390/s390.md b/gcc/config/s390/s390.md index ddf8608..537ed35 100644 --- a/gcc/config/s390/s390.md +++ b/gcc/config/s390/s390.md @@ -404,6 +404,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 @@ -5377,9 +5381,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_<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); }) @@ -5399,9 +5407,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_<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); }) @@ -5442,9 +5454,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_<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); }) @@ -5464,9 +5480,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_<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); }) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1d38a8e..a29d014 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-09-12 Andreas Krebbel <krebbel@linux.ibm.com> + + * gcc.target/s390/dfp_to_bfp_rounding.c: New test. + 2018-09-12 Jakub Jelinek <jakub@redhat.com> Andreas Krebbel <krebbel@linux.ibm.com> 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 0000000..9a32abf --- /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 <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 (); +} |