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: 86609 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1799952vqo; Sat, 22 Apr 2023 09:43:46 -0700 (PDT) X-Google-Smtp-Source: AKy350ZiIFowwAiScJS0z+ZPrRkNpWMsORIij3T6VkdnPzh7//jxCdUwx154wIGPCwamQpmyfaiB X-Received: by 2002:a17:906:1c4:b0:94e:f9b:2b14 with SMTP id 4-20020a17090601c400b0094e0f9b2b14mr5576783ejj.62.1682181826082; Sat, 22 Apr 2023 09:43:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682181826; cv=none; d=google.com; s=arc-20160816; b=UK4GLlSxsu+k7woUPSFkhRin9yxGlz+YYzGF2EGuc1hSv6Nqm+47z6v5W/5kc+72Wk lnTYsMTa87j9D0zceINNrmkjzbI9fzfLuKg68rWYl8d3NTu/XlnJXdcmhT5G+4iuMbI3 zkJlFUsA/YDIK8tlG2xFd1zEPED5MQcU2rfIW5cvq8qz7scQT9mhhbDXhJpJ2BQJIMXV uDPy/uJWH/DzUuksmk7S+eeOq7U/2L4xXZKFVFUp/bsDnxYmHKRxHKVteJLRDk5o+Pmc xAlv3NGN7LDjIcwYWaBVhICSrOn0YLZ8pRP2wviWrGo/gHAhNwXm+IHq1/ZArvY2AOVd OIzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:thread-index :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=0KE2z30jAZI5f5m12kTozrSeMqiu8RcDpgs5iuD3fMo=; b=srDP8m9Uvog4RKC+M387SB4OnzZ0r0KSRQ7road3AzkG7qN12rbDrFTu/J66/DBxLT JN0on1yoJlsVy1z2xNNgSwHFFOUT74+H+cq/X96esZL2tGF/KMgFG4cLNSh4UfnoAgCE 7nSjMcqsLz2LWSZuCiCAuVRaXHGzK2XWbnAvvvFptH4a8YvsQ2RH8w9/StKwR7hulybE A1hYg1UR+dIYdp14bTfD3UW2IGG5mTO0tYBa1nuhN5c4sUZdM7iXJdw4rskVfTHsx1bS do9SM0N/z3e7zgZmJ+sWOK+6cjSC5+dOhuOjUIOCVGbTlmP4IH3o+xwHyg+QWT/U1ARo EXkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=NFgl7CHQ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id tc10-20020a1709078d0a00b0094f5f27c745si5657569ejc.591.2023.04.22.09.43.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 09:43:46 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=NFgl7CHQ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C036385842E for ; Sat, 22 Apr 2023 16:43:39 +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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763895490447559329?= X-GMAIL-MSGID: =?utf-8?q?1763895490447559329?= 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 " } } */