From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0085_01D97541.E9923EE0" 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 List-Id: This is a multipart message in MIME format. ------=_NextPart_000_0085_01D97541.E9923EE0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 -- ------=_NextPart_000_0085_01D97541.E9923EE0 Content-Type: text/plain; name="patchxs2.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchxs2.txt" diff --git a/gcc/config/stormy16/stormy16.cc = b/gcc/config/stormy16/stormy16.cc=0A= index 1ed619a..cf2f807 100644=0A= --- a/gcc/config/stormy16/stormy16.cc=0A= +++ b/gcc/config/stormy16/stormy16.cc=0A= @@ -2105,6 +2105,29 @@ xstormy16_output_shift (machine_mode mode, enum = rtx_code code,=0A= return r;=0A= }=0A= =0A= + /* For shifts of size 2, we can use two shifts of size 1. */=0A= + if (size =3D=3D 2)=0A= + {=0A= + switch (code)=0A= + {=0A= + case ASHIFT:=0A= + sprintf (r, "shl %s,#1 | rlc %s,#1 | shl %s,#1 | rlc %s,#1",=0A= + r0, r1, r0, r1);=0A= + break;=0A= + case ASHIFTRT:=0A= + sprintf (r, "asr %s,#1 | rrc %s,#1 | asr %s,#1 | rrc %s,#1",=0A= + r1, r0, r1, r0);=0A= + break;=0A= + case LSHIFTRT:=0A= + sprintf (r, "shr %s,#1 | rrc %s,#1 | shr %s,#1 | rrc %s,#1",=0A= + r1, r0, r1, r0);=0A= + break;=0A= + default:=0A= + gcc_unreachable ();=0A= + }=0A= + return r;=0A= + }=0A= +=0A= /* For large shifts, there are easy special cases. */=0A= if (size =3D=3D 16)=0A= {=0A= diff --git a/gcc/testsuite/gcc.target/xstormy16/shiftsi.c = b/gcc/testsuite/gcc.target/xstormy16/shiftsi.c=0A= new file mode 100644=0A= index 0000000..42bbca7=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gcc.target/xstormy16/shiftsi.c=0A= @@ -0,0 +1,12 @@=0A= +/* { dg-do compile } */=0A= +/* { dg-options "-O2" } */=0A= +=0A= +unsigned long ashift_1(unsigned long x) { return x << 1; }=0A= +unsigned long ashift_2(unsigned long x) { return x << 2; }=0A= +unsigned long lshiftrt_1(unsigned long x) { return x >> 1; }=0A= +unsigned long lshiftrt_2(unsigned long x) { return x >> 2; }=0A= +long ashiftrt_1(long x) { return x >> 1; }=0A= +long ashiftrt_2(long x) { return x >> 2; }=0A= +=0A= +/* { dg-final { scan-assembler-not "mov " } } */=0A= +/* { dg-final { scan-assembler-not "or " } } */=0A= ------=_NextPart_000_0085_01D97541.E9923EE0--