From patchwork Thu May 18 21:12:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Love X-Patchwork-Id: 96049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp802007vqo; Thu, 18 May 2023 14:13:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7k4nBtDLbAxD9DqAAUHt9t9WsmyCcUYYNwBZGZNCPr9RsTXQHe0tnOkD9S46Kq33tVJ7fC X-Received: by 2002:aa7:c2d9:0:b0:510:f6e0:7d9f with SMTP id m25-20020aa7c2d9000000b00510f6e07d9fmr363103edp.13.1684444421212; Thu, 18 May 2023 14:13:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684444421; cv=none; d=google.com; s=arc-20160816; b=GerNl9Kg/nh+9r2YPUd1zXrFratox7NPw1CmYKeHxnkf/ncjsm83eLBUsIteoH7+Xp 3HgkTlUwLnlocSz6BKhpc2HdAQs9ZqY2slcYiU2c5+aYbuGgEFEtXLZJPhpN6V1PQ4O0 wPX6YOhlDQSjoE0Q6PGKX/mrWyNN01uo8kVQg+bS5NrxKA8QR9I4FMBhDNQd6Oyg6JbJ OFWhghT8RwYQ/iWN9ovCGcbxBLNbZVGQ418+bH189a1i3Mqta13F4mSYEHIZxlTO1Vty ZP08COZAnIwPFg/ZQ3IUzQJ4D5JWzILC0NcsWsSwzWAJHQAgewet0fuot4CM3cF1rJh8 3rBw== 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=AqYPABS0/4tOFfZjUdwAgex4Th7fEOVLc76Puqi3c0E=; b=LMHyR11E30768Fxt1QXfIy8j1YVuJJZamjVxD75Fx02s1bybNIFvprv6Zew6AP1T7L 1CdiW+UPJnpb2stQmkFE1rZLL3JriiBY4koPeIlTT55kBa3pQAHWRQM9xgwK9UoZm2za ziMuWw7Mrm/+/DK1URRnSkYJhc8svdBK3XHL3CXO2bbpBuZ0q+j7XLNwNzHwqREqXFoJ AA0k2Q/6jcSTHHa9DYULnE2Kh+AWoPZ17mR/swA3mZw+aurKM/hA2zDNKofgrowY6opa IgS5yFmsL0mlMLAO4j/h5XzZie3Ly95gK+Deq3qrlUROp1b7Unfm/7jHxCP297Lmj/VV F7wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JLEMwOx0; 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 b13-20020a05640202cd00b0050478011989si1768924edx.150.2023.05.18.14.13.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 14:13:41 -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=JLEMwOx0; 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 10CAD3857344 for ; Thu, 18 May 2023 21:13:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 10CAD3857344 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684444420; bh=AqYPABS0/4tOFfZjUdwAgex4Th7fEOVLc76Puqi3c0E=; 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=JLEMwOx0uZdSwT0GGu1ZI99rxMSPvHNsoPj90TMyTSu4wKZaL8YygOp2LkecNA53z i12D1xRVTKwNNek503aCTAPJlXXfI9wZwBKmzBe6p363Ks1BxnMsVjrR0K2jv8bAlN BLSc2dGGGY2h6125dbNydI+PYVEzXx/wcboHC8zc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id E64D63856DE2 for ; Thu, 18 May 2023 21:12:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E64D63856DE2 Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34IL9aJc013936; Thu, 18 May 2023 21:12:54 GMT Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qnudsghw1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 May 2023 21:12:54 +0000 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 34IKKpOf017804; Thu, 18 May 2023 21:12:53 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([9.208.130.97]) by ppma05wdc.us.ibm.com (PPS) with ESMTPS id 3qj26649mg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 May 2023 21:12:53 +0000 Received: from smtpav02.dal12v.mail.ibm.com (smtpav02.dal12v.mail.ibm.com [10.241.53.101]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 34ILCqg025494146 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 May 2023 21:12:52 GMT Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 667B35805C; Thu, 18 May 2023 21:12:52 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 18DBE5805A; Thu, 18 May 2023 21:12:52 +0000 (GMT) Received: from li-e362e14c-2378-11b2-a85c-87d605f3c641.ibm.com (unknown [9.163.31.184]) by smtpav02.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 18 May 2023 21:12:52 +0000 (GMT) Message-ID: Subject: [PATCH v2] rs6000: Add buildin for mffscrn instructions To: Segher Boessenkool , gcc-patches@gcc.gnu.org Cc: Peter Bergner Date: Thu, 18 May 2023 14:12:51 -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: YstBHnDKDGGS-oTd2DjW3qg_RaDsC9Cl X-Proofpoint-ORIG-GUID: YstBHnDKDGGS-oTd2DjW3qg_RaDsC9Cl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-18_15,2023-05-17_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 impostorscore=0 suspectscore=0 phishscore=0 adultscore=0 mlxlogscore=629 priorityscore=1501 bulkscore=0 spamscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305180173 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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?1766267993758672876?= GCC maintainers: 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 buildin for mffscrn instructions This patch adds overloaded __builtin_mffscrn for the move From FPSCR Control & Set R 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 | 7 ++ gcc/config/rs6000/rs6000-overload.def | 5 + gcc/doc/extend.texi | 8 ++ .../gcc.target/powerpc/builtin-mffscrn.c | 106 ++++++++++++++++++ 4 files changed, 126 insertions(+) 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..67125473684 100644 --- a/gcc/config/rs6000/rs6000-builtins.def +++ b/gcc/config/rs6000/rs6000-builtins.def @@ -2875,6 +2875,13 @@ pure vsc __builtin_vsx_xl_len_r (void *, signed long); XL_LEN_R xl_len_r {} +; Immediate instruction only uses the least significant two bits of the +; const int. + double __builtin_mffscrni (const int<2>); + MFFSCRNI rs6000_mffscrni {} + + double __builtin_mffscrnd (double); + MFFSCRNF rs6000_mffscrn {} ; Builtins requiring hardware support for IEEE-128 floating-point. [ieee128-hw] diff --git a/gcc/config/rs6000/rs6000-overload.def b/gcc/config/rs6000/rs6000-overload.def index c582490c084..adda2df69ea 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..f16c046051a 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -18455,6 +18455,9 @@ int __builtin_dfp_dtstsfi_ov_td (unsigned int comparison, _Decimal128 value); double __builtin_mffsl(void); +double __builtin_mffscrn (unsigned long int); +double __builtin_mffscrn (double); + @end smallexample The @code{__builtin_byte_in_set} function requires a 64-bit environment supporting ISA 3.0 or later. This function returns @@ -18511,6 +18514,11 @@ the FPSCR. The instruction is a lower latency version of the @code{mffs} instruction. If the @code{mffsl} instruction is not available, then the builtin uses the older @code{mffs} instruction to read the FPSCR. +The @code{__builtin_mffscrn} returns the contents of the control bits in the +FPSCR, bits 29:31 (DRN) and bits 56:63 (VE, OE, UE, ZE, XE, NI, RN). The +contents of bits [62:63] of the unsigned long int or double argument are placed +into bits [62:63] of the FPSCR (RN). + @node Basic PowerPC Built-in Functions Available on ISA 3.1 @subsubsection Basic PowerPC Built-in Functions Available on ISA 3.1 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..26c666a4091 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/builtin-mffscrn.c @@ -0,0 +1,106 @@ +/* { dg-do run } */ +/* { dg-require-effective-target p9vector_hw } */ +/* { dg-options "-mpower9-vector -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 +}