From patchwork Mon May 22 17:36:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Love X-Patchwork-Id: 97561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1633509vqo; Mon, 22 May 2023 11:12:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7W8UPa6SY0JEyf3GD6ohl+FrEZ8/mAKfNfjI6xKGBVROpZ09awm6eMfDm5XT9bHh+uBu31 X-Received: by 2002:aa7:d7d4:0:b0:50c:7fb:93cf with SMTP id e20-20020aa7d7d4000000b0050c07fb93cfmr9209140eds.12.1684779153924; Mon, 22 May 2023 11:12:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684779153; cv=none; d=google.com; s=arc-20160816; b=KnLjvJEYABjwwX8FmKnwnBoKKNIpDbeP2g2rEYNy/d9zE3JImi8FpvwJ+9QnYpi/Wc qpVBIDqJMX3k0AHLgnjLnPt46RwHb9nCc5yXO8CfUpJXq52LugE1Z7p3G7Ud7VFDsrnT DTgpvIzHBTCeLONWmm2CmI8xPP5Lh1m57kmLtfLxRcDzqScYk1dgszFoFgvV1UydLXln Q9lnBKN8LbzrRHJU+OvkC89DP0UVKjwl7hMZepsywz41DgKYv+9efTTtq4VZFdlK4dxm 4xp+xo49O0A6RmmYW4SuHFmgzXbcENcJlrAPtv5/bHT067cw3UlnaTF+01AwP6/J6+w9 G/ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to:date :cc:to:subject:message-id:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=zpgp21Ns2976jZRlDjB58YEpHhrYuJdlgQ7CKZrHn7g=; b=zuluwVqhFUnA25XLHGim/2G3biMEoKV4QgSqaB4ffzkHQFtLlVu91HZae//aSl1TYQ L85jZQg6AevojySXqT8A491/mgs0wqwXgFvE2PBFfG0Kw5ahmYF3tC3JcciAhZ1sdHMJ H5/9X4wEf9p0/vc5hAe8U/VJsro0L3KkWV57lW7rC8nY0T8nE/nSGYA4qLmX0RX0K9HQ bvLPs8GLNv85og7yA44PP/RPU13YaeOtvh5iIQ3aBhvNaRxOofMvyjB2NJuXSSt6BkC5 JV0pSO3t3jmI60/augzzFFk7QCoMCT+43O+jGYfgfjlYKbJSBswceFCOlTmu9/HzYvK0 YXwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Rez6NzcN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j26-20020aa7c41a000000b0050bf6020dcasi4976800edq.639.2023.05.22.11.12.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 11:12:33 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Rez6NzcN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D29DB385842D for ; Mon, 22 May 2023 18:12:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D29DB385842D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684779152; bh=zpgp21Ns2976jZRlDjB58YEpHhrYuJdlgQ7CKZrHn7g=; h=Subject:To:Cc:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Rez6NzcNvFK9vtgBR4qIDC9PvvFRhPCCXb/QPL0PlgLI4iirk+ZaQstooqB0e+zYf PJqigXhtEfKtqipUmL9gT67c30kANbPzyEkFChAHUk/cFC63Kgqs8sn8u+HMNL27lK icsBa1Nts2v2Qwram9Bzs1F6wa9z5UuPh8365+VY= 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 4635A3858D35 for ; Mon, 22 May 2023 18:11:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4635A3858D35 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34MI1Rub025338; Mon, 22 May 2023 18:11:44 GMT Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qrdacg8uq-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 May 2023 18:11:44 +0000 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34MHAM5C016415; Mon, 22 May 2023 17:36:53 GMT Received: from smtprelay04.dal12v.mail.ibm.com ([9.208.130.102]) by ppma01dal.us.ibm.com (PPS) with ESMTPS id 3qppdsp4rx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 May 2023 17:36:53 +0000 Received: from smtpav05.wdc07v.mail.ibm.com (smtpav05.wdc07v.mail.ibm.com [10.39.53.232]) by smtprelay04.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34MHaplv58261952 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 May 2023 17:36:52 GMT Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 983D658063; Mon, 22 May 2023 17:36:51 +0000 (GMT) Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 12FBE5806B; Mon, 22 May 2023 17:36:51 +0000 (GMT) Received: from li-e362e14c-2378-11b2-a85c-87d605f3c641.ibm.com (unknown [9.163.31.184]) by smtpav05.wdc07v.mail.ibm.com (Postfix) with ESMTP; Mon, 22 May 2023 17:36:50 +0000 (GMT) Message-ID: <79d6f621a9f0420fb3f2571eaa65f9d332dd7545.camel@us.ibm.com> Subject: [PATCH v3] rs6000: Add buildin for mffscrn instructions To: "Kewen.Lin" Cc: Peter Bergner , Segher Boessenkool , gcc-patches@gcc.gnu.org Date: Mon, 22 May 2023 10:36:50 -0700 In-Reply-To: References: X-Mailer: Evolution 3.28.5 (3.28.5-18.el8) Mime-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: xbT50irScEGomuey2tlkjLY57CfcVya- X-Proofpoint-ORIG-GUID: xbT50irScEGomuey2tlkjLY57CfcVya- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-22_12,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 priorityscore=1501 phishscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 mlxlogscore=831 impostorscore=0 bulkscore=0 clxscore=1015 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305220134 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Carl Love via Gcc-patches From: Carl Love Reply-To: Carl Love Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763095487484146316?= X-GMAIL-MSGID: =?utf-8?q?1766618986033625735?= Kewen, Segher, GCC maintainers: Version 3, fixed various issues noted by Kewen. Retested on Power 10. No regression issues. Version 2, Fixed an issue with the test case. The dg-options line was missing. The following patch adds an overloaded builtin. There are two possible arguments for the builtin. The builtin definitions are: double __builtin_mffscrn (unsigned long int); double __builtin_mffscrn (double); The patch has been tested on Power 10 with no regressions. Please let me know if the patch is acceptable for mainline. Thanks. Carl ------------------------------------------- rs6000: Add builtin for mffscrn instructions This patch adds overloaded __builtin_mffscrn for the move From FPSCR Control & Set RN instruction with an immediate argument. It also adds the builtin with a floating point register argument. A new runnable test is added for the new builtin. gcc/ * config/rs6000/rs6000-builtins.def (__builtin_mffscrni, __builtin_mffscrnd): Add builtin definitions. * config/rs6000/rs6000-overload.def (__builtin_mffscrn): Add overloaded definition. * doc/extend.texi: Add documentation for __builtin_mffscrn. gcc/testsuite/ * gcc.target/powerpc/builtin-mffscrn.c: Add testcase for new builtin. --- gcc/config/rs6000/rs6000-builtins.def | 9 +- gcc/config/rs6000/rs6000-overload.def | 5 + gcc/doc/extend.texi | 10 ++ .../gcc.target/powerpc/builtin-mffscrn.c | 106 ++++++++++++++++++ 4 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/builtin-mffscrn.c diff --git a/gcc/config/rs6000/rs6000-builtins.def b/gcc/config/rs6000/rs6000-builtins.def index 92d9b46e1b9..ae08d2fbff7 100644 --- a/gcc/config/rs6000/rs6000-builtins.def +++ b/gcc/config/rs6000/rs6000-builtins.def @@ -2849,6 +2849,14 @@ const signed int __builtin_vsx_scalar_extract_exp (double); VSEEDP xsxexpdp_si {} +; Immediate instruction only uses the least significant two bits of the +; const int. + double __builtin_mffscrni (const int<2>); + MFFSCRNI rs6000_mffscrni {nosoft} + + double __builtin_mffscrnd (double); + MFFSCRNF rs6000_mffscrn {nosoft} + [power9-64] void __builtin_altivec_xst_len_r (vsc, void *, long); XST_LEN_R xst_len_r {} @@ -2875,7 +2883,6 @@ pure vsc __builtin_vsx_xl_len_r (void *, signed long); XL_LEN_R xl_len_r {} - ; Builtins requiring hardware support for IEEE-128 floating-point. [ieee128-hw] fpmath _Float128 __builtin_addf128_round_to_odd (_Float128, _Float128); diff --git a/gcc/config/rs6000/rs6000-overload.def b/gcc/config/rs6000/rs6000-overload.def index 26dc662b8fb..39423bcec2b 100644 --- a/gcc/config/rs6000/rs6000-overload.def +++ b/gcc/config/rs6000/rs6000-overload.def @@ -78,6 +78,11 @@ ; like after a required newline, but nowhere else. Lines beginning with ; a semicolon are also treated as blank lines. +[MFFSCR, __builtin_mffscrn, __builtin_mffscrn] + double __builtin_mffscrn (const int<2>); + MFFSCRNI + double __builtin_mffscrn (double); + MFFSCRNF [BCDADD, __builtin_bcdadd, __builtin_vec_bcdadd] vsq __builtin_vec_bcdadd (vsq, vsq, const int); diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index ed8b9c8a87b..82f9932666a 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -18274,6 +18274,16 @@ The @code{__builtin_recipdiv}, and @code{__builtin_recipdivf} functions generate multiple instructions to implement division using the reciprocal estimate instructions. +double __builtin_mffscrn (const int); +double __builtin_mffscrn (double); + +The @code{__builtin_mffscrn} returns the contents of the control bits DRN, VE, +OE, UE, ZE, XE, NI, RN in the FPSCR are returned with RN updated appropriately. +In the case of the const int variant of the builtin, RN is set to the 2-bit +value specified in the builtin. In the case of the double builtin variant, the +2-bit value in the double argument that corresponds to the RN location in the +FPSCR is updated. + The following functions require @option{-mhard-float} and @option{-mmultiple} options. diff --git a/gcc/testsuite/gcc.target/powerpc/builtin-mffscrn.c b/gcc/testsuite/gcc.target/powerpc/builtin-mffscrn.c new file mode 100644 index 00000000000..69a7a17cfc7 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/builtin-mffscrn.c @@ -0,0 +1,106 @@ +/* { dg-do run } */ +/* { dg-require-effective-target p9modulo_hw } */ +/* { dg-options "-mdejagnu-cpu=power9" } */ + +#include + +#ifdef DEBUG +#include +#endif + +#define MASK 0x3 +#define EXPECTED1 0x1 +#define EXPECTED2 0x2 + +void abort (void); + +int +main() +{ + unsigned long mask, result, expected; + double double_arg; + + union convert_t { + double d; + unsigned long ul; + } val; + + /* Test immediate version of __builtin_mffscrn. */ + /* Read FPSCR and set RN bits in FPSCR[62:63]. */ + val.d = __builtin_mffscrn (EXPECTED2); + + /* Read FPSCR, bits [62:63] should have been set to 0x2 by previous builtin + call. */ + val.d = __builtin_mffscrn (EXPECTED1); + /* The expected result is the argument for the previous call to + __builtin_mffscrn. */ + expected = EXPECTED2; + result = MASK & val.ul; + + if (EXPECTED2 != result) +#ifdef DEBUG + printf("Result of mffscrn immediate doesn't match EXPECTED2. Result was 0x%lx\n", + result); +#else + abort(); +#endif + + /* Read FPSCR, bits [62:63] should have been set to 0x1 by previous builtin + call*/ + val.d = __builtin_mffscrn (EXPECTED1); + expected = EXPECTED1; + result = MASK & val.ul; + + if (EXPECTED1 != result) +#ifdef DEBUG + printf("Result of mffscrn immediate doesn't match EXPECTED1. Result was 0x%lx\n", + result); +#else + abort(); +#endif + + + /* Test double argument version of __builtin_mffscrn */ + val.ul = EXPECTED2; + double_arg = val.d; + + /* Read FPSCR and set RN bits in FPSCR[62:63]. */ + val.d = __builtin_mffscrn (double_arg); + + /* Read FPSCR, bits [62:63] should have been set to 0x2 by previous builtin + call. */ + + val.ul = EXPECTED1; + double_arg = val.d; + + val.d = __builtin_mffscrn (double_arg); + /* The expected result is the argument for the previous call to + __builtin_mffscrn. */ + expected = EXPECTED2; + result = MASK & val.ul; + + if (EXPECTED2 != result) +#ifdef DEBUG + printf("Result of mffscrn double arg doesn't match EXPECTED2. Result was 0x%lx\n", + result); +#else + abort(); +#endif + + /* Read FPSCR, bits [62:63] should have been set to 0x1 by previous builtin + call*/ + val.ul = EXPECTED1; + double_arg = val.d; + + val.d = __builtin_mffscrn (double_arg); + expected = EXPECTED1; + result = MASK & val.ul; + + if (EXPECTED1 != result) +#ifdef DEBUG + printf("Result of mffscrn double arg doesn't match EXPECTED1. Result was 0x%lx\n", + result); +#else + abort(); +#endif +}