From patchwork Sat Apr 22 20:57: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: 86633 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1889086vqo; Sat, 22 Apr 2023 13:58:25 -0700 (PDT) X-Google-Smtp-Source: AKy350bk/gSG/IncuYcI3y7UdRGpSnBLbmeka0o0E3j+43pMdoysujq34BnXhOaejE05T6khFK2h X-Received: by 2002:aa7:d458:0:b0:506:bb4f:ec with SMTP id q24-20020aa7d458000000b00506bb4f00ecmr8430739edr.33.1682197104850; Sat, 22 Apr 2023 13:58:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682197104; cv=none; d=google.com; s=arc-20160816; b=qEmw9RaD/9IckM7t1hfoZaeyeU6EoTu5b+rhmGpz6BgNn7K/wC0fobDelff435Dakx ooWsSpw4pJNaReJlsYuySyoOZEFnTfnl9PalN/zHRhpCaIhv/+XNIjGr7WbQ3Q50qBYB auyRyPl6MpRBI2/7/4ZxvPDT+3nNfSGvmmxM3t0oLdsgOXWiEv1g50jrS4ZcP5KVUVwT E1pzDQJAxQQ/0icrORbccayp0XpSTDmZQ8SSfPEOkNWx/MCZdAuft1wUz6GuyqzzDyfa zmoFRpEKUMDuj9HoSdZ6M66TPZqCZTTjDxuSGv07KbE9UdVCmcjnvHkHJBJUFqMVRB7z vyuA== 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=lrRxzeQ1i8x7r1ELc1lL+VKvdt7qghexBSEhC6vTPk4=; b=DU+qWnG4Topyaz/7ciTGK52hFLn7LbBsxmN1CADHCJ08JNUivZZaSWXiiWJmqOC7Gy iPrxSUmb+3dBKdZFysCwRyqtA/0ILCql8n964Z9ng4Ewbv0c1Rg4H3hEJttZa31K8at/ /jBILBj4dEZh9Y1sMvuoylCfRxHlcmsNQTGeRmM+mMS+uYCio0tvrbrM32BmbJ5x5/PJ 6NpwZu6SX8vBJv5FUOkOXARNagFJhZW5NBEI8M8PIJsKZfmq4gLIRq+5czAg9kN3DsrI FZixrFA7A7TT8hMAUE3Xc/alk2dSj46g4YKh5b1EbhHfUym5S/kuuBW97eYWcIPGHvuG kgmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=fpYlskkS; 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 d5-20020aa7d5c5000000b0050676db401asi3943837eds.129.2023.04.22.13.58.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 13:58:24 -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=fpYlskkS; 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 E8B41385735C for ; Sat, 22 Apr 2023 20:58:17 +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 B87403858C50 for ; Sat, 22 Apr 2023 20:57:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B87403858C50 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=lrRxzeQ1i8x7r1ELc1lL+VKvdt7qghexBSEhC6vTPk4=; b=fpYlskkSSMSfq1IcCU7A/fFZC8 Be5uMDKL8prVEozB1wmS/nTtONr0tp41SkdccQzPCcjbaufRcv7WolfW4kI6bcUPxdVJoj1mR3EES SCFQiZLrTfgM4O6O+25M0dsKi1DdXzROcI5FMjb5evAhoNoszENkkNM6Wk33bZM7GGsm8RirHyYvU fdcDJf48axMrEN6LoI5B07tj7xuycZNkrKhIiEVDc9s9UMA5I/SJBnE2ukORQgAowSn+xFDBZ1r1S rcju6HCTs13Vhc7S8Yx42IzVeJ1V2syeH73h0zd0uCui1oUjoQRE//FYddER2Z74qfb9T57gkjNgV gdBcfYjw==; Received: from host86-169-41-81.range86-169.btcentralplus.com ([86.169.41.81]:50397 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 1pqKIp-0005Uw-09 for gcc-patches@gcc.gnu.org; Sat, 22 Apr 2023 16:57:51 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [xstormy16] Add extendhisi2 and zero_extendhisi2 patterns to stormy16.md Date: Sat, 22 Apr 2023 21:57:48 +0100 Message-ID: <026001d9755d$19b30030$4d190090$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adl1W4nNwZRXONUaTiCfIyc0+pfgIA== 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=-7.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, MEDICAL_SUBJECT, RCVD_IN_BARRACUDACENTRAL, 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?1763911511718883451?= X-GMAIL-MSGID: =?utf-8?q?1763911511718883451?= This patch adds a pair of define_insn patterns to the xstormy16 machine description that provide extendhisi2 and zero_extendhisi2, i.e. 16-bit to 32-bit sign- and zero-extension respectively. This functionality is already synthesized during RTL expansion, but providing patterns allow the semantics to be exposed to the RTL optimizers. To simplify things, this patch introduces a new %h0 output format, for emitting the high_part register name of a double-word (SImode) register pair. The actual code generated is identical to before. Whilst there, I also fixed the instruction lengths and formatting of the zero_extendqihi2 pattern. Then, mostly for documentation purposes as the 'T' constraint isn't yet implemented, I've added a "and Rx,#255" alternative to zero_extendqihi2 that takes advantage of its efficient instruction encoding. 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_print_operand): Add %h format specifier to output high_part register name of SImode reg. * config/stormy16/stormy16.md (extendhisi2): New define_insn. (zero_extendqihi2): Fix lengths, consistent formatting and add "and Rx,#255" alternative, for documentation purposes. (zero_extendhisi2): New define_insn. gcc/testsuite/ChangeLog * gcc.target/xstormy16/extendhisi2.c: New test case. * gcc.target/xstormy16/zextendhisi2.c: Likewise. Thanks in advance, Roger diff --git a/gcc/config/stormy16/stormy16.cc b/gcc/config/stormy16/stormy16.cc index 1ed619a..34118e2 100644 --- a/gcc/config/stormy16/stormy16.cc +++ b/gcc/config/stormy16/stormy16.cc @@ -1828,6 +1828,14 @@ xstormy16_print_operand (FILE *file, rtx x, int code) return; } + case 'h': + /* Print the highpart register of an SI mode register pair. */ + if (REG_P (x) && GET_MODE (x) == SImode) + fputs (reg_names [REGNO (x) + 1], file); + else + output_operand_lossage ("'h' operand is not SImode register"); + return; + case 0: /* Handled below. */ break; diff --git a/gcc/config/stormy16/stormy16.md b/gcc/config/stormy16/stormy16.md index d27c9fb..fd52588 100644 --- a/gcc/config/stormy16/stormy16.md +++ b/gcc/config/stormy16/stormy16.md @@ -268,17 +268,34 @@ "" "cbw %0") +(define_insn "extendhisi2" + [(set (match_operand:SI 0 "register_operand" "=r") + (sign_extend:SI (match_operand:HI 1 "register_operand" "0")))] + "" + "mov %h0,%0 | asr %h0,#15" + [(set_attr "length" "4") + (set_attr "psw_operand" "clobber")]) + (define_insn "zero_extendqihi2" - [(set (match_operand:HI 0 "register_operand" "=e,r") - (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "m,0")))] + [(set (match_operand:HI 0 "register_operand" "=e,T,r") + (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "m,0,0")))] "" "@ - mov.b %0, %1 - shl %0,#8\n\tshr %0,#8" - [(set_attr "psw_operand" "nop,0") + mov.b %0,%1 + and Rx,#255 + shl %0,#8 | shr %0,#8" + [(set_attr "psw_operand" "nop,nop,0") (set_attr_alternative "length" - [(const_int 4) - (const_int 8)])]) + [(const_int 2) + (const_int 2) + (const_int 4)])]) + +(define_insn "zero_extendhisi2" + [(set (match_operand:SI 0 "register_operand" "=r") + (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))] + "" + "mov %h0,#0" + [(set_attr "psw_operand" "clobber")]) ;; :::::::::::::::::::: ;; :: diff --git a/gcc/testsuite/gcc.target/xstormy16/extendhisi2.c b/gcc/testsuite/gcc.target/xstormy16/extendhisi2.c new file mode 100644 index 0000000..bb8a22d --- /dev/null +++ b/gcc/testsuite/gcc.target/xstormy16/extendhisi2.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +long foo(short x) +{ + return x; +} +/* { dg-final { scan-assembler "asr r3,#15" } } */ diff --git a/gcc/testsuite/gcc.target/xstormy16/zextendhisi2.c b/gcc/testsuite/gcc.target/xstormy16/zextendhisi2.c new file mode 100644 index 0000000..9aef32a --- /dev/null +++ b/gcc/testsuite/gcc.target/xstormy16/zextendhisi2.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +unsigned long foo(unsigned short x) +{ + return x; +} +/* { dg-final { scan-assembler "mov r3,#0" } } */