From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 730143858C60 for ; Fri, 3 Feb 2023 21:37:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 730143858C60 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 313LBtSs021224; Fri, 3 Feb 2023 21:37:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : subject : message-id : references : mime-version : content-type : in-reply-to; s=pp1; bh=ldH5ieDlix4SE8ECO075Y6xuR5PKXo0Z/WYXRu63394=; b=ZQgV/PoewCQj5I7Er+CTJ+fJ17nVmpdz3/kRDLyUsL7fgWPWltRcms5kTd1y5O+pxCtN 5dI3BjMp9sJFA7IUAwHbzvD1IaicBYPEqA69m7Z6aAJWhROA6ittP7jLdLLxt2Gu1Xj/ WXMBC2Dn3V6MtpXjp7pd2w8mHBFninzwGyVfBLMuU0av0TVr5sKrld/fa8YvRNilUEsH XlYYLqRKW3St2PQU1TFcDr6Er7y6p3eygQOv3SJTko8cSB5GST5lrCfePqD6Yb/kKR4g xkNfH8s9d8xG/5aFRULcKzxcH41Ui0CDiCTrolB/LQkCP0r8yUvMtUQK25bmN34Ag1ol /A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nh9yfrum7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Feb 2023 21:37:14 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 313LFXSf033254; Fri, 3 Feb 2023 21:37:13 GMT Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nh9yfrukn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Feb 2023 21:37:13 +0000 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 313J3u8h026758; Fri, 3 Feb 2023 21:37:12 GMT Received: from smtprelay06.dal12v.mail.ibm.com ([9.208.130.100]) by ppma01wdc.us.ibm.com (PPS) with ESMTPS id 3ncvtnjukm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Feb 2023 21:37:12 +0000 Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay06.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 313LbBj37799408 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 3 Feb 2023 21:37:11 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 106A458065; Fri, 3 Feb 2023 21:37:11 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 29C655804B; Fri, 3 Feb 2023 21:37:10 +0000 (GMT) Received: from toto.the-meissners.org (unknown [9.65.233.34]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTPS; Fri, 3 Feb 2023 21:37:10 +0000 (GMT) Date: Fri, 3 Feb 2023 16:37:08 -0500 From: Michael Meissner To: Michael Meissner , gcc-patches@gcc.gnu.org, Segher Boessenkool , "Kewen.Lin" , David Edelsohn , Peter Bergner , Will Schmidt Subject: [PATCH 8/8] Add saturating subtract built-ins. Message-ID: Mail-Followup-To: Michael Meissner , gcc-patches@gcc.gnu.org, Segher Boessenkool , "Kewen.Lin" , David Edelsohn , Peter Bergner , Will Schmidt References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-TM-AS-GCONF: 00 X-Proofpoint-GUID: dcCpXqTjAq7CBurPDo9vmcLfqSDCO_P_ X-Proofpoint-ORIG-GUID: wEodvHz0_vi9xKSIrbIMaJ7RFzg4GA1U X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-03_19,2023-02-03_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 impostorscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302030194 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,KAM_MANYTO,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This patch adds support for a saturating subtract built-in function that may be added to a future PowerPC processor. Note, if it is added, the name of the built-in function may change before GCC 13 is released. If the name changes, we will submit a patch changing the name. I also added support for providing dense math built-in functions, even though at present, we have not added any new built-in functions for dense math. It is likely we will want to add new dense math built-in functions as the dense math support is fleshed out. I tested this patch on a little endian power10 system with long double using the tradiational IBM double double format. Assuming the other 6 patches for -mcpu=future are checked in (or at least the first patch), can I check this patch into the master branch for GCC 13. Note, I will be on vacation from Tuesday February 7th through Tuesday February 14th. 2023-02-03 Michael Meissner gcc/ * config/rs6000/rs6000-builtin.cc (rs6000_invalid_builtin): Add support for flagging invalid use of future built-in functions. (rs6000_builtin_is_supported): Add support for future built-in functions. * config/rs6000/rs6000-builtins.def (__builtin_saturate_subtract32): New built-in function for -mcpu=future. (__builtin_saturate_subtract64): Likewise. * config/rs6000/rs6000-gen-builtins.cc (enum bif_stanza): Add stanzas for -mcpu=future built-ins. (stanza_map): Likewise. (enable_string): Likewise. (struct attrinfo): Likewise. (parse_bif_attrs): Likewise. (write_decls): Likewise. * config/rs6000/rs6000.md (sat_sub3): Add saturating subtract built-in insn declarations. (sat_sub3_dot): Likewise. (sat_sub3_dot2): Likewise. * doc/extend.texi (Future PowerPC built-ins): New section. gcc/testsuite/ * gcc.target/powerpc/subfus-1.c: New test. * gcc.target/powerpc/subfus-2.c: Likewise. --- gcc/config/rs6000/rs6000-builtin.cc | 17 ++++++ gcc/config/rs6000/rs6000-builtins.def | 11 ++++ gcc/config/rs6000/rs6000-gen-builtins.cc | 35 ++++++++++-- gcc/config/rs6000/rs6000.md | 60 +++++++++++++++++++++ gcc/doc/extend.texi | 24 +++++++++ gcc/testsuite/gcc.target/powerpc/subfus-1.c | 32 +++++++++++ gcc/testsuite/gcc.target/powerpc/subfus-2.c | 32 +++++++++++ gcc/testsuite/lib/target-supports.exp | 16 +++++- 8 files changed, 220 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/subfus-1.c create mode 100644 gcc/testsuite/gcc.target/powerpc/subfus-2.c diff --git a/gcc/config/rs6000/rs6000-builtin.cc b/gcc/config/rs6000/rs6000-builtin.cc index d971cf90e51..b9b0b2d52d0 100644 --- a/gcc/config/rs6000/rs6000-builtin.cc +++ b/gcc/config/rs6000/rs6000-builtin.cc @@ -139,6 +139,17 @@ rs6000_invalid_builtin (enum rs6000_gen_builtins fncode) case ENB_MMA: error ("%qs requires the %qs option", name, "-mmma"); break; + case ENB_FUTURE: + error ("%qs requires the %qs option", name, "-mcpu=future"); + break; + case ENB_FUTURE_64: + error ("%qs requires the %qs option and either the %qs or %qs option", + name, "-mcpu=future", "-m64", "-mpowerpc64"); + break; + case ENB_DM: + error ("%qs requires the %qs or %qs options", name, "-mcpu=future", + "-mdense-math"); + break; default: case ENB_ALWAYS: gcc_unreachable (); @@ -194,6 +205,12 @@ rs6000_builtin_is_supported (enum rs6000_gen_builtins fncode) return TARGET_HTM; case ENB_MMA: return TARGET_MMA; + case ENB_FUTURE: + return TARGET_FUTURE; + case ENB_FUTURE_64: + return TARGET_FUTURE && TARGET_POWERPC64; + case ENB_DM: + return TARGET_DENSE_MATH; default: gcc_unreachable (); } diff --git a/gcc/config/rs6000/rs6000-builtins.def b/gcc/config/rs6000/rs6000-builtins.def index e0d9f5adc97..8b73e994558 100644 --- a/gcc/config/rs6000/rs6000-builtins.def +++ b/gcc/config/rs6000/rs6000-builtins.def @@ -139,6 +139,8 @@ ; endian Needs special handling for endianness ; ibmld Restrict usage to the case when TFmode is IBM-128 ; ibm128 Restrict usage to the case where __ibm128 is supported or if ibmld +; future Restrict usage to future instructions +; dm Restrict usage to dense math ; ; Each attribute corresponds to extra processing required when ; the built-in is expanded. All such special processing should @@ -4108,3 +4110,12 @@ void __builtin_vsx_stxvp (v256, unsigned long, const v256 *); STXVP nothing {mma,pair} + +[future] + const signed int __builtin_saturate_subtract32 (signed int, signed int); + SAT_SUBSI sat_subsi3 {} + +[future-64] + const signed long __builtin_saturate_subtract64 (signed long, signed long); + SAT_SUBDI sat_subdi3 {} + diff --git a/gcc/config/rs6000/rs6000-gen-builtins.cc b/gcc/config/rs6000/rs6000-gen-builtins.cc index a2f442ed90d..daf7fff079e 100644 --- a/gcc/config/rs6000/rs6000-gen-builtins.cc +++ b/gcc/config/rs6000/rs6000-gen-builtins.cc @@ -233,6 +233,9 @@ enum bif_stanza BSTZ_P10, BSTZ_P10_64, BSTZ_MMA, + BSTZ_FUTURE, + BSTZ_FUTURE_64, + BSTZ_DM, NUMBIFSTANZAS }; @@ -266,7 +269,10 @@ static stanza_entry stanza_map[NUMBIFSTANZAS] = { "htm", BSTZ_HTM }, { "power10", BSTZ_P10 }, { "power10-64", BSTZ_P10_64 }, - { "mma", BSTZ_MMA } + { "mma", BSTZ_MMA }, + { "future", BSTZ_FUTURE }, + { "future-64", BSTZ_FUTURE_64 }, + { "dm", BSTZ_DM }, }; static const char *enable_string[NUMBIFSTANZAS] = @@ -291,7 +297,10 @@ static const char *enable_string[NUMBIFSTANZAS] = "ENB_HTM", "ENB_P10", "ENB_P10_64", - "ENB_MMA" + "ENB_MMA", + "ENB_FUTURE", + "ENB_FUTURE_64", + "ENB_DM", }; /* Function modifiers provide special handling for const, pure, and fpmath @@ -395,6 +404,8 @@ struct attrinfo bool isendian; bool isibmld; bool isibm128; + bool isfuture; + bool isdm; }; /* Fields associated with a function prototype (bif or overload). */ @@ -1477,7 +1488,8 @@ parse_bif_attrs (attrinfo *attrptr) "ldvec = %d, stvec = %d, reve = %d, pred = %d, htm = %d, " "htmspr = %d, htmcr = %d, mma = %d, quad = %d, pair = %d, " "mmaint = %d, no32bit = %d, 32bit = %d, cpu = %d, ldstmask = %d, " - "lxvrse = %d, lxvrze = %d, endian = %d, ibmdld = %d, ibm128 = %d.\n", + "lxvrse = %d, lxvrze = %d, endian = %d, ibmdld = %d, ibm128 = %d,", + "future = %d, dm = %d.\n", attrptr->isinit, attrptr->isset, attrptr->isextract, attrptr->isnosoft, attrptr->isldvec, attrptr->isstvec, attrptr->isreve, attrptr->ispred, attrptr->ishtm, attrptr->ishtmspr, @@ -1485,7 +1497,7 @@ parse_bif_attrs (attrinfo *attrptr) attrptr->ismmaint, attrptr->isno32bit, attrptr->is32bit, attrptr->iscpu, attrptr->isldstmask, attrptr->islxvrse, attrptr->islxvrze, attrptr->isendian, attrptr->isibmld, - attrptr->isibm128); + attrptr->isibm128, attrptr->isfuture, attrptr->isdm); #endif return PC_OK; @@ -2257,7 +2269,10 @@ write_decls (void) fprintf (header_file, " ENB_HTM,\n"); fprintf (header_file, " ENB_P10,\n"); fprintf (header_file, " ENB_P10_64,\n"); - fprintf (header_file, " ENB_MMA\n"); + fprintf (header_file, " ENB_MMA,\n"); + fprintf (header_file, " ENB_FUTURE,\n"); + fprintf (header_file, " ENB_FUTURE_64,\n"); + fprintf (header_file, " ENB_DM\n"); fprintf (header_file, "};\n\n"); fprintf (header_file, "#define PPC_MAXRESTROPNDS 3\n"); @@ -2301,6 +2316,8 @@ write_decls (void) fprintf (header_file, "#define bif_endian_bit\t\t(0x00200000)\n"); fprintf (header_file, "#define bif_ibmld_bit\t\t(0x00400000)\n"); fprintf (header_file, "#define bif_ibm128_bit\t\t(0x00800000)\n"); + fprintf (header_file, "#define bif_future_bit\t\t(0x01000000)\n"); + fprintf (header_file, "#define bif_dm_bit\t\t(0x02000000)\n"); fprintf (header_file, "\n"); fprintf (header_file, "#define bif_is_init(x)\t\t((x).bifattrs & bif_init_bit)\n"); @@ -2350,6 +2367,10 @@ write_decls (void) "#define bif_is_ibmld(x)\t((x).bifattrs & bif_ibmld_bit)\n"); fprintf (header_file, "#define bif_is_ibm128(x)\t((x).bifattrs & bif_ibm128_bit)\n"); + fprintf (header_file, + "#define bif_is_future(x)\t((x).bifattrs & bif_future_bit)\n"); + fprintf (header_file, + "#define bif_is_dm(x)\t((x).bifattrs & bif_dm_bit)\n"); fprintf (header_file, "\n"); fprintf (header_file, @@ -2548,6 +2569,10 @@ write_bif_static_init (void) fprintf (init_file, " | bif_ibmld_bit"); if (bifp->attrs.isibm128) fprintf (init_file, " | bif_ibm128_bit"); + if (bifp->attrs.isfuture) + fprintf (init_file, " | bif_future_bit"); + if (bifp->attrs.isdm) + fprintf (init_file, " | bif_dm_bit"); fprintf (init_file, ",\n"); fprintf (init_file, " /* restr_opnd */\t{%d, %d, %d},\n", bifp->proto.restr_opnd[0], bifp->proto.restr_opnd[1], diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index ee7651d9b43..f9e231c16be 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -15654,6 +15654,66 @@ (define_insn "hashchk" } [(set_attr "type" "load")]) +;; Signed saturation. + +;; The subfus instruction is defined as: SUBFUS RT,L,RA,RB. The extended +;; mnemonic that we use (subdus and subwus) has the arguments RA and RB +;; reversed (so it becomes a subtract instead of subtract from). + +(define_insn "sat_sub3" + [(set (match_operand:GPR 0 "gpc_reg_operand" "=r") + (ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r") + (match_operand:GPR 2 "gpc_reg_operand" "r")))] + "TARGET_FUTURE" + "subus %0,%1,%2" + [(set_attr "type" "add")]) + +(define_insn_and_split "*sat_sub3_dot" + [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y") + (compare:CC (ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r") + (match_operand:GPR 2 "gpc_reg_operand" "r,r")) + (const_int 0))) + (clobber (match_scratch:GPR 0 "=r,r"))] + "TARGET_FUTURE" + "@ + subus. %0,%1,%2 + #" + "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)" + [(set (match_dup 0) + (ss_minus:GPR (match_dup 1) + (match_dup 2))) + (set (match_dup 3) + (compare:CC (match_dup 0) + (const_int 0)))] + "" + [(set_attr "type" "add") + (set_attr "dot" "yes") + (set_attr "length" "4,8")]) + +(define_insn_and_split "*sat_sub3_dot2" + [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y") + (compare:CC (ss_minus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r") + (match_operand:GPR 2 "gpc_reg_operand" "r,r")) + (const_int 0))) + (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r") + (ss_minus:GPR (match_dup 1) + (match_dup 2)))] + "TARGET_FUTURE" + "@ + subus. %0,%1,%2 + #" + "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)" + [(set (match_dup 0) + (ss_minus:GPR (match_dup 1) + (match_dup 2))) + (set (match_dup 3) + (compare:CC (match_dup 0) + (const_int 0)))] + "" + [(set_attr "type" "add") + (set_attr "dot" "yes") + (set_attr "length" "4,8")]) + (include "sync.md") (include "vector.md") diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 5a026c4b48c..a6d25b5b618 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -17839,6 +17839,7 @@ Disable global interrupt. * Basic PowerPC Built-in Functions Available on ISA 2.07:: * Basic PowerPC Built-in Functions Available on ISA 3.0:: * Basic PowerPC Built-in Functions Available on ISA 3.1:: +* Basic Built-in Functions that may be available on future PowerPCs:: @end menu This section describes PowerPC built-in functions that do not require @@ -18496,6 +18497,29 @@ ISA 3.1 @code{stxvrbx}, @code{stxvrhx}, @code{stxvrwx}, and @code{stxvrdx} instructions. @findex vec_xst_trunc +@node Basic Built-in Functions that may be available on future PowerPCs +@subsubsection Potential future PowerPC Built-in Functions + +The built-in functions described in this section may be available on +future PowerPC processors. At present, these built-ins exist to +allowing testing of new instructions. There is no guarantee that +these instructions will actually be implemented. + +The following built-in functions are available on Linux 64-bit systems +that use a potential future instruction set (@option{-mcpu=future}): + +@table @code +@item int __builtin_saturate_subtract32 (int, int) +Subtract the second operand from the first operand. If the value +would be less than 0, then the result is 0 instead of the negative +value of the subtraction. + +@item long __builtin_saturate_subtract64 (long, long) +Subtract the second operand from the first operand. If the value +would be less than 0, then the result is 0 instead of the negative +value of the subtraction. +@end table + @node PowerPC AltiVec/VSX Built-in Functions @subsection PowerPC AltiVec/VSX Built-in Functions diff --git a/gcc/testsuite/gcc.target/powerpc/subfus-1.c b/gcc/testsuite/gcc.target/powerpc/subfus-1.c new file mode 100644 index 00000000000..535e7f8483d --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/subfus-1.c @@ -0,0 +1,32 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_future_ok } */ +/* { dg-options "-mdejagnu-cpu=future -O2" } */ + +/* Test whether the saturating subtract built-in generates subwus for 32-bit + subtracts. */ + +int do_sat_int (int a, int b) +{ + return __builtin_saturate_subtract32 (a, b); /* subwus */ +} + +int do_sat_int_dot (int a, int b, int *p) +{ + int r = __builtin_saturate_subtract32 (a, b); /* subwus. */ + if (r == 0) + *p = 0; + + return r; +} + +void do_sat_int_dot2 (int a, int b, int *p, int *q) +{ + if (__builtin_saturate_subtract32 (a, b)) /* subwus. */ + *p = 0; + + *q = a + b; + return; +} + +/* { dg-final { scan-assembler {\msubwus\M} } } */ +/* { dg-final { scan-assembler-not {\msubf\M} } } */ diff --git a/gcc/testsuite/gcc.target/powerpc/subfus-2.c b/gcc/testsuite/gcc.target/powerpc/subfus-2.c new file mode 100644 index 00000000000..b68e66dd2b0 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/subfus-2.c @@ -0,0 +1,32 @@ +/* { dg-do compile { target lp64 } } */ +/* { dg-require-effective-target powerpc_future_ok } */ +/* { dg-options "-mdejagnu-cpu=future -O2" } */ + +/* Test whether the saturating subtract built-in generates subwus for 64-bit + subtracts. */ + +long do_sat_long (long a, long b) +{ + return __builtin_saturate_subtract64 (a, b); /* subwus */ +} + +long do_sat_long_dot (long a, long b, long *p) +{ + long r = __builtin_saturate_subtract64 (a, b); /* subwus. */ + if (r == 0) + *p = 0; + + return r; +} + +void do_sat_long_dot2 (long a, long b, long *p, long *q) +{ + if (__builtin_saturate_subtract64 (a, b)) /* subwus. */ + *p = 0; + + *q = a + b; + return; +} + +/* { dg-final { scan-assembler {\msubdus\M} } } */ +/* { dg-final { scan-assembler-not {\msubf\M} } } */ -- 2.39.1 -- Michael Meissner, IBM PO Box 98, Ayer, Massachusetts, USA, 01432 email: meissner@linux.ibm.com