Message ID | 20230224055127.2500953-5-christoph.muellner@vrull.eu |
---|---|
State | Committed |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 58140384FB7A for <patchwork@sourceware.org>; Fri, 24 Feb 2023 05:51:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 99717385B501 for <gcc-patches@gcc.gnu.org>; Fri, 24 Feb 2023 05:51:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 99717385B501 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-wr1-x42c.google.com with SMTP id j2so12598934wrh.9 for <gcc-patches@gcc.gnu.org>; Thu, 23 Feb 2023 21:51:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GYXOlOd7Q7luwkWUh38lFwuKiDMWoPJh8wz/t8z+iYE=; b=GcfvF0N7tu20YHtZ+8ya67SFTPa84xMTWqiZWFo8lxeNrbsICQYdGt9zzRA7HpqniS 863tUV2tY2W+RPn/Bk8GDpn0FqSyTh4OHz+a1iXcK6IzaNu+Gzd3o42ghSl3BbFOQL2m dTPlbb2nZRU+7tG+dq7ftLNDGGGmL/kHZpuYd6Ic5yRQuDLQ1KGatcch+imC8cUFPbo4 Xdx6/NedxKN5wc73+NH2ETCMvG/G2LjqWlgmmvJpthCRiANLilIlCWnG9rzFmhZF9UvN 3qgD15MdNoHPyt4UgGs+8JSrQ77ZNZVpAmi11KO3aPdM/6V1nMTnGiX6dWaGz0TFbrbN lm/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GYXOlOd7Q7luwkWUh38lFwuKiDMWoPJh8wz/t8z+iYE=; b=VAFpXUR7U5hW/N4uCyTTlCqXmzBMIz++afCib8rsppg2XRYDhPm0hhDJXOsp1rwc/4 gLGQahxe0IVBr3Vbigy4DyLTlQuPuiWHAl1krD0spuoGUo70SHaRWdqTvBNN+AMoZElb 7H0VoiZsvZzgZaE/TuZl/GcLiDVJbcdtiJdGqep+O/AO5dDaVHxAur4FPX3Rzs1zVBzD fOsI0GkTmllpOgOlFpu4ydY58RqPyu0EnFQqgFF386ooTz1lOYtxYioDSEdXtT7OerZJ sxIQB5ZMBSpNKWW4NrZisEQeAu4Vet3BfHbuqz/G92Bfw8KHUUOZlDJexXWvegY327W1 sptA== X-Gm-Message-State: AO0yUKUEFtfSFGwZ9G5FIFw5VA+y2iZIttKyoitfGu5cdscXc02npsUX VIXRi4d+lRRaMCOcCg7CveScSZIyYp3gizqg X-Google-Smtp-Source: AK7set//MFFTFp1/YRQaULD2vq7os1BQej0MrJXaKckwCL+y1Tg5nU+sIT1d6XbpJ8M0WppQNCAD+A== X-Received: by 2002:a05:6000:170a:b0:2c5:4c9d:2dab with SMTP id n10-20020a056000170a00b002c54c9d2dabmr10899588wrc.10.1677217898020; Thu, 23 Feb 2023 21:51:38 -0800 (PST) Received: from beast.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id f18-20020adffcd2000000b002c59e001631sm11704055wrs.77.2023.02.23.21.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 21:51:37 -0800 (PST) From: Christoph Muellner <christoph.muellner@vrull.eu> To: gcc-patches@gcc.gnu.org, Kito Cheng <kito.cheng@sifive.com>, Jim Wilson <jim.wilson.gcc@gmail.com>, Palmer Dabbelt <palmer@dabbelt.com>, Andrew Waterman <andrew@sifive.com>, Philipp Tomsich <philipp.tomsich@vrull.eu>, Jeff Law <jeffreyalaw@gmail.com>, Cooper Qu <cooper.qu@linux.alibaba.com>, Lifang Xia <lifang_xia@linux.alibaba.com>, Yunhai Shang <yunhai@linux.alibaba.com>, Zhiwei Liu <zhiwei_liu@linux.alibaba.com> Cc: =?utf-8?q?Christoph_M=C3=BCllner?= <christoph.muellner@vrull.eu> Subject: [PATCH v3 04/11] riscv: thead: Add support for the XTheadBs ISA extension Date: Fri, 24 Feb 2023 06:51:20 +0100 Message-Id: <20230224055127.2500953-5-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230224055127.2500953-1-christoph.muellner@vrull.eu> References: <20230224055127.2500953-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
RISC-V: Add XThead* extension support
|
|
Commit Message
Christoph Müllner
Feb. 24, 2023, 5:51 a.m. UTC
From: Christoph Müllner <christoph.muellner@vrull.eu> This patch adds support for the XTheadBs ISA extension. The new INSN pattern is defined in a new file to separate this vendor extension from the standard extensions. The cost model adjustment reuses the xbs:bext cost. gcc/ChangeLog: * config/riscv/riscv.cc (riscv_rtx_costs): Add xthead:tst cost. * config/riscv/thead.md (*th_tst): New INSN. gcc/testsuite/ChangeLog: * gcc.target/riscv/xtheadbs-tst.c: New test. Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> --- gcc/config/riscv/riscv.cc | 4 ++-- gcc/config/riscv/thead.md | 11 +++++++++++ gcc/testsuite/gcc.target/riscv/xtheadbs-tst.c | 13 +++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/xtheadbs-tst.c
Comments
> diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md > index 158e9124c3a..2c684885850 100644 > --- a/gcc/config/riscv/thead.md > +++ b/gcc/config/riscv/thead.md > @@ -29,3 +29,14 @@ (define_insn "*th_addsl" > "th.addsl\t%0,%3,%1,%2" > [(set_attr "type" "bitmanip") > (set_attr "mode" "<X:MODE>")]) > + > +;; XTheadBs > + > +(define_insn "*th_tst" > + [(set (match_operand:X 0 "register_operand" "=r") > + (zero_extract:X (match_operand:X 1 "register_operand" "r") > + (const_int 1) > + (match_operand 2 "immediate_operand" "i")))] > + "TARGET_XTHEADBS" Add range check like *bexti pattern? TARGET_XTHEADBS && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode) > + "th.tst\t%0,%1,%2" > + [(set_attr "type" "bitmanip")])
On Fri, Feb 24, 2023 at 8:37 AM Kito Cheng <kito.cheng@sifive.com> wrote: > > > diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md > > index 158e9124c3a..2c684885850 100644 > > --- a/gcc/config/riscv/thead.md > > +++ b/gcc/config/riscv/thead.md > > @@ -29,3 +29,14 @@ (define_insn "*th_addsl" > > "th.addsl\t%0,%3,%1,%2" > > [(set_attr "type" "bitmanip") > > (set_attr "mode" "<X:MODE>")]) > > + > > +;; XTheadBs > > + > > +(define_insn "*th_tst" > > + [(set (match_operand:X 0 "register_operand" "=r") > > + (zero_extract:X (match_operand:X 1 "register_operand" "r") > > + (const_int 1) > > + (match_operand 2 "immediate_operand" "i")))] > > + "TARGET_XTHEADBS" > > Add range check like *bexti pattern? > > TARGET_XTHEADBS && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode) Ok. Thanks, Christoph > > > + "th.tst\t%0,%1,%2" > > + [(set_attr "type" "bitmanip")])
On Fri, 24 Feb 2023, Christoph Muellner wrote: > diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md > index 158e9124c3a..2c684885850 100644 > --- a/gcc/config/riscv/thead.md > +++ b/gcc/config/riscv/thead.md > @@ -29,3 +29,14 @@ (define_insn "*th_addsl" > "th.addsl\t%0,%3,%1,%2" > [(set_attr "type" "bitmanip") > (set_attr "mode" "<X:MODE>")]) > + > +;; XTheadBs > + > +(define_insn "*th_tst" > + [(set (match_operand:X 0 "register_operand" "=r") > + (zero_extract:X (match_operand:X 1 "register_operand" "r") > + (const_int 1) > + (match_operand 2 "immediate_operand" "i")))] (Here and same elsewhere.) You're unlikely to get other constant operands in that pattern, but FWIW, the actual matching pair for just CONST_INT is "const_int_operand" for the predicate and "n" for the constraint. Using the right predicate and constraint will also help the generated part of recog be a few nanoseconds faster. ;) brgds, H-P
On Sun, Feb 26, 2023 at 12:42 AM Hans-Peter Nilsson <hp@bitrange.com> wrote: > > On Fri, 24 Feb 2023, Christoph Muellner wrote: > > diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md > > index 158e9124c3a..2c684885850 100644 > > --- a/gcc/config/riscv/thead.md > > +++ b/gcc/config/riscv/thead.md > > @@ -29,3 +29,14 @@ (define_insn "*th_addsl" > > "th.addsl\t%0,%3,%1,%2" > > [(set_attr "type" "bitmanip") > > (set_attr "mode" "<X:MODE>")]) > > + > > +;; XTheadBs > > + > > +(define_insn "*th_tst" > > + [(set (match_operand:X 0 "register_operand" "=r") > > + (zero_extract:X (match_operand:X 1 "register_operand" "r") > > + (const_int 1) > > + (match_operand 2 "immediate_operand" "i")))] > > (Here and same elsewhere.) > > You're unlikely to get other constant operands in that pattern, > but FWIW, the actual matching pair for just CONST_INT is > "const_int_operand" for the predicate and "n" for the > constraint. Using the right predicate and constraint will also > help the generated part of recog be a few nanoseconds faster. ;) Thank you for that comment! I think what you mean would look like this: (define_insn "*th_tst" [(set (match_operand:X 0 "register_operand" "=r") (zero_extract:X (match_operand:X 1 "register_operand" "r") (match_operand 3 "const_int_operand" "n") (match_operand 2 "immediate_operand" "i")))] "TARGET_XTHEADBS && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode) && UINTVAL (operands[3]) == 1" "th.tst\t%0,%1,%2" [(set_attr "type" "bitmanip")]) So while we have more generic form in the pattern, the condition needs to check that the operand is equal to 1. I can change this in the patch (I don't have strong opinions about this and I do care about the nanosecond). However, I think this goes beyond this patchset. Because a single git grep shows many examples of "const_int " matches in GCC's backends. Examples can be found in gcc/config/riscv/bitmanip.md, gcc/config/aarch64/aarch64.md,... So it feels like changing the patch to use const_int_operand would go against common practice. @Kito: Any preferences about this? Thanks, Christoph
On Tue, 28 Feb 2023, Christoph Müllner wrote: > On Sun, Feb 26, 2023 at 12:42 AM Hans-Peter Nilsson <hp@bitrange.com> wrote: > > > > On Fri, 24 Feb 2023, Christoph Muellner wrote: > > > diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md > > > index 158e9124c3a..2c684885850 100644 > > > --- a/gcc/config/riscv/thead.md > > > +++ b/gcc/config/riscv/thead.md > > > @@ -29,3 +29,14 @@ (define_insn "*th_addsl" > > > "th.addsl\t%0,%3,%1,%2" > > > [(set_attr "type" "bitmanip") > > > (set_attr "mode" "<X:MODE>")]) > > > + > > > +;; XTheadBs > > > + > > > +(define_insn "*th_tst" > > > + [(set (match_operand:X 0 "register_operand" "=r") > > > + (zero_extract:X (match_operand:X 1 "register_operand" "r") > > > + (const_int 1) > > > + (match_operand 2 "immediate_operand" "i")))] > > > > (Here and same elsewhere.) > > > > You're unlikely to get other constant operands in that pattern, > > but FWIW, the actual matching pair for just CONST_INT is > > "const_int_operand" for the predicate and "n" for the > > constraint. Using the right predicate and constraint will also > > help the generated part of recog be a few nanoseconds faster. ;) > > Thank you for that comment! > I think what you mean would look like this: > > (define_insn "*th_tst" > [(set (match_operand:X 0 "register_operand" "=r") > (zero_extract:X (match_operand:X 1 "register_operand" "r") > (match_operand 3 "const_int_operand" "n") > (match_operand 2 "immediate_operand" "i")))] No; misunderstanding. Keep the (const_int 1) but replace (match_operand 2 "immediate_operand" "i") with (match_operand 2 "const_int_operand" "n") brgds, H-P
On Wed, Mar 1, 2023 at 1:19 AM Hans-Peter Nilsson <hp@bitrange.com> wrote: > > > > On Tue, 28 Feb 2023, Christoph Müllner wrote: > > > On Sun, Feb 26, 2023 at 12:42 AM Hans-Peter Nilsson <hp@bitrange.com> wrote: > > > > > > On Fri, 24 Feb 2023, Christoph Muellner wrote: > > > > diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md > > > > index 158e9124c3a..2c684885850 100644 > > > > --- a/gcc/config/riscv/thead.md > > > > +++ b/gcc/config/riscv/thead.md > > > > @@ -29,3 +29,14 @@ (define_insn "*th_addsl" > > > > "th.addsl\t%0,%3,%1,%2" > > > > [(set_attr "type" "bitmanip") > > > > (set_attr "mode" "<X:MODE>")]) > > > > + > > > > +;; XTheadBs > > > > + > > > > +(define_insn "*th_tst" > > > > + [(set (match_operand:X 0 "register_operand" "=r") > > > > + (zero_extract:X (match_operand:X 1 "register_operand" "r") > > > > + (const_int 1) > > > > + (match_operand 2 "immediate_operand" "i")))] > > > > > > (Here and same elsewhere.) > > > > > > You're unlikely to get other constant operands in that pattern, > > > but FWIW, the actual matching pair for just CONST_INT is > > > "const_int_operand" for the predicate and "n" for the > > > constraint. Using the right predicate and constraint will also > > > help the generated part of recog be a few nanoseconds faster. ;) > > > > Thank you for that comment! > > I think what you mean would look like this: > > > > (define_insn "*th_tst" > > [(set (match_operand:X 0 "register_operand" "=r") > > (zero_extract:X (match_operand:X 1 "register_operand" "r") > > (match_operand 3 "const_int_operand" "n") > > (match_operand 2 "immediate_operand" "i")))] > > No; misunderstanding. Keep the (const_int 1) but replace > (match_operand 2 "immediate_operand" "i") with > (match_operand 2 "const_int_operand" "n") Ah, yes, this makes sense! Thanks! > > brgds, H-P
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index f11b7949a49..e35bc0a745b 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -2400,8 +2400,8 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN *total = COSTS_N_INSNS (SINGLE_SHIFT_COST); return true; } - /* bext pattern for zbs. */ - if (TARGET_ZBS && outer_code == SET + /* bit extraction pattern (zbs:bext, xtheadbs:tst). */ + if ((TARGET_ZBS || TARGET_XTHEADBS) && outer_code == SET && GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 1) { diff --git a/gcc/config/riscv/thead.md b/gcc/config/riscv/thead.md index 158e9124c3a..2c684885850 100644 --- a/gcc/config/riscv/thead.md +++ b/gcc/config/riscv/thead.md @@ -29,3 +29,14 @@ (define_insn "*th_addsl" "th.addsl\t%0,%3,%1,%2" [(set_attr "type" "bitmanip") (set_attr "mode" "<X:MODE>")]) + +;; XTheadBs + +(define_insn "*th_tst" + [(set (match_operand:X 0 "register_operand" "=r") + (zero_extract:X (match_operand:X 1 "register_operand" "r") + (const_int 1) + (match_operand 2 "immediate_operand" "i")))] + "TARGET_XTHEADBS" + "th.tst\t%0,%1,%2" + [(set_attr "type" "bitmanip")]) diff --git a/gcc/testsuite/gcc.target/riscv/xtheadbs-tst.c b/gcc/testsuite/gcc.target/riscv/xtheadbs-tst.c new file mode 100644 index 00000000000..674cec09128 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/xtheadbs-tst.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv32gc_xtheadbs" { target { rv32 } } } */ +/* { dg-options "-march=rv64gc_xtheadbs" { target { rv64 } } } */ +/* { dg-skip-if "" { *-*-* } { "-O0" } } */ + +long +foo1 (long i) +{ + return 1L & (i >> 20); +} + +/* { dg-final { scan-assembler-times "th.tst\t" 1 } } */ +/* { dg-final { scan-assembler-not "andi" } } */