From patchwork Sat Apr 29 16:25:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 88885 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1686460vqo; Sat, 29 Apr 2023 09:26:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ727gUuqXMjApgPdTOF399znCRJ1tZlDSxHrU9skQ6KGeUbArXdLWmGmL/sGAXA7z3s/jzt X-Received: by 2002:a17:907:268e:b0:94e:d75b:5998 with SMTP id bn14-20020a170907268e00b0094ed75b5998mr7901000ejc.5.1682785581092; Sat, 29 Apr 2023 09:26:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682785581; cv=none; d=google.com; s=arc-20160816; b=qgpQhnu+TQKJfrnWw8fqwhciQ5xU0hO1+aoTbKJ7xwlHP8ZDp/Z7ePJFmzYZISSpKw jW3Xzq8zs9ktzN9jUx+HIBjOg8rq78yKblB+6T0ZWE1f45OJAKKZ78C0OikMo4DO05vu cVKlf5JFF7937N1ZI2jdA+46Ykv9fkCHa9NDFs/nJRamZBOw9I/5IWYxt1azd5glFsPE SwtstY48U5Ir0FwyrfmbLT67gsizyzQvF7dqStCy/pCokdxrYUE5BX9YHSjtdClTuqoM gZQ813TmLutvr8QgwBl/UpwIXBd3OIg7FbTZE3TZI54Cqt52kYbBBemd4+LOXeko+62p xMlw== 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:thread-index:content-language :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=pi4qserZshxkhs5WFPNBwHUTmKvL978EkuF9LqGViSE=; b=H6bqXxln6OojLTPe+LWh83qcGGSGtrEQscBAO8ewQ8SmJhAU/kL2gJM8HGFmU41m+A 2E+pEdjl/jhs+XCEBGVBDwQQwEh06vqrnYUoPnb/HZ9ikUqvgDzCyEapM8gZsbXHkKb9 IIlSrQ4124jBb4eD4jK7xtzUiZx8/c/TE/cfh4ElvEGESmXtphEmFZ6+10UbGyjGLv+y 3MlMcjXXqQgn5w1yxsWv/iLkFIBbquG6shRwOUPwEYoJsrwWkCRNNGVDStQr7EjTMFq8 xk8PfYkHd/cOl0xPg/+GRquJ3ljlFNwfdlrrH4negMvX3B7CUXh8s/UY6aXvNRwPGBya KWoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=oNqLBpHv; 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 f12-20020a056402160c00b0050673bf45b2si17384158edv.208.2023.04.29.09.26.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 09:26:21 -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=oNqLBpHv; 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 69630385772A for ; Sat, 29 Apr 2023 16:26:15 +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 0776F3858C50 for ; Sat, 29 Apr 2023 16:25:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0776F3858C50 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=pi4qserZshxkhs5WFPNBwHUTmKvL978EkuF9LqGViSE=; b=oNqLBpHvswLUJQMsYZbMSxhtjP qYTnVaEvw7pDiieOHhDazAUN4XV3tbaYH+IQUSW4DV8hMfTrgfI9ot23OI6k47o9ZfrMnLR8yIHD+ a0FPk4XdDrchWx/aCqskoIYnZyntXyO4GZeNzGlf5IeZhHxQzoGg4NVyVAhKk9vyIa3BangjEggmU CPPYkUyF3uSEGlqpWc5ksyHZ0B2SYh7Scalr3Wxav8ACcjHOA5bNnLthyNCKn1Q4IDgBB16Olu6Lm 3oyueU2p1/SxFbMcW4iS8Iado5GfhmLKtK2omme4YlQLuvWkVj8QbCNi6kTPEmoM1hf2hGOMwcO9n KTfRvspQ==; Received: from [185.62.158.67] (port=60600 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 1psnOP-0001OJ-1z for gcc-patches@gcc.gnu.org; Sat, 29 Apr 2023 12:25:49 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [xstormy16 PATCH] Efficient HImode rotate left by a single bit. Date: Sat, 29 Apr 2023 17:25:48 +0100 Message-ID: <004a01d97ab7$42722140$c75663c0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Content-Language: en-gb Thread-Index: Adl6txufGEOCzdeuTjOwopej3xtpBA== 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.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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?1764528573535611452?= X-GMAIL-MSGID: =?utf-8?q?1764528573535611452?= This patch contains some minor tweak to xstormy16's machine description most significantly providing a pattern for HImode rotate left by a single bit that requires only two instructions. unsigned short foo(unsigned short x) { return (x << 1) | (x >> 15); } currently with -O2 generates: foo: mov r7,r2 shr r7,#15 shl r2,#1 or r2,r7 ret with this patch, GCC now generates: foo: shl r2,#1 | adc r2,#0 ret Additionally neghi2 is converted to a define_insn (so that the RTL optimizers see the negation semantics), and HImode rotations by 8-bits can now be recognized and implemented using swpb. This patch has been tested by building a cross-compiler to xstormy16-elf from x86_64-pc-linux-gnu and confirming the new test cases pass. Ok for mainline? 2023-04-29 Roger Sayle gcc/ChangeLog * config/stormy16/stormy16.md (neghi2): Convert from a define_expand to a define_insn. (*rotatehi_1): New define_insn for efficient 2 insn sequence. (*rotatehi_8, *rotaterthi_8): New define_insn to emit a swpb. gcc/testsuite/ChangeLog * gcc.target/xstormy16/neghi2.c: New test case. * gcc.target/rotatehi-1.c: Likewise. Thanks in advance, Roger diff --git a/gcc/config/stormy16/stormy16.md b/gcc/config/stormy16/stormy16.md index b2e86ee..be1ee04 100644 --- a/gcc/config/stormy16/stormy16.md +++ b/gcc/config/stormy16/stormy16.md @@ -514,13 +518,13 @@ ;; Negation -(define_expand "neghi2" - [(set (match_operand:HI 0 "register_operand" "") - (not:HI (match_operand:HI 1 "register_operand" ""))) - (parallel [(set (match_dup 0) (plus:HI (match_dup 0) (const_int 1))) +(define_insn "neghi2" + [(parallel [(set (match_operand:HI 0 "register_operand" "=r") + (neg:HI (match_operand:HI 1 "register_operand" "0"))) (clobber (reg:BI CARRY_REG))])] "" - "") + "not %0 | add %0,#1" + [(set_attr "length" "4")]) ;; :::::::::::::::::::: ;; :: @@ -554,6 +558,24 @@ (clobber (reg:BI CARRY_REG))] "" "shr %0,%2") + +;; HImode rotate left by 1 bit +(define_insn "*rotatehi_1" + [(set (match_operand:HI 0 "register_operand" "=r") + (rotate:HI (match_operand:HI 1 "register_operand" "0") + (const_int 1))) + (clobber (reg:BI CARRY_REG))] + "" + "shl %0,#1 | adc %0,#0" + [(set_attr "length" "4")]) + +;; HImode rotate left by 8 bits +(define_insn "*hi_8" + [(set (match_operand:HI 0 "register_operand" "=r") + (any_rotate:HI (match_operand:HI 1 "register_operand" "0") + (const_int 8)))] + "" + "swpb %0") ;; :::::::::::::::::::: ;; :: diff --git a/gcc/testsuite/gcc.target/xstormy16/neghi2.c b/gcc/testsuite/gcc.target/xstormy16/neghi2.c new file mode 100644 index 0000000..dd3dd1e --- /dev/null +++ b/gcc/testsuite/gcc.target/xstormy16/neghi2.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +short neg(short x) +{ + return -x; +} +/* { dg-final { scan-assembler "not r2 | add r2,#1" } } */ diff --git a/gcc/testsuite/gcc.target/xstormy16/rotatehi-1.c b/gcc/testsuite/gcc.target/xstormy16/rotatehi-1.c new file mode 100644 index 0000000..586e7dc --- /dev/null +++ b/gcc/testsuite/gcc.target/xstormy16/rotatehi-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +unsigned short foo(unsigned short x) +{ + return (x << 1) | (x >> 15); +} + +/* { dg-final { scan-assembler "shl r2,#1" } } */ +/* { dg-final { scan-assembler "adc r2,#0" } } */