From patchwork Fri May 8 13:17:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 1286133 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=fSRA0jCQ; 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 49JW8f66HxzB3sv for ; Fri, 8 May 2020 23:17:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B6113851C14; Fri, 8 May 2020 13:17:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B6113851C14 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588943856; bh=RuK+0Sky6NO1CSf9PY/7itwzgXBVwiEeqwpW9JQOhUI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=fSRA0jCQtkU+DG4EXB0sF5E0FIJtYXN6pQO1aEM5wQLb6uubuf6GeTpfw6FQOrhGC 2l6NqNnreQszt7mrX99wRavJcugzujPww5MsagbNVDHw44lITCOv3C1wOsucMj203z PsaLeFM8ZXH7SoPfjPZJXahMOiOXKiLvClEsq6WA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id DFFC83851C02 for ; Fri, 8 May 2020 13:17:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DFFC83851C02 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 048D4RTt173294; Fri, 8 May 2020 09:17:24 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 30vtveme58-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 May 2020 09:17:24 -0400 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 048D4Z47173921; Fri, 8 May 2020 09:17:24 -0400 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0b-001b2d01.pphosted.com with ESMTP id 30vtveme4s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 May 2020 09:17:23 -0400 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 048DFPdK028043; Fri, 8 May 2020 13:17:23 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma04dal.us.ibm.com with ESMTP id 30s0g7pq69-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 May 2020 13:17:23 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 048DHMFn14549658 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 8 May 2020 13:17:22 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 289B228067; Fri, 8 May 2020 13:17:22 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 04FCF2805C; Fri, 8 May 2020 13:17:21 +0000 (GMT) Received: from localhost (unknown [9.40.194.84]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 8 May 2020 13:17:21 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] rs6000: Add cntlzdm and cnttzdm Date: Fri, 8 May 2020 08:17:18 -0500 Message-Id: <20200508131718.24294-1-wschmidt@linux.ibm.com> X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.676 definitions=2020-05-08_12:2020-05-08, 2020-05-08 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 mlxscore=0 suspectscore=1 spamscore=0 adultscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 malwarescore=0 clxscore=1015 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005080111 X-Spam-Status: No, score=-13.2 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: Bill Schmidt via Gcc-patches From: Bill Schmidt Reply-To: Bill Schmidt Cc: dje.gcc@gmail.com, segher@kernel.crashing.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" From: Kelvin Nilsen Add support for new scalar instructions for counting leading or trailing zeros under control of a bitmask. Bootstrapped and tested on powerpc64le-unknown-linux-gnu with no regressions. Is this okay for master? Thanks, Bill [gcc] 2020-05-08 Kelvin Nilsen * config/rs6000/rs6000-builtin.def (__builtin_cntlzdm): New built-in function definition. (__builtin_cnttzdm): Likewise., * config/rs6000/rs6000.md (UNSPEC_CNTLZDM): New constant. (UNSPEC_CNTTZDM): Likewise. (cntlzdm): New insn. (cnttzdm): Likewise. * doc/extend.texi (Basic PowerPC Built-in Functions available for a Future Architecture): Add descriptions of __builtin_cntlzdm and __builtin_cnttzdm functions. [gcc/testsuite] 2020-05-08 Kelvin Nilsen * gcc.target/powerpc/cntlzdm-0.c: New test. * gcc.target/powerpc/cntlzdm-1.c: New test. * gcc.target/powerpc/cnttzdm-0.c: New test. * gcc.target/powerpc/cnttzdm-1.c: New test. --- gcc/config/rs6000/rs6000-builtin.def | 2 + gcc/config/rs6000/rs6000.md | 20 +++++++ gcc/doc/extend.texi | 16 ++++++ gcc/testsuite/gcc.target/powerpc/cntlzdm-0.c | 57 ++++++++++++++++++++ gcc/testsuite/gcc.target/powerpc/cntlzdm-1.c | 56 +++++++++++++++++++ gcc/testsuite/gcc.target/powerpc/cnttzdm-0.c | 53 ++++++++++++++++++ gcc/testsuite/gcc.target/powerpc/cnttzdm-1.c | 53 ++++++++++++++++++ 7 files changed, 257 insertions(+) create mode 100644 gcc/testsuite/gcc.target/powerpc/cntlzdm-0.c create mode 100644 gcc/testsuite/gcc.target/powerpc/cntlzdm-1.c create mode 100644 gcc/testsuite/gcc.target/powerpc/cnttzdm-0.c create mode 100644 gcc/testsuite/gcc.target/powerpc/cnttzdm-1.c diff --git a/gcc/config/rs6000/rs6000-builtin.def b/gcc/config/rs6000/rs6000-builtin.def index 9d80d03fe50..c05d9f53d54 100644 --- a/gcc/config/rs6000/rs6000-builtin.def +++ b/gcc/config/rs6000/rs6000-builtin.def @@ -2575,6 +2575,8 @@ BU_P9_OVERLOAD_2 (CMPEQB, "byte_in_set") /* Future architecture scalar built-ins. */ BU_FUTURE_MISC_2 (CFUGED, "cfuged", CONST, cfuged) +BU_FUTURE_MISC_2 (CNTLZDM, "cntlzdm", CONST, cntlzdm) +BU_FUTURE_MISC_2 (CNTTZDM, "cnttzdm", CONST, cnttzdm) /* Future architecture vector built-ins. */ BU_FUTURE_V_2 (VCFUGED, "vcfuged", CONST, vcfuged) diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index 001ec27f403..19b3d7263d3 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -149,6 +149,8 @@ (define_c_enum "unspec" UNSPEC_PLTSEQ UNSPEC_PLT16_HA UNSPEC_CFUGED + UNSPEC_CNTLZDM + UNSPEC_CNTTZDM ]) ;; @@ -2463,6 +2465,24 @@ (define_insn "cfuged" "cfuged %0,%1,%2" [(set_attr "type" "integer")]) +(define_insn "cntlzdm" + [(set (match_operand:DI 0 "gpc_reg_operand" "=r") + (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "r") + (match_operand:DI 2 "gpc_reg_operand" "r")] + UNSPEC_CNTLZDM))] + "TARGET_FUTURE && TARGET_64BIT" + "cntlzdm %0,%1,%2" + [(set_attr "type" "integer")]) + +(define_insn "cnttzdm" + [(set (match_operand:DI 0 "gpc_reg_operand" "=r") + (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "r") + (match_operand:DI 2 "gpc_reg_operand" "r")] + UNSPEC_CNTTZDM))] + "TARGET_FUTURE && TARGET_64BIT" + "cnttzdm %0,%1,%2" + [(set_attr "type" "integer")]) + (define_insn "cmpb3" [(set (match_operand:GPR 0 "gpc_reg_operand" "=r") (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r") diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index f7b30c7ead7..8c833d39fec 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -17556,6 +17556,22 @@ Perform a 64-bit centrifuge operation, as if implemented by the Future @code{cfuged} instruction. @findex __builtin_cfuged +@smallexample +@exdent unsigned long long int +@exdent __builtin_cntlzdm (unsigned long long int, unsigned long long int) +@end smallexample +Perform a 64-bit count leading zeros operation under mask, as if +implemented by the future @code{cntlzdm} instruction. +@findex __builtin_cntlzdm + +@smallexample +@exdent unsigned long long int +@exdent __builtin_cnttzdm (unsigned long long int, unsigned long long int) +@end smallexample +Perform a 64-bit count trailing zeros operation under mask, as if +implemented by the future @code{cnttzdm} instruction. +@findex __builtin_cnttzdm + @node PowerPC AltiVec/VSX Built-in Functions @subsection PowerPC AltiVec/VSX Built-in Functions diff --git a/gcc/testsuite/gcc.target/powerpc/cntlzdm-0.c b/gcc/testsuite/gcc.target/powerpc/cntlzdm-0.c new file mode 100644 index 00000000000..e3ce63c3447 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/cntlzdm-0.c @@ -0,0 +1,57 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-options "-mdejagnu-cpu=future" } */ + +extern void abort (void); + +unsigned long long int +do_cntlzdm (unsigned long long int source, unsigned long long int mask) +{ + return __builtin_cntlzdm (source, mask); +} + +int main (int argc, char *argv []) +{ + unsigned long long int sources [4], masks [4]; + unsigned long long int intermediates [4][4] = { + /* sources[0] with each of masks [0 .. 3] */ + { 0x0000a5f0ll, 0x00007e3cll, 0x000050ecll, 0x0000af73ll }, + /* sources[1] with each of masks [0 .. 3] */ + { 0x00007e3cll, 0x0000a5f0ll, 0x0000ec50ll, 0x000073afll }, + /* sources[2] with each of masks [0 .. 3] */ + { 0x00003ca5ll, 0x0000f07ell, 0x0000c50ell, 0x00003af7ll }, + /* sources[3] with each of masks [0 .. 3] */ + { 0x00005a0fll, 0x0000e7c3ll, 0x0000af73ll, 0x000050ecll }, + }; + unsigned long long int results [4][4] = { + { 0, 1, 1, 0 }, + { 1, 0, 0, 1 }, + { 2, 0, 0, 2 }, + { 1, 0, 0, 1 }, + }; + + sources[0] = 0xa5f07e3cll; + sources[1] = 0x7e3ca5f0ll; + sources[2] = 0x3ca5f07ell; + sources[3] = 0x5a0fe7c3ll; + + masks[0] = 0xffff0000ll; + masks[1] = 0x0000ffffll; + masks[2] = 0x0f0f0f0fll; + masks[3] = 0xf0f0f0f0ll; + + unsigned long long int result; + + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + if (do_cntlzdm (sources[i], masks[j]) != results [i][j]) + abort (); + } + } + + return 0; +} + +/* { dg-final { scan-assembler {\mcntlzdm\M} } } */ diff --git a/gcc/testsuite/gcc.target/powerpc/cntlzdm-1.c b/gcc/testsuite/gcc.target/powerpc/cntlzdm-1.c new file mode 100644 index 00000000000..3239c386bb7 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/cntlzdm-1.c @@ -0,0 +1,56 @@ +/* { dg-do run } */ +/* { dg-require-effective-target powerpc_future_hw } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-options "-mdejagnu-cpu=future" } */ + +extern void abort (void); + +unsigned long long int +do_cntlzdm (unsigned long long int source, unsigned long long int mask) +{ + return __builtin_cntlzdm (source, mask); +} + +int main (int argc, char *argv []) +{ + unsigned long long int sources [4], masks [4]; + unsigned long long int intermediates [4][4] = { + /* sources[0] with each of masks [0 .. 3] */ + { 0x0000a5f0ll, 0x00007e3cll, 0x000050ecll, 0x0000af73ll }, + /* sources[1] with each of masks [0 .. 3] */ + { 0x00007e3cll, 0x0000a5f0ll, 0x0000ec50ll, 0x000073afll }, + /* sources[2] with each of masks [0 .. 3] */ + { 0x00003ca5ll, 0x0000f07ell, 0x0000c50ell, 0x00003af7ll }, + /* sources[3] with each of masks [0 .. 3] */ + { 0x00005a0fll, 0x0000e7c3ll, 0x0000af73ll, 0x000050ecll }, + }; + unsigned long long int results [4][4] = { + { 0, 1, 1, 0 }, + { 1, 0, 0, 1 }, + { 2, 0, 0, 2 }, + { 1, 0, 0, 1 }, + }; + + sources[0] = 0xa5f07e3cll; + sources[1] = 0x7e3ca5f0ll; + sources[2] = 0x3ca5f07ell; + sources[3] = 0x5a0fe7c3ll; + + masks[0] = 0xffff0000ll; + masks[1] = 0x0000ffffll; + masks[2] = 0x0f0f0f0fll; + masks[3] = 0xf0f0f0f0ll; + + unsigned long long int result; + + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + if (do_cntlzdm (sources[i], masks[j]) != results [i][j]) + abort (); + } + } + + return 0; +} diff --git a/gcc/testsuite/gcc.target/powerpc/cnttzdm-0.c b/gcc/testsuite/gcc.target/powerpc/cnttzdm-0.c new file mode 100644 index 00000000000..6601f1f6471 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/cnttzdm-0.c @@ -0,0 +1,53 @@ +/* { dg-do compile } */ +/* { dg-options "-mdejagnu-cpu=future" } */ + +extern void abort (void); + +unsigned long long int +do_cnttzdm (unsigned long long int source, unsigned long long int mask) { + return __builtin_cnttzdm (source, mask); +} + +int main (int argc, char *argv []) +{ + unsigned long long int sources [4], masks [4]; + unsigned long long int intermediates [4][4] = { + /* sources[0] with each of masks [0 .. 3] */ + { 0x0000a5f0ll, 0x00007e3cll, 0x000050ecll, 0x0000af73ll }, + /* sources[1] with each of masks [0 .. 3] */ + { 0x00007e3cll, 0x0000a5f0ll, 0x0000ec50ll, 0x000073afll }, + /* sources[2] with each of masks [0 .. 3] */ + { 0x00003ca5ll, 0x0000f07ell, 0x0000c50ell, 0x00003af7ll }, + /* sources[3] with each of masks [0 .. 3] */ + { 0x00005a0fll, 0x0000e7c3ll, 0x0000af73ll, 0x000050ecll }, + }; + unsigned long long int results [4][4] = { + { 4, 2, 2, 0 }, + { 2, 4, 4, 0 }, + { 0, 1, 1, 0 }, + { 0, 0, 0, 2 }, + }; + + sources[0] = 0xa5f07e3cll; + sources[1] = 0x7e3ca5f0ll; + sources[2] = 0x3ca5f07ell; + sources[3] = 0x5a0fe7c3ll; + + masks[0] = 0xffff0000ll; + masks[1] = 0x0000ffffll; + masks[2] = 0x0f0f0f0fll; + masks[3] = 0xf0f0f0f0ll; + + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + if (do_cnttzdm (sources[i], masks[j]) != results [i][j]) + abort (); + } + } + + return 0; +} + +/* { dg-final { scan-assembler {\mcnttzdm\M} } } */ diff --git a/gcc/testsuite/gcc.target/powerpc/cnttzdm-1.c b/gcc/testsuite/gcc.target/powerpc/cnttzdm-1.c new file mode 100644 index 00000000000..d04b1192d15 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/cnttzdm-1.c @@ -0,0 +1,53 @@ +/* { dg-do run } */ +/* { dg-require-effective-target powerpc_future_hw } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-options "-mdejagnu-cpu=future" } */ + +extern void abort (void); + +unsigned long long int +do_cnttzdm (unsigned long long int source, unsigned long long int mask) { + return __builtin_cnttzdm (source, mask); +} + +int main (int argc, char *argv []) +{ + unsigned long long int sources [4], masks [4]; + unsigned long long int intermediates [4][4] = { + /* sources[0] with each of masks [0 .. 3] */ + { 0x0000a5f0ll, 0x00007e3cll, 0x000050ecll, 0x0000af73ll }, + /* sources[1] with each of masks [0 .. 3] */ + { 0x00007e3cll, 0x0000a5f0ll, 0x0000ec50ll, 0x000073afll }, + /* sources[2] with each of masks [0 .. 3] */ + { 0x00003ca5ll, 0x0000f07ell, 0x0000c50ell, 0x00003af7ll }, + /* sources[3] with each of masks [0 .. 3] */ + { 0x00005a0fll, 0x0000e7c3ll, 0x0000af73ll, 0x000050ecll }, + }; + unsigned long long int results [4][4] = { + { 4, 2, 2, 0 }, + { 2, 4, 4, 0 }, + { 0, 1, 1, 0 }, + { 0, 0, 0, 2 }, + }; + + sources[0] = 0xa5f07e3cll; + sources[1] = 0x7e3ca5f0ll; + sources[2] = 0x3ca5f07ell; + sources[3] = 0x5a0fe7c3ll; + + masks[0] = 0xffff0000ll; + masks[1] = 0x0000ffffll; + masks[2] = 0x0f0f0f0fll; + masks[3] = 0xf0f0f0f0ll; + + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + if (do_cnttzdm (sources[i], masks[j]) != results [i][j]) + abort (); + } + } + + return 0; +}