From patchwork Mon Dec 12 03:16:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hurugalawadi, Naveen" X-Patchwork-Id: 87623 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1438427qgi; Sun, 11 Dec 2016 19:17:08 -0800 (PST) X-Received: by 10.99.164.9 with SMTP id c9mr164640382pgf.141.1481512628554; Sun, 11 Dec 2016 19:17:08 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id m5si41828943pgk.293.2016.12.11.19.17.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Dec 2016 19:17:08 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-444120-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-444120-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-444120-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:references:in-reply-to :content-type:mime-version; q=dns; s=default; b=VEN6tkv725cTj7Cf scgfhNZwqo3FqQ5I8k86CmRS3wbZsuECmZVjcQj5x2TCwwl5gSQyDiF5Wv3P49ua +8w3L71olPEianQ5solp7LH8YmLy4XSWKquG2FGEu26D2oLqj7VaRLrrNpttDxTL ruq5oY3yK4+OvTxWBY15tgCf6Gc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:references:in-reply-to :content-type:mime-version; s=default; bh=E44oqYeTtpEYSR1zMXjKog dIRz0=; b=dGtTQa+oWFC0rhynS3GQIt60uTkhLZhJo/cLZ9tiG8WjGPRgoEOXHL x5zxz19k6TejdkoODj1HSmfNPd2mw1Ur3IQBb6incrG9LYpmLhaOO4tCwcK/TRu9 s/CcLqicQUz5n0CLBqn/bB1v68M++mfGYH5xqx/bxZtf7/wdxlPbU= Received: (qmail 65842 invoked by alias); 12 Dec 2016 03:16:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 65787 invoked by uid 89); 12 Dec 2016 03:16:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=2016-12-12, apinski@cavium.com, apinskicaviumcom, HX-MS-Has-Attach:yes X-HELO: NAM02-BL2-obe.outbound.protection.outlook.com Received: from mail-bl2nam02on0065.outbound.protection.outlook.com (HELO NAM02-BL2-obe.outbound.protection.outlook.com) (104.47.38.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Dec 2016 03:16:35 +0000 Received: from CO2PR07MB2694.namprd07.prod.outlook.com (10.166.214.7) by BL2PR07MB2305.namprd07.prod.outlook.com (10.167.101.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.771.8; Mon, 12 Dec 2016 03:16:31 +0000 Received: from CO2PR07MB2694.namprd07.prod.outlook.com ([10.166.214.7]) by CO2PR07MB2694.namprd07.prod.outlook.com ([10.166.214.7]) with mapi id 15.01.0771.014; Mon, 12 Dec 2016 03:16:30 +0000 From: "Hurugalawadi, Naveen" To: "gcc-patches@gcc.gnu.org" CC: "Pinski, Andrew" , James Greenhalgh , Marcus Shawcroft , Richard Earnshaw Subject: [PATCH] [AArch64] Implement popcount pattern Date: Mon, 12 Dec 2016 03:16:30 +0000 Message-ID: References: In-Reply-To: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Naveen.Hurugalawadi@cavium.com; x-microsoft-exchange-diagnostics: 1; BL2PR07MB2305; 7:yjpocsNaIMGX0Gn3dkhHvu3B48pTpIEkH+8DfwwwzugzCDVGudRXLJWjCFY5690gez1CTI4y/eRsEjiWOXTxtPdbOotoa0Mc++VsXoWNET8Jv1uwJkWucOadsSak0/f/APU51sqGQFpaSQKoT7F/xcYohPx0tW3LDiRvlHDUmhz6dSgcEiQ3lpwiCGcdn5Act9VWKfqFaPGvap8gtKPg3GU0csI4cBednV4GzQhb4FZEIxBqGz7yxKs24qjk8vv7lzYcFYAG23RdhJEhmBW5G/l46gXdv9ide80MFQGFYhxkXpMOMKnP9QBqeTyRp3nWVTuQuCO+wPLsKNqt+RGVcSSv+XCqJPoK++XcyXTnEV6XS36G105acJ8vcBB3e///iuk4Gy8MjipjUqrNEgNbFamotWJ9JFS3Pz2+aEkbLi3G1cnyITd9Srt/53r8AghNClnycEel8wMdWbvN0Otf9A== x-forefront-antispam-report: SFV:SKI; SCL:-1SFV:NSPM; SFS:(10009020)(6009001)(7916002)(39840400002)(39450400003)(39410400002)(199003)(377424004)(189002)(6506006)(3846002)(106116001)(6436002)(33656002)(106356001)(9686002)(76576001)(102836003)(101416001)(105586002)(81156014)(99286002)(4001150100001)(6116002)(81166006)(76176999)(5660300001)(8936002)(54356999)(50986999)(38730400001)(8676002)(99936001)(2501003)(66066001)(3280700002)(189998001)(97736004)(77096006)(68736007)(2900100001)(7736002)(74316002)(5890100001)(122556002)(110136003)(92566002)(3660700001)(4326007)(2906002)(305945005)(6916009)(2950100002)(86362001)(7696004)(2351001); DIR:OUT; SFP:1101; SCL:1; SRVR:BL2PR07MB2305; H:CO2PR07MB2694.namprd07.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; x-ms-office365-filtering-correlation-id: 3e4cad18-e47e-40d2-5456-08d4223d44b9 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BL2PR07MB2305; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(102415395)(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6041248)(20161123555025)(20161123562025)(20161123564025)(20161123560025)(6072148); SRVR:BL2PR07MB2305; BCL:0; PCL:0; RULEID:; SRVR:BL2PR07MB2305; x-forefront-prvs: 0154C61618 received-spf: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Dec 2016 03:16:30.3064 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR07MB2305 Hi, Please find attached the patch that implements the support for popcount patterns in AArch64. The implementation improves OVS-DPDK on ThunderX by 3%. It would have a similar effect on other AArch64 targets. Please review the patch and let us know if its okay? 2016-12-12 Andrew Pinski gcc * config/aarch64/aarch64.md (popcount2): New pattern. gcc/testsuite * gcc.target/aarch64/popcount.c : New Testcase. diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index 65eb326..c688ddc 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -3785,6 +3785,39 @@ } ) +/* Pop count be done via the pop count instruction in NEON. */ +/* + mov v.1d, x0 + Cnt v1.8b, v.8b + Addv b2, v1.8b + Mov w0, v2.b[0] +*/ +(define_expand "popcount2" + [(match_operand:GPI 0 "register_operand") + (match_operand:GPI 1 "register_operand")] + "TARGET_SIMD" +{ + rtx v = gen_reg_rtx (V8QImode); + rtx v1 = gen_reg_rtx (V8QImode); + rtx r = gen_reg_rtx (QImode); + rtx in = operands[1]; + rtx out = operands[0]; + if(mode == SImode) + { + rtx tmp; + tmp = gen_reg_rtx (DImode); + /* If we have SImode, zero extend to DImode, pop count does + not change if we have extra zeros. */ + emit_insn (gen_zero_extendsidi2 (tmp, in)); + in = tmp; + } + emit_move_insn (v, gen_lowpart (V8QImode, in)); + emit_insn (gen_popcountv8qi2 (v1, v)); + emit_insn (gen_reduc_plus_scal_v8qi (r, v1)); + emit_insn (gen_zero_extendqi2 (out, r)); + DONE; +}) + (define_insn "clrsb2" [(set (match_operand:GPI 0 "register_operand" "=r") (clrsb:GPI (match_operand:GPI 1 "register_operand" "r")))] diff --git a/gcc/testsuite/gcc.target/aarch64/popcount.c b/gcc/testsuite/gcc.target/aarch64/popcount.c new file mode 100644 index 0000000..2d71168 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/popcount.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int foo(int x) +{ + return __builtin_popcount(x); +} + +/* { dg-final { scan-assembler-not "popcountdi2" } } */ +/* { dg-final { scan-assembler "cnt\t" } } */