From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 7DC933875463 for ; Tue, 28 Nov 2023 13:16:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7DC933875463 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7DC933875463 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701177404; cv=none; b=u/JQgj5t6f9sqUKZ068kLaIQ4GmZu5LKy7OKWHc+lLQ31CE2KxRQrt3dIoDZmECsJvRsO4E7XrmlexvRD5GP9K9fsWWb2Cgl5Q4L99bOsf9FIfsPjGTsM7YvKj4BjQ3CSknKCfYG0p7RvTc6o8GfzuQPeUMNVn1eCt6VENmDKeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701177404; c=relaxed/simple; bh=PIEGNEtzrpb2S/5m6RQIH53QGF06ACmkAC/f/jP/jC8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=BkkD23FAAL/Uq8bs6dLjGJ5+U3JFwUjllyH4DcQKNztCRpw0HTPo2Yd8gUvqXpMthLRg4o+dm9cBvGuiyy/VlHTM9JhZlR3ofwx8GJH9PYyHaI+ccN6WKVuh6XIUzN8ZwxzvdoTkndgbm5+K3wNdcplbbCJA3GDea5OLHSTj+p0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40b4c2ef584so6104755e9.3 for ; Tue, 28 Nov 2023 05:16:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1701177400; x=1701782200; darn=gcc.gnu.org; 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=CarMoq6VtK7I0QRM2rV04wMmuVPxbU7jXxXudc1tyeA=; b=eBTHvbpc5OAa5SQHehtY1oaWQp+S+SaFn1ILqCKv58Ij49fQ2pf95wzt4yNJIC6ag0 3Xh1X3T86doHL9FQoquAMdLLq+h6EyfWum0AxS/Hx1D3q2Eae9cnzSEC4cvnhc/PQXVi du7A3PZwc8lDUpdgWuTD9vHeFk3kVWgUj6z7+JYH1nfC0ylnrB7riJ5bq5U34gBRWBhk DiIEvqbPiIbNLyuFy5tdtYfAwNs0uWxRrJre1PeYwvgCIs2pqvA0KgPFK+l64f/ejIDQ t/Rx2yA/dKWkKONyBLU/JySyxM9v7nZKJLXz1sOKnU50bcM6LjmYbXgvwuEZLqC18bjx 1lZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701177400; x=1701782200; 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=CarMoq6VtK7I0QRM2rV04wMmuVPxbU7jXxXudc1tyeA=; b=IP7o84v6/+60cVGtn6t74wn+jEbUUJ4Ob0HUz7IYYT4IYtVLZYrMSlV/nEDFdRBtU+ sDfhTBhhDTy1udly1KRaihU4sz19jsR8BPdsa8oK9Zm6oCamkHvaSMDRBR0YEn3/qnGt rW8Q/fkUiB8fOJ3bQvIpOhvarp65oaxye1KT9z9KLrS7jj4K7p3uxS30muc8O0A6tjgD /HRszDduiPUNAbCh0V6a4TtLnyGYOktl4cYUwP9ytt4Vf2ZKyw2rmqxq+1ZdOl8ABmuB HpXY1F8JxaYsuem8jPBwwV0AHHUXvnvpXqbrfbbqscNYUfVB7psh8yPBv6zPC6F8lzVs t/5g== X-Gm-Message-State: AOJu0Ywh6ra3ygJSM+vyzevXxLUhc105yQ9WbHcakTY3A3+lXwuv9ZvZ fpt5herlJCNepCji3xS3lzjbIDmVvvSFlnAm/hBDeA== X-Google-Smtp-Source: AGHT+IFE4nyb4KpGIJh78cmgmXVj9EWM9KyxW5bWEUImCldLVZE0MSfXmXSLmLRTGYoW5wWf3J6QUA== X-Received: by 2002:a05:600c:154b:b0:40b:4c66:874e with SMTP id f11-20020a05600c154b00b0040b4c66874emr1424907wmg.2.1701177399515; Tue, 28 Nov 2023 05:16:39 -0800 (PST) Received: from troughton.sou.embecosm-corp.com ([212.69.42.53]) by smtp.gmail.com with ESMTPSA id s9-20020a05600c45c900b0040b3829eb50sm15991844wmo.20.2023.11.28.05.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 05:16:38 -0800 (PST) From: Mary Bennett To: gcc-patches@gcc.gnu.org Cc: mary.bennett@embecosm.com Subject: [PATCH v3 3/3] RISC-V: Add support for XCVbi extension in CV32E40P Date: Tue, 28 Nov 2023 13:16:15 +0000 Message-Id: <20231128131615.3986922-4-mary.bennett@embecosm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231128131615.3986922-1-mary.bennett@embecosm.com> References: <20231113133530.1727444-1-mary.bennett@embecosm.com> <20231128131615.3986922-1-mary.bennett@embecosm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,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 List-Id: Spec: github.com/openhwgroup/core-v-sw/blob/master/specifications/corev-builtin-spec.md Contributors: Mary Bennett Nandni Jamnadas Pietra Ferreira Charlie Keaney Jessica Mills Craig Blackmore Simon Cook Jeremy Bennett Helene Chelin gcc/ChangeLog: * common/config/riscv/riscv-common.cc: Create XCVbi extension support. * config/riscv/riscv.opt: Likewise. * config/riscv/corev.md: Implement cv_branch pattern for cv.beqimm and cv.bneimm. * config/riscv/riscv.md: Add CORE-V branch immediate to RISC-V branch instruction pattern. * config/riscv/constraints.md: Implement constraints cv_bi_s5 - signed 5-bit immediate. * config/riscv/predicates.md: Implement predicate const_int5s_operand - signed 5 bit immediate. * doc/sourcebuild.texi: Add XCVbi documentation. gcc/testsuite/ChangeLog: * gcc.target/riscv/cv-bi-beqimm-compile-1.c: New test. * gcc.target/riscv/cv-bi-beqimm-compile-2.c: New test. * gcc.target/riscv/cv-bi-bneimm-compile-1.c: New test. * gcc.target/riscv/cv-bi-bneimm-compile-2.c: New test. * lib/target-supports.exp: Add proc for XCVbi. --- gcc/common/config/riscv/riscv-common.cc | 2 + gcc/config/riscv/constraints.md | 6 +++ gcc/config/riscv/corev.md | 14 ++++++ gcc/config/riscv/predicates.md | 4 ++ gcc/config/riscv/riscv.md | 4 ++ gcc/config/riscv/riscv.opt | 2 + gcc/doc/sourcebuild.texi | 3 ++ .../gcc.target/riscv/cv-bi-beqimm-compile-1.c | 17 +++++++ .../gcc.target/riscv/cv-bi-beqimm-compile-2.c | 48 +++++++++++++++++++ .../gcc.target/riscv/cv-bi-bneimm-compile-1.c | 17 +++++++ .../gcc.target/riscv/cv-bi-bneimm-compile-2.c | 48 +++++++++++++++++++ gcc/testsuite/lib/target-supports.exp | 13 +++++ 12 files changed, 178 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/cv-bi-beqimm-compile-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/cv-bi-beqimm-compile-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/cv-bi-bneimm-compile-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/cv-bi-bneimm-compile-2.c diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index c8c0d0a2252..125f8fb71f7 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -313,6 +313,7 @@ static const struct riscv_ext_version riscv_ext_version_table[] = {"xcvmac", ISA_SPEC_CLASS_NONE, 1, 0}, {"xcvalu", ISA_SPEC_CLASS_NONE, 1, 0}, {"xcvelw", ISA_SPEC_CLASS_NONE, 1, 0}, + {"xcvbi", ISA_SPEC_CLASS_NONE, 1, 0}, {"xtheadba", ISA_SPEC_CLASS_NONE, 1, 0}, {"xtheadbb", ISA_SPEC_CLASS_NONE, 1, 0}, @@ -1678,6 +1679,7 @@ static const riscv_ext_flag_table_t riscv_ext_flag_table[] = {"xcvmac", &gcc_options::x_riscv_xcv_subext, MASK_XCVMAC}, {"xcvalu", &gcc_options::x_riscv_xcv_subext, MASK_XCVALU}, {"xcvelw", &gcc_options::x_riscv_xcv_subext, MASK_XCVELW}, + {"xcvbi", &gcc_options::x_riscv_xcv_subext, MASK_XCVBI}, {"xtheadba", &gcc_options::x_riscv_xthead_subext, MASK_XTHEADBA}, {"xtheadbb", &gcc_options::x_riscv_xthead_subext, MASK_XTHEADBB}, diff --git a/gcc/config/riscv/constraints.md b/gcc/config/riscv/constraints.md index 2711efe68c5..718b4bd77df 100644 --- a/gcc/config/riscv/constraints.md +++ b/gcc/config/riscv/constraints.md @@ -247,3 +247,9 @@ (and (match_code "const_int") (and (match_test "IN_RANGE (ival, 0, 1073741823)") (match_test "exact_log2 (ival + 1) != -1")))) + +(define_constraint "CV_bi_sign5" + "@internal + A 5-bit signed immediate for CORE-V Immediate Branch." + (and (match_code "const_int") + (match_test "IN_RANGE (ival, -16, 15)"))) diff --git a/gcc/config/riscv/corev.md b/gcc/config/riscv/corev.md index 92bf0b5d6a6..f6a1f916d7e 100644 --- a/gcc/config/riscv/corev.md +++ b/gcc/config/riscv/corev.md @@ -706,3 +706,17 @@ [(set_attr "type" "load") (set_attr "mode" "SI")]) + +;; XCVBI Builtins +(define_insn "cv_branch" + [(set (pc) + (if_then_else + (match_operator 1 "equality_operator" + [(match_operand:X 2 "register_operand" "r") + (match_operand:X 3 "const_int5s_operand" "CV_bi_sign5")]) + (label_ref (match_operand 0 "" "")) + (pc)))] + "TARGET_XCVBI" + "cv.b%C1imm\t%2,%3,%0" + [(set_attr "type" "branch") + (set_attr "mode" "none")]) diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md index ff213e5f8a3..dfe0db02ac1 100644 --- a/gcc/config/riscv/predicates.md +++ b/gcc/config/riscv/predicates.md @@ -406,6 +406,10 @@ (ior (match_operand 0 "register_operand") (match_code "const_int"))) +(define_predicate "const_int5s_operand" + (and (match_code "const_int") + (match_test "IN_RANGE (INTVAL (op), -16, 15)"))) + ;; Predicates for the V extension. (define_special_predicate "vector_length_operand" (ior (match_operand 0 "pmode_register_operand") diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index 935eeb7fd8e..467cd09d8b0 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -2647,6 +2647,10 @@ (pc)))] "" { + if (TARGET_XCVBI && const_int5s_operand (operands[3], SImode) + && (GET_CODE (operands[1]) == EQ || GET_CODE (operands[1]) == NE)) + return "cv.b%C1imm\t%2,%3,%0"; + if (get_attr_length (insn) == 12) return "b%N1\t%2,%z3,1f; jump\t%l0,ra; 1:"; diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index bfa0945daca..e11172388b5 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -413,6 +413,8 @@ Mask(XCVALU) Var(riscv_xcv_subext) Mask(XCVELW) Var(riscv_xcv_subext) +Mask(XCVBI) Var(riscv_xcv_subext) + TargetVariable int riscv_xthead_subext diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi index d63b11d245c..3d72b88a4a9 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -2484,6 +2484,9 @@ Test system has support for the CORE-V ALU extension. @item cv_elw Test system has support for the CORE-V ELW extension. +@item cv_bi +Test system has support for the CORE-V BI extension. + @end table @subsubsection Other hardware attributes diff --git a/gcc/testsuite/gcc.target/riscv/cv-bi-beqimm-compile-1.c b/gcc/testsuite/gcc.target/riscv/cv-bi-beqimm-compile-1.c new file mode 100644 index 00000000000..5b6ba5b8ae6 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/cv-bi-beqimm-compile-1.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target cv_bi } */ +/* { dg-options "-march=rv32i_xcvbi -mabi=ilp32" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */ + +/* __builtin_expect is used to provide the compiler with + branch prediction information and to direct the compiler + to the expected flow through the code. */ + +int +foo1 (int a, int x, int y) +{ + a = __builtin_expect (a, 12); + return a != 10 ? x : y; +} + +/* { dg-final { scan-assembler-times "cv\\.beqimm\t\(\?\:t\[0-6\]\|a\[0-7\]\|s\[1-11\]\),10,\(\?\:.L\[0-9\]\)" 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/cv-bi-beqimm-compile-2.c b/gcc/testsuite/gcc.target/riscv/cv-bi-beqimm-compile-2.c new file mode 100644 index 00000000000..bb2e5843957 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/cv-bi-beqimm-compile-2.c @@ -0,0 +1,48 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target cv_bi } */ +/* { dg-options "-march=rv32i_xcvbi -mabi=ilp32" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */ + +/* __builtin_expect is used to provide the compiler with + branch prediction information and to direct the compiler + to the expected flow through the code. */ + +int +foo1 (int a, int x, int y) +{ + a = __builtin_expect (a, 10); + return a != -16 ? x : y; +} + +int +foo2 (int a, int x, int y) +{ + a = __builtin_expect (a, 10); + return a != 0 ? x : y; +} + +int +foo3 (int a, int x, int y) +{ + a = __builtin_expect (a, 10); + return a != 15 ? x : y; +} + +int +foo4 (int a, int x, int y) +{ + a = __builtin_expect (a, 10); + return a != -17 ? x : y; +} + +int +foo5 (int a, int x, int y) +{ + a = __builtin_expect (a, 10); + return a != 16 ? x : y; +} + +/* { dg-final { scan-assembler-times "cv\\.beqimm\t\(\?\:t\[0-6\]\|a\[0-7\]\|s\[1-11\]\),-16,\(\?\:.L\[0-9\]\)" 1 } } */ +/* { dg-final { scan-assembler-times "cv\\.beqimm\t\(\?\:t\[0-6\]\|a\[0-7\]\|s\[1-11\]\),0,\(\?\:.L\[0-9\]\)" 1 } } */ +/* { dg-final { scan-assembler-times "cv\\.beqimm\t\(\?\:t\[0-6\]\|a\[0-7\]\|s\[1-11\]\),15,\(\?\:.L\[0-9\]\)" 1 } } */ +/* { dg-final { scan-assembler-times "beq\t\(\?\:t\[0-6\]\|a\[0-7\]\|s\[1-11\]\),\(\?\:t\[0-6\]\|a\[0-7\]\|s\[1-11\]\),\(\?\:.L\[0-9\]+\)" 2 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/cv-bi-bneimm-compile-1.c b/gcc/testsuite/gcc.target/riscv/cv-bi-bneimm-compile-1.c new file mode 100644 index 00000000000..21eab38a08d --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/cv-bi-bneimm-compile-1.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target cv_bi } */ +/* { dg-options "-march=rv32i_xcvbi -mabi=ilp32" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */ + +/* __builtin_expect is used to provide the compiler with + branch prediction information and to direct the compiler + to the expected flow through the code. */ + +int +foo1(int a, int x, int y) +{ + a = __builtin_expect(a, 10); + return a == 10 ? x : y; +} + +/* { dg-final { scan-assembler-times "cv\\.bneimm\t\(\?\:t\[0-6\]\|a\[0-7\]\|s\[1-11\]\),10,\(\?\:.L\[0-9\]\)" 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/cv-bi-bneimm-compile-2.c b/gcc/testsuite/gcc.target/riscv/cv-bi-bneimm-compile-2.c new file mode 100644 index 00000000000..a028f684489 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/cv-bi-bneimm-compile-2.c @@ -0,0 +1,48 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target cv_bi } */ +/* { dg-options "-march=rv32i_xcvbi -mabi=ilp32" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */ + +/* __builtin_expect is used to provide the compiler with + branch prediction information and to direct the compiler + to the expected flow through the code. */ + +int +foo1(int a, int x, int y) +{ + a = __builtin_expect(a, -16); + return a == -16 ? x : y; +} + +int +foo2(int a, int x, int y) +{ + a = __builtin_expect(a, 0); + return a == 0 ? x : y; +} + +int +foo3(int a, int x, int y) +{ + a = __builtin_expect(a, 15); + return a == 15 ? x : y; +} + +int +foo4(int a, int x, int y) +{ + a = __builtin_expect(a, -17); + return a == -17 ? x : y; +} + +int +foo5(int a, int x, int y) +{ + a = __builtin_expect(a, 16); + return a == 16 ? x : y; +} + +/* { dg-final { scan-assembler-times "cv\\.bneimm\t\(\?\:t\[0-6\]\|a\[0-7\]\|s\[1-11\]\),-16,\(\?\:.L\[0-9\]\)" 1 } } */ +/* { dg-final { scan-assembler-times "cv\\.bneimm\t\(\?\:t\[0-6\]\|a\[0-7\]\|s\[1-11\]\),0,\(\?\:.L\[0-9\]\)" 1 } } */ +/* { dg-final { scan-assembler-times "cv\\.bneimm\t\(\?\:t\[0-6\]\|a\[0-7\]\|s\[1-11\]\),15,\(\?\:.L\[0-9\]\)" 1 } } */ +/* { dg-final { scan-assembler-times "bne\t\(\?\:t\[0-6\]\|a\[0-7\]\|s\[1-11\]\),\(\?\:t\[0-6\]\|a\[0-7\]\|s\[1-11\]\),\(\?\:.L\[0-9\]+\)" 2 } } */ diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index c324a7898fc..9c8e2ed1896 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -13160,6 +13160,19 @@ proc check_effective_target_cv_elw { } { } "-march=rv32i_xcvelw" ] } +# Return 1 if the CORE-V BI extension is available +proc check_effective_target_cv_bi { } { + if { !([istarget riscv*-*-*]) } { + return 0 + } + return [check_no_compiler_messages cv_bi object { + void foo (void) + { + asm ("cv.beqimm t0, -16, foo"); + } + } "-march=rv32i_xcvbi" ] +} + proc check_effective_target_loongarch_sx { } { return [check_no_compiler_messages loongarch_lsx assembly { #if !defined(__loongarch_sx) -- 2.34.1