From patchwork Fri Jul 17 19:47:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Bergner X-Patchwork-Id: 1331425 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=vch9N11j; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B7hVr47Rtz9sSd for ; Sat, 18 Jul 2020 05:48:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DB400388A827; Fri, 17 Jul 2020 19:48:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB400388A827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1595015280; bh=jg1+uP/WmUUqtJ8y//2RbxVskUu5Re6zWP6+0dd9meU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=vch9N11jfLrcMWLT1a2lO3leVoGWR/WIXVgeNKVhP+tg6zF+I3I9yjQpWTCgflLy6 aRzPfbseoruHOH5muDUY+TN5OEvXN+H+xb5DexaSA+3DKwVI/Dds/CURx3HCfh793P MnkTx7f0OSjqihva8hcG9wCj38bDP6sa9x5eFpBo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 0AB5A388A827 for ; Fri, 17 Jul 2020 19:47:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0AB5A388A827 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 06HJbVPd087043; Fri, 17 Jul 2020 15:47:55 -0400 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 32autbn6ft-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jul 2020 15:47:54 -0400 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 06HJegbQ024312; Fri, 17 Jul 2020 19:47:53 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma01dal.us.ibm.com with ESMTP id 328ux8242a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jul 2020 19:47:53 +0000 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 06HJlqcP58786056 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jul 2020 19:47:52 GMT Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2D4186E04E; Fri, 17 Jul 2020 19:47:52 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 480526E053; Fri, 17 Jul 2020 19:47:51 +0000 (GMT) Received: from [9.65.200.87] (unknown [9.65.200.87]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 17 Jul 2020 19:47:51 +0000 (GMT) To: Segher Boessenkool Subject: [PATCH] rs6000: Generate _Decimal128 to _Decimal32 hardware conversion instructions Message-ID: Date: Fri, 17 Jul 2020 14:47:50 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-07-17_09:2020-07-17, 2020-07-17 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 phishscore=0 bulkscore=0 impostorscore=0 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007170133 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Peter Bergner via Gcc-patches From: Peter Bergner Reply-To: Peter Bergner Cc: Paul E Murphy , Bill Schmidt , GCC Patches Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" PR92488 shows we do not generate hardware conversion instructions when converting from _Decimal128 to _Decimal32. There is no one instruction that does the conversion, so we currently call the __dpd_trunctdsd2 function to do the conversion for us. This is slow. Paul Murphy described a short sequence of dfp hardware instructions that would do the conversion correctly. The patch below implements that idea. The convert-fp-128.c test case uses dg-require-effective-target dfp, so its !dfp usages are basically disabling those tests completely. What we really want is to know whether the compiler is generating hardware instructions or calling the libcalls. For that, we need to test hard_dfp. This patch bootstrapped and regtested with no regressions on powerpc64le-linux. Segher, you pre-approved the pattern, but I thought I'd have you double check the test case changes and new test case. Still ok for trunk? Peter gcc/ PR target/92488 * config/rs6000/dfp.md (trunctdsd2): New define_insn. gcc/testsuite/ PR target/92488 * gcc.target/powerpc/convert-fp-128.c (bl, drsp, drdpq): Update counts. (__dpd_trunctdsd2): Make conditional on !hard_dfp. (__dpd_extendsddd2, __dpd_extendsdtd2, __dpd_truncddsd2, __dpd_extendddtd2, __dpd_trunctddd2): Use !hard_dfp. * gcc.target/powerpc/pr92488.c: New test. diff --git a/gcc/config/rs6000/dfp.md b/gcc/config/rs6000/dfp.md index e91d6f581ed..50bfad6beb7 100644 --- a/gcc/config/rs6000/dfp.md +++ b/gcc/config/rs6000/dfp.md @@ -155,6 +155,16 @@ [(set_attr "type" "dfp") (set_attr "length" "8")]) +(define_insn "trunctdsd2" + [(set (match_operand:SD 0 "gpc_reg_operand" "=d") + (float_truncate:SD (match_operand:TD 1 "gpc_reg_operand" "d"))) + (clobber (match_scratch:TD 2 "=&d")) + (clobber (match_scratch:DF 3 "=&d"))] + "TARGET_DFP" + "mffs %3\;mtfsfi 7,7,1\;drdpq %2,%1\;mtfsf 0xff,%3,1,0\;drsp %0,%2" + [(set_attr "type" "dfp") + (set_attr "length" "20")]) + (define_insn "add3" [(set (match_operand:DDTD 0 "gpc_reg_operand" "=d") (plus:DDTD (match_operand:DDTD 1 "gpc_reg_operand" "%d") diff --git a/gcc/testsuite/gcc.target/powerpc/convert-fp-128.c b/gcc/testsuite/gcc.target/powerpc/convert-fp-128.c index 67896d92c86..5b0ef3b0d49 100644 --- a/gcc/testsuite/gcc.target/powerpc/convert-fp-128.c +++ b/gcc/testsuite/gcc.target/powerpc/convert-fp-128.c @@ -34,7 +34,7 @@ conv2 /* { dg-final { scan-assembler-times {\mbl\M} 24 { target { ! hard_dfp } } } } */ /* { dg-final { scan-assembler-times {\mbl\M} 19 { target { hard_dfp && { ! ppc_float128 } } } } } */ -/* { dg-final { scan-assembler-times {\mbl\M} 31 { target { hard_dfp && { ppc_float128 && { ! ppc_float128_insns } } } } } } */ +/* { dg-final { scan-assembler-times {\mbl\M} 30 { target { hard_dfp && { ppc_float128 && { ! ppc_float128_insns } } } } } } */ /* { dg-final { scan-assembler-times {\mbl\M} 27 { target { hard_dfp && { ppc_float128 && { ppc_float128_insns } } } } } } */ @@ -60,20 +60,20 @@ conv2 /* { dg-final { scan-assembler-times {\mbl __dpd_extendsddf\M} 1 } } */ /* { dg-final { scan-assembler-times {\mbl __dpd_extendsdtf\M} 1 } } */ /* { dg-final { scan-assembler-times {\mbl __dpd_extendsdkf\M} 1 { target { ppc_float128 } } } } */ -/* { dg-final { scan-assembler-times {\mbl __dpd_extendsddd2\M} 1 { target { ! dfp } } } } */ -/* { dg-final { scan-assembler-times {\mbl __dpd_extendsdtd2\M} 1 { target { ! dfp } } } } */ +/* { dg-final { scan-assembler-times {\mbl __dpd_extendsddd2\M} 1 { target { ! hard_dfp } } } } */ +/* { dg-final { scan-assembler-times {\mbl __dpd_extendsdtd2\M} 1 { target { ! hard_dfp } } } } */ /* { dg-final { scan-assembler-times {\mbl __dpd_truncddsf\M} 1 } } */ /* { dg-final { scan-assembler-times {\mbl __dpd_truncdddf\M} 1 } } */ /* { dg-final { scan-assembler-times {\mbl __dpd_extendddtf\M} 1 } } */ /* { dg-final { scan-assembler-times {\mbl __dpd_extendddkf\M} 1 { target { ppc_float128 } } } } */ -/* { dg-final { scan-assembler-times {\mbl __dpd_truncddsd2\M} 1 { target { ! dfp } } } } */ -/* { dg-final { scan-assembler-times {\mbl __dpd_extendddtd2\M} 1 { target { ! dfp } } } } */ +/* { dg-final { scan-assembler-times {\mbl __dpd_truncddsd2\M} 1 { target { ! hard_dfp } } } } */ +/* { dg-final { scan-assembler-times {\mbl __dpd_extendddtd2\M} 1 { target { ! hard_dfp } } } } */ /* { dg-final { scan-assembler-times {\mbl __dpd_trunctdsf\M} 1 } } */ /* { dg-final { scan-assembler-times {\mbl __dpd_trunctddf\M} 1 } } */ /* { dg-final { scan-assembler-times {\mbl __dpd_trunctdtf\M} 1 } } */ /* { dg-final { scan-assembler-times {\mbl __dpd_trunctdkf\M} 1 { target { ppc_float128 } } } } */ -/* { dg-final { scan-assembler-times {\mbl __dpd_trunctdsd2\M} 1 } } */ -/* { dg-final { scan-assembler-times {\mbl __dpd_trunctddd2\M} 1 { target { ! dfp } } } } */ +/* { dg-final { scan-assembler-times {\mbl __dpd_trunctdsd2\M} 1 { target { ! hard_dfp } } } } */ +/* { dg-final { scan-assembler-times {\mbl __dpd_trunctddd2\M} 1 { target { ! hard_dfp } } } } */ /* { dg-final { scan-assembler-times {\mfrsp|xsrsp\M} 2 { target { ! ppc_float128_insns } } } } */ @@ -88,8 +88,8 @@ conv2 /* { dg-final { scan-assembler-times {\mxxlor|xscpsgndp\M} 3 { target { ppc_float128_insns } } } } */ -/* { dg-final { scan-assembler-times {\mdrsp\M} 1 { target { hard_dfp } } } } */ -/* { dg-final { scan-assembler-times {\mdrdpq\M} 1 { target { hard_dfp } } } } */ +/* { dg-final { scan-assembler-times {\mdrsp\M} 2 { target { hard_dfp } } } } */ +/* { dg-final { scan-assembler-times {\mdrdpq\M} 2 { target { hard_dfp } } } } */ /* { dg-final { scan-assembler-times {\mdctdp\M} 2 { target { hard_dfp } } } } */ /* { dg-final { scan-assembler-times {\mdctqpq\M} 2 { target { hard_dfp } } } } */ diff --git a/gcc/testsuite/gcc.target/powerpc/pr92488.c b/gcc/testsuite/gcc.target/powerpc/pr92488.c new file mode 100644 index 00000000000..3ca575531ca --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr92488.c @@ -0,0 +1,43 @@ +/* { dg-do run } */ +/* { dg-require-effective-target dfprt } */ +/* { dg-options "-O2" } */ + +#include +#include + +/* Runnable test case for testing _Decimal128 to _Decimal32 rounding. + The value below when rounded to _Decimal64 would result in the value + 1.2345675e+00, which if it were rounded to _Decimal32 would result in + the value 1.234568e+00. However, the correct value when rounding from + _Decimal128 directly to _Decimal32 is 1.234567e+00. */ + +_Decimal128 td = 1.23456749999999999999e+00dl; +_Decimal32 sd_expected = 1.234567e+00df; + +_Decimal32 __attribute__((noinline)) +td2sd (_Decimal128 td) +{ + return td; +} + +int +main (void) +{ + _Decimal32 sd = td2sd (td); + if (sd != sd_expected) + { + union { + _Decimal32 sd; + unsigned int i; + } u; + + printf ("cast to _Decimal32 failed:\n"); + u.sd = sd; + printf (" actual = 0x%x\n", u.i); + u.sd = sd_expected; + printf (" expected = 0x%x\n", u.i); + abort (); + } + + return 0; +}