From patchwork Wed Jul 1 13:06:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1320459 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=nextmovesoftware.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=EEXDsWA6; 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 49xhMH0cnjz9sQt for ; Wed, 1 Jul 2020 23:06:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 188B93857031; Wed, 1 Jul 2020 13:06:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 6A1C43857031 for ; Wed, 1 Jul 2020 13:06:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6A1C43857031 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=roger@nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=kZIzWufQHbKcYymyriv065TwVezBunLB2DaKqS9YvAY=; b=EEXDsWA6+jmsDJZwKqn8cUrPWu FjupHM4tgopOiaebAwaYT5fzwC30dAncFD2OjJrcF4y4+x/CXMziu6LKyNeNDFclKh+p2QDFkO+aS joh5+CFcV5bFBe9aYT68QXCa4MxK29gAUtwft+6lJz7riMKDZHSn8cUVOqL4KZgCgFs+vQewgglDr 4UEZWs3CUh4IkdRanJETJXHMvnwkhaOxklU8I/whpQZAaHQllDy+Ec8cdV6iWgmrQ9Q8KGBkmRY+D WNKRUhCTM8YvUva5z7ZFC9Wuig8hKpuKX65+rH9Z1W0YBz26TlBSAKEOrzlHRRdJnFYSySXV8WXC+ wkyy2d3g==; Received: from host86-137-89-56.range86-137.btcentralplus.com ([86.137.89.56]:64401 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1jqcRo-0006Qz-LP for gcc-patches@gcc.gnu.org; Wed, 01 Jul 2020 09:06:44 -0400 From: "Roger Sayle" To: Subject: [PATCH] nvptx: : Add support for popcount and widening multiply instructions Date: Wed, 1 Jul 2020 14:06:43 +0100 Message-ID: <000c01d64fa8$78551430$68ff3c90$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdZPpyyqSTmEW1MgQdOf9GJhq9SOnQ== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The following patch adds support for the popc and mul.wide instructions to the nvptx backend. I've a follow-up patch for supporting mul.hi instructions, but those changes require some minor tweaks to GCC's middle-end, so I'll submit those pieces separately. Tested by "make" and "make -k check" on --build=nvptx-none hosted on x86_64-pc-linux-gnu with no new regressions. 2020-07-01 Roger Sayle gcc/ChangeLog: * config/nvptx/nvptx.md (popcount2): New instructions. (mulhishi3, mulsidi3, umulhisi3, umulsidi3): New instructions. gcc/testsuite/ChangeLog: * gcc.target/nvptx/popc-1.c: New test. * gcc.target/nvptx/popc-2.c: New test. * gcc.target/nvptx/popc-3.c: New test. * gcc.target/nvptx/mul-wide.c: New test. * gcc.target/nvptx/umul-wide.c: New test. Ok for mainline? Thanks in advance, Roger --- Roger Sayle NextMove Software Cambridge, UK /* { dg-do compile } */ /* { dg-options "-O2" } */ unsigned int foo(unsigned int x) { return __builtin_popcount(x); } /* { dg-final { scan-assembler-times "popc.b32" 1 } } */ /* { dg-do compile } */ /* { dg-options "-O2" } */ unsigned long foo(unsigned long x) { return __builtin_popcountl(x); } /* { dg-final { scan-assembler-times "popc.b64" 1 } } */ /* { dg-final { scan-assembler-times "cvt.s64.s32" 1 } } */ /* { dg-do compile } */ /* { dg-options "-O2" } */ unsigned int foo(unsigned long x) { return __builtin_popcountl(x); } /* { dg-final { scan-assembler-times "popc.b64" 1 } } */ /* { dg-final { scan-assembler-times "cvt.s64.s32" 0 } } */ /* { dg-do compile } */ /* { dg-options "-O2" } */ int mulhisi3(short x, short y) { return (int)x * (int)y; } long mulsidi3(int x, int y) { return (long)x * (long)y; } /* { dg-final { scan-assembler-times "mul.wide.s16" 1 } } */ /* { dg-final { scan-assembler-times "mul.wide.s32" 1 } } */ /* { dg-do compile } */ /* { dg-options "-O2" } */ unsigned int umulhisi3(unsigned short x, unsigned short y) { return (unsigned int)x * (unsigned int)y; } unsigned long umulsidi3(unsigned int x, unsigned int y) { return (unsigned long)x * (unsigned long)y; } /* { dg-final { scan-assembler-times "mul.wide.u16" 1 } } */ /* { dg-final { scan-assembler-times "mul.wide.u32" 1 } } */ diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md index 089cdf0..5ceeac7 100644 --- a/gcc/config/nvptx/nvptx.md +++ b/gcc/config/nvptx/nvptx.md @@ -493,6 +493,50 @@ DONE; }) +(define_insn "popcount2" + [(set (match_operand:SI 0 "nvptx_register_operand" "=R") + (popcount:SI (match_operand:SDIM 1 "nvptx_register_operand" "R")))] + "" + "%.\\tpopc.b%T1\\t%0, %1;") + +;; Multiplication variants + +(define_insn "mulhisi3" + [(set (match_operand:SI 0 "nvptx_register_operand" "=R") + (mult:SI (sign_extend:SI + (match_operand:HI 1 "nvptx_register_operand" "R")) + (sign_extend:SI + (match_operand:HI 2 "nvptx_register_operand" "R"))))] + "" + "%.\\tmul.wide.s16\\t%0, %1, %2;") + +(define_insn "mulsidi3" + [(set (match_operand:DI 0 "nvptx_register_operand" "=R") + (mult:DI (sign_extend:DI + (match_operand:SI 1 "nvptx_register_operand" "R")) + (sign_extend:DI + (match_operand:SI 2 "nvptx_register_operand" "R"))))] + "" + "%.\\tmul.wide.s32\\t%0, %1, %2;") + +(define_insn "umulhisi3" + [(set (match_operand:SI 0 "nvptx_register_operand" "=R") + (mult:SI (zero_extend:SI + (match_operand:HI 1 "nvptx_register_operand" "R")) + (zero_extend:SI + (match_operand:HI 2 "nvptx_register_operand" "R"))))] + "" + "%.\\tmul.wide.u16\\t%0, %1, %2;") + +(define_insn "umulsidi3" + [(set (match_operand:DI 0 "nvptx_register_operand" "=R") + (mult:DI (zero_extend:DI + (match_operand:SI 1 "nvptx_register_operand" "R")) + (zero_extend:DI + (match_operand:SI 2 "nvptx_register_operand" "R"))))] + "" + "%.\\tmul.wide.u32\\t%0, %1, %2;") + ;; Shifts (define_insn "ashl3"