From patchwork Sun Jul 12 19:38:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1327593 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=asVYh3Nn; 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 4B4cWl68tHz9sR4 for ; Mon, 13 Jul 2020 05:38:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F55A39CEC35; Sun, 12 Jul 2020 19:38:06 +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 AA3E939CEC35 for ; Sun, 12 Jul 2020 19:38:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AA3E939CEC35 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:Cc:To:From:Sender:Reply-To: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=0FVjnepzVUVPnHXXc2WMAVv1dmhtpSZQTfQ/eXWoSlA=; b=asVYh3Nn15xtw9FNKQ0ndnM548 LvQZigy1gIndDoi5xpAf3cOl1TfWprmbJhPM18f4rXh8tEcM7cuKAfCzBId/OtGdD3XVFQJJseDfy ttUTSnfIkyfXjkNBk25xcQRb/OpibTzwfjRcv7yAOszhtVFkPT0ZBvP3/xN5nTfAeIhzlNJ/NIGjL dzhIm0f9opeUpN2SPoQkMUbJxPZb0De4tgCkbaZ4TiFY2uiJbx2EhMrqF3AIkqI0guR5n78NIJQqZ 2ICBVlbPgdNzWciKmGMVcySX8MX+Ihz+szJ5nprRQhOgzyqDKXoNgUco4ojvNTBsJSpxdvsvNMNXL DZhOOL7g==; Received: from host86-137-89-56.range86-137.btcentralplus.com ([86.137.89.56]:62022 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 1juhnW-0003nv-Ck; Sun, 12 Jul 2020 15:38:02 -0400 From: "Roger Sayle" To: Subject: [PATCH] nvptx: Support floating point reciprocal instructions. Date: Sun, 12 Jul 2020 20:38:00 +0100 Message-ID: <000901d65883$f495b3e0$ddc11ba0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdZYg3rRgJgo0MYDRcmBeWiL3UC3JQ== 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=-11.2 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 addds support for PTX's rcp.rn.f32 and rcp.rn.f64 instructions. Note that the "rcp.rn" forms of this instruction calculate the fully IEEE compliant result for the reciprocal, unlike the rcp.approx variants that just provide fast approximations. I'm undecided as to whether to prefix this instruction name with "*" as this pattern is almost standard, so I can imagine the middle-end potentially adding optab support for recip2 expansion at some point. I'll go with the (backend) reviewer's recommendation? This patch has been tested on nvptx-none hosted on x86_64-pc-linux-gnu with "make" and "make check" with no new regressions. Ok for mainline? 2020-07-12 Roger Sayle gcc/ChangeLog * config/nvptx/nvptx.md (recip2): New instruction. gcc/testsuite/ChangeLog * gcc.target/nvptx/recip-1.c: New test. Thanks in advance, Roger --- Roger Sayle NextMove Software Cambridge, UK diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md index 6545b81..ea6fc94 100644 --- a/gcc/config/nvptx/nvptx.md +++ b/gcc/config/nvptx/nvptx.md @@ -872,6 +872,15 @@ "" "%.\\tfma%#%t0\\t%0, %1, %2, %3;") +(define_insn "recip2" + [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R") + (div:SDFM + (match_operand:SDFM 2 "const_double_operand" "F") + (match_operand:SDFM 1 "nvptx_register_operand" "R")))] + "CONST_DOUBLE_P (operands[2]) + && real_identical (CONST_DOUBLE_REAL_VALUE (operands[2]), &dconst1)" + "%.\\trcp%#%t0\\t%0, %1;") + (define_insn "div3" [(set (match_operand:SDFM 0 "nvptx_register_operand" "=R") (div:SDFM (match_operand:SDFM 1 "nvptx_register_operand" "R") diff --git a/gcc/testsuite/gcc.target/nvptx/recip-1.c b/gcc/testsuite/gcc.target/nvptx/recip-1.c new file mode 100644 index 0000000..9a165f1 --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/recip-1.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +double foo(double x) +{ + return 1.0/x; +} + +float foof(float x) +{ + return 1.0f/x; +} + +/* { dg-final { scan-assembler-times "rcp.rn.f64" 1 } } */ +/* { dg-final { scan-assembler-times "rcp.rn.f32" 1 } } */ +