From patchwork Wed Mar 15 12:24:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 70187 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2296744wrd; Wed, 15 Mar 2023 05:25:50 -0700 (PDT) X-Google-Smtp-Source: AK7set9DEaP3aLYaK4y0UzXNxWGlxbDfWqe9VPYh8JaU817ReHvwC1EtESatH2OsxYoER0pP74RF X-Received: by 2002:a05:6402:6d4:b0:4fb:54b7:50ea with SMTP id n20-20020a05640206d400b004fb54b750eamr2612844edy.21.1678883150348; Wed, 15 Mar 2023 05:25:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678883150; cv=none; d=google.com; s=arc-20160816; b=XyAGwCV87rZEPGvK18w9j5cPB+RLENstoSRD/kqQyY4lJgFmzrtQCzBeprSvP2Xuys EBpK696V27iyIMPBNBwKMymRvTF2QPRKGgdu+Ks+U8nO29d5LfIOiRB4E4N/5hrZYOMM weWPZ/1eAUekKzJnl4jIWX2NhPoCVaKb0brZCuF+7bq4dfrxWeQBPKEtXShGMJ3J+0Ty oBSiZaYui2xoEAmjYJ7Y3YiQdlLYSR5IbvnooUG67wQXQhxBPYYsUhNfBjzHk/666/fR TuXXD2Sn24tUVn4K1Z2elF0ZLCQq3HDJiVCvRhE4di4mbUhQHnoDD3GiSUrerIX2zrGr +toA== 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-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=WQy9LJ2fnOUpjvuuXqKsOWheBdEtLe3Zo84PMxb0CWg=; b=tK7bc8IzCeJJEPpmKreyc7InwmaPvEOGgVRXGy+G0aw8xvRPrTmQnUhz9hLaujPvR4 l46Ivwz7iIaPinRYkDOVHFyQvXp7AwaOWfE02StRbEa02TSE4net46duvMAvHsWbC0Uo 7reo3B9HJUcdRIBimpK7pDMM76gicEFh9NZWpgq47mQSpDxiKDe04sj0lJtnVrCqkwTg +8VFDJPoefyCbmbfSoS0II+cMDf2YvaJBsl9/X7wORbVZs8MDBdam8qT3oCm54VSG3Wt lf4TQgoIv0v+0zSkP9OBtFRSoHdkV0zv7ohbhYX0N7X0Gi2OL2X1bThs0GzSVJSe3v7o /cyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b="Fo/eb5Q5"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id cf12-20020a170906b2cc00b008c9851d114asi4544889ejb.607.2023.03.15.05.25.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 05:25:50 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b="Fo/eb5Q5"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 8FCE8385040A for ; Wed, 15 Mar 2023 12:25:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 74AFA3858C83 for ; Wed, 15 Mar 2023 12:24:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74AFA3858C83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-ed1-x532.google.com with SMTP id cn21so44589186edb.0 for ; Wed, 15 Mar 2023 05:24:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1678883095; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=WQy9LJ2fnOUpjvuuXqKsOWheBdEtLe3Zo84PMxb0CWg=; b=Fo/eb5Q5KspmE+p3B+iRhqWYCgJX0Jg5KCWpoDWSjfPNxBrr9UH/F6oaLOFU5YUPh7 7+3CSrCFPukoxBtIAZxrJcPGirAleocHuxKkAR0OS9yWKFby7XZ0WSJMnwssSDu3mM89 yEez2AYkPeVqE60bFKAczvVsq8PZ2c8m8g3pG3HwzEg8ldu8HMvDvr+UgoTiWZsjJJWR 5/xuo2I0DGdfkrjUCPohtgaavSmIfPNtGhxgaxRYg5YlwafenS7eDb2OJO6VNTB434nj 2AgHD61CvuX+EesfQeONTmnMb/VsQdt+n8o5mnBDxOg2XHM5alW/Ta0nRrL7wmBVBbcA HpjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678883095; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WQy9LJ2fnOUpjvuuXqKsOWheBdEtLe3Zo84PMxb0CWg=; b=QKz4wrnxIHC1eJY8oUcU96xjG+caaKqk/hQ8mWn0Fwxi4mBMDoO+rSlbhXKZlU51qd TM3lEVtHi+13N6ZaZcXeGqojYeawqe/vncTmxLZvPQrHHtmX5P/7lSluMSm8C4ZY3WhR tRP2tacQp/GGWQnsquvgWFr9+923SGge/ParBvXetj2ZEeTd901zkEZ3LrWxQK/b+6rS gMCvoI04b+MTEp1gnlnYkw3ORUB4uPbL3mDKB2U9BEcinURII5MEqBUoLdkAqhUChtQ9 xZ/0GOZhVG1rk/4ucCJzxvqr541FXKxM3QiMOuT+5wEPe9ZMstMGFiDDi8+hYWCB7jU9 fqtg== X-Gm-Message-State: AO0yUKXqTRSG/Q/26gZR9L9slPH6X9qLyTY+fCPYgWan9Qh3NxurLbJT EUQXkvsM4isn+tko6EO+Gwt1UrVL2m0ZrECRyRc= X-Received: by 2002:a17:906:dfda:b0:862:11f6:a082 with SMTP id jt26-20020a170906dfda00b0086211f6a082mr5274708ejc.17.1678883095599; Wed, 15 Mar 2023 05:24:55 -0700 (PDT) Received: from beast.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id v18-20020a509552000000b004fe924d16cfsm1868415eda.31.2023.03.15.05.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 05:24:55 -0700 (PDT) From: Christoph Muellner To: gcc-patches@gcc.gnu.org, Kito Cheng , Jim Wilson , Palmer Dabbelt , Andrew Waterman , Philipp Tomsich , Cooper Qu , Lifang Xia , Yunhai Shang , Zhiwei Liu Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH] riscv: thead: Add sign/zero extension support for th.ext and th.extu Date: Wed, 15 Mar 2023 13:24:48 +0100 Message-Id: <20230315122448.3394353-1-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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?1760436578104703472?= X-GMAIL-MSGID: =?utf-8?q?1760436578104703472?= From: Christoph Müllner The current support of the bitfield-extraction instructions th.ext and th.extu (XTheadBb extension) only covers sign_extract and zero_extract. This patch add support for sign_extend and zero_extend to avoid any shifts for sign or zero extensions. gcc/ChangeLog: * config/riscv/riscv.md: * config/riscv/thead.md (*extend2_th_ext): (*zero_extendsidi2_th_extu): (*zero_extendhi2_th_extu): gcc/testsuite/ChangeLog: * gcc.target/riscv/xtheadbb-ext-1.c: New test. * gcc.target/riscv/xtheadbb-extu-1.c: New test. Signed-off-by: Christoph Müllner --- gcc/config/riscv/riscv.md | 6 +- gcc/config/riscv/thead.md | 31 +++++++++ .../gcc.target/riscv/xtheadbb-ext-1.c | 67 +++++++++++++++++++ .../gcc.target/riscv/xtheadbb-extu-1.c | 67 +++++++++++++++++++ 4 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadbb-ext-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadbb-extu-1.c diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index 863400cd447..b763b84b763 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -1368,7 +1368,7 @@ (define_insn_and_split "*zero_extendsidi2_internal" [(set (match_operand:DI 0 "register_operand" "=r,r") (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" " r,m")))] - "TARGET_64BIT && !TARGET_ZBA + "TARGET_64BIT && !TARGET_ZBA && !TARGET_XTHEADBB && !(REG_P (operands[1]) && REGNO (operands[1]) == VL_REGNUM)" "@ @@ -1395,7 +1395,7 @@ (define_insn_and_split "*zero_extendhi2" [(set (match_operand:GPR 0 "register_operand" "=r,r") (zero_extend:GPR (match_operand:HI 1 "nonimmediate_operand" " r,m")))] - "!TARGET_ZBB" + "!TARGET_ZBB && !TARGET_XTHEADBB" "@ # lhu\t%0,%1" @@ -1451,7 +1451,7 @@ (define_insn_and_split "*extend2" [(set (match_operand:SUPERQI 0 "register_operand" "=r,r") (sign_extend:SUPERQI (match_operand:SHORT 1 "nonimmediate_operand" " r,m")))] - "!TARGET_ZBB" + "!TARGET_ZBB && !TARGET_XTHEADBB" "@ # l\t%0,%1" diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md index 63c4af6f77d..978402e0b5d 100644 --- a/gcc/config/riscv/thead.md +++ b/gcc/config/riscv/thead.md @@ -59,6 +59,17 @@ (define_insn "*th_ext4" [(set_attr "type" "bitmanip") (set_attr "mode" "")]) +(define_insn "*extend2_th_ext" + [(set (match_operand:SUPERQI 0 "register_operand" "=r,r") + (sign_extend:SUPERQI + (match_operand:SHORT 1 "nonimmediate_operand" "r,m")))] + "TARGET_XTHEADBB" + "@ + th.ext\t%0,%1,15,0 + l\t%0,%1" + [(set_attr "type" "bitmanip,load") + (set_attr "mode" "")]) + (define_insn "*th_extu4" [(set (match_operand:GPR 0 "register_operand" "=r") (zero_extract:GPR (match_operand:GPR 1 "register_operand" "r") @@ -72,6 +83,26 @@ (define_insn "*th_extu4" [(set_attr "type" "bitmanip") (set_attr "mode" "")]) +(define_insn "*zero_extendsidi2_th_extu" + [(set (match_operand:DI 0 "register_operand" "=r,r") + (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "r,m")))] + "TARGET_64BIT && TARGET_XTHEADBB" + "@ + th.extu\t%0,%1,31,0 + lwu\t%0,%1" + [(set_attr "type" "bitmanip,load") + (set_attr "mode" "SI")]) + +(define_insn "*zero_extendhi2_th_extu" + [(set (match_operand:GPR 0 "register_operand" "=r,r") + (zero_extend:GPR (match_operand:HI 1 "nonimmediate_operand" "r,m")))] + "TARGET_XTHEADBB" + "@ + th.extu\t%0,%1,15,0 + lhu\t%0,%1" + [(set_attr "type" "bitmanip,load") + (set_attr "mode" "HI")]) + (define_insn "*th_clz2" [(set (match_operand:X 0 "register_operand" "=r") (clz:X (match_operand:X 1 "register_operand" "r")))] diff --git a/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-1.c b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-1.c new file mode 100644 index 00000000000..02f6ec1417d --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/xtheadbb-ext-1.c @@ -0,0 +1,67 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_xtheadbb" { target { rv64 } } } */ +/* { dg-options "-march=rv32gc_xtheadbb" { target { rv32 } } } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Os" "-Og" } } */ + +long sext64_32(int s32) +{ + return s32; +} + +long sext64_16(short s16) +{ + return s16; +} + +long sext64_8(char s8) +{ + return s8; +} + +int sext32_64(long s64) +{ + return s64; +} + +int sext32_16(short s16) +{ + return s16; +} + +int sext32_8(char s8) +{ + return s8; +} + +short sext16_64(long s64) +{ + return s64; +} + +short sext16_32(int s32) +{ + return s32; +} + +short sext16_8(char s8) +{ + return s8; +} + +char sext8_64(long s64) +{ + return s64; +} + +char sext8_32(int s32) +{ + return s32; +} + +char sext8_16(short s16) +{ + return s16; +} + +/* { dg-final { scan-assembler-not "slli" } } */ +/* { dg-final { scan-assembler-not "srli" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/xtheadbb-extu-1.c b/gcc/testsuite/gcc.target/riscv/xtheadbb-extu-1.c new file mode 100644 index 00000000000..01e3eda7df2 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/xtheadbb-extu-1.c @@ -0,0 +1,67 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv32gc_xtheadbb" { target { rv32 } } } */ +/* { dg-options "-march=rv64gc_xtheadbb" { target { rv64 } } } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Os" "-Og" } } */ + +unsigned long zext64_32(unsigned int u32) +{ + return u32; //th.extu a0, a0, 31, 0 +} + +unsigned long zext64_16(unsigned short u16) +{ + return u16; +} + +unsigned long zext64_8(unsigned char u8) +{ + return u8; +} + +unsigned int zext32_64(unsigned long u64) +{ + return u64; +} + +unsigned int zext32_16(unsigned short u16) +{ + return u16; +} + +unsigned int zext32_8(unsigned char u8) +{ + return u8; +} + +unsigned short zext16_64(unsigned long u64) +{ + return u64; +} + +unsigned short zext16_32(unsigned int u32) +{ + return u32; +} + +unsigned short zext16_8(unsigned char u8) +{ + return u8; +} + +unsigned char zext8_64(unsigned long u64) +{ + return u64; +} + +unsigned char zext8_32(unsigned int u32) +{ + return u32; +} + +unsigned char zext8_16(unsigned short u16) +{ + return u16; +} + +/* { dg-final { scan-assembler-not "slli" } } */ +/* { dg-final { scan-assembler-not "srli" } } */