From patchwork Sat Apr 22 16:43:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1772312 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=NFgl7CHQ; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q3cf96K3Mz23tD for ; Sun, 23 Apr 2023 02:43:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 968D23857739 for ; Sat, 22 Apr 2023 16:43:26 +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 1FDDD3858C83 for ; Sat, 22 Apr 2023 16:43:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FDDD3858C83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=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=0KE2z30jAZI5f5m12kTozrSeMqiu8RcDpgs5iuD3fMo=; b=NFgl7CHQoeaPyi+8Jn87dpaQgZ IfOPJMiKjP6Ji277KyFUMkkVsJ8VSjYi19NR2bW0Jwbx0HqvjbRGLtea6nDCvZAmyc0Eu1KZFziXl /EdpGWlMzqueXAGqFkRD1AfMrgA/uyLQ4uLHkNgzk6AVBaQIfymCRYCL1p8/xntwll+W3hP4R1Zc1 NxzKKIfPTGVZCfVKc3/f7dRhZn/JtunBibDV5jR+S8ja4OFllbuJWI3oOmQupGWHkPYJjhkaytpcQ QcdAy8UwyUKPw/Pzkpnv8IU/OX9qM8G7h3gQRujNTOCfqaE4+YCt0pHDSGC0Wbp8kov+W+zdFN0TL KSW3lGUA==; Received: from [185.62.158.67] (port=60224 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pqGKP-0003eb-1d for gcc-patches@gcc.gnu.org; Sat, 22 Apr 2023 12:43:13 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [xstormy16 PATCH] Improved SImode shifts by two bits. Date: Sat, 22 Apr 2023 17:43:12 +0100 Message-ID: <008401d97539$87cdd6e0$976984a0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adl1OPB42SES1IhuR/Cwc4BGmJDQHQ== 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=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Currently on xstormy16 SImode shifts by a single bit require two instructions, and shifts by other non-zero integer immediate constants require five instructions. This patch implements the obvious optimization that shifts by two bits can be done in four instructions, by using two single-bit sequences. Hence, ashift_2 was previously generated as: mov r7,r2 | shl r2,#2 | shl r3,#2 | shr r7,#14 | or r3,r7 ret and with this patch we now generate: shl r2,#1 | rlc r3,#1 | shl r2,#1 | rlc r3,#1 ret This patch has been tested by building a cross-compiler to xstormy16-elf on x86_64-pc-linux-gnu, and confirming that the new test case passes with "make -k check-gcc". Ok for mainline? 2023-04-22 Roger Sayle gcc/ChangeLog * config/stormy16/stormy16.cc (xstormy16_output_shift): Implement SImode shifts by two by performing a single bit SImode shift twice. gcc/testsuite/ChangeLog * gcc.target/xstormy16/shiftsi.c: New test case. Thanks in advance, Roger diff --git a/gcc/config/stormy16/stormy16.cc b/gcc/config/stormy16/stormy16.cc index 1ed619a..cf2f807 100644 --- a/gcc/config/stormy16/stormy16.cc +++ b/gcc/config/stormy16/stormy16.cc @@ -2105,6 +2105,29 @@ xstormy16_output_shift (machine_mode mode, enum rtx_code code, return r; } + /* For shifts of size 2, we can use two shifts of size 1. */ + if (size == 2) + { + switch (code) + { + case ASHIFT: + sprintf (r, "shl %s,#1 | rlc %s,#1 | shl %s,#1 | rlc %s,#1", + r0, r1, r0, r1); + break; + case ASHIFTRT: + sprintf (r, "asr %s,#1 | rrc %s,#1 | asr %s,#1 | rrc %s,#1", + r1, r0, r1, r0); + break; + case LSHIFTRT: + sprintf (r, "shr %s,#1 | rrc %s,#1 | shr %s,#1 | rrc %s,#1", + r1, r0, r1, r0); + break; + default: + gcc_unreachable (); + } + return r; + } + /* For large shifts, there are easy special cases. */ if (size == 16) { diff --git a/gcc/testsuite/gcc.target/xstormy16/shiftsi.c b/gcc/testsuite/gcc.target/xstormy16/shiftsi.c new file mode 100644 index 0000000..42bbca7 --- /dev/null +++ b/gcc/testsuite/gcc.target/xstormy16/shiftsi.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +unsigned long ashift_1(unsigned long x) { return x << 1; } +unsigned long ashift_2(unsigned long x) { return x << 2; } +unsigned long lshiftrt_1(unsigned long x) { return x >> 1; } +unsigned long lshiftrt_2(unsigned long x) { return x >> 2; } +long ashiftrt_1(long x) { return x >> 1; } +long ashiftrt_2(long x) { return x >> 2; } + +/* { dg-final { scan-assembler-not "mov " } } */ +/* { dg-final { scan-assembler-not "or " } } */