From patchwork Tue Dec 12 19:32:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mary Bennett X-Patchwork-Id: 82001 X-Patchwork-Delegate: kito.cheng@gmail.com Return-Path: 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 D71FC385C405 for ; Tue, 12 Dec 2023 19:33:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id AE4AF3858C2F for ; Tue, 12 Dec 2023 19:33:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE4AF3858C2F 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 AE4AF3858C2F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702409598; cv=none; b=DPYpcMycauiHd63X+UYWkwnNnHlBHjv2HGSJ+TL4C6zFHzxgSmv9SsyPikfHWlO7vFwSg3fqPXHD6bCXjBl5/uGH0QvayYp+pUbhanYmqRzonzskqjjLu2A+9S4qorK0UNnndE1dqOmBnK8ILztqtaGZgByvpFqlZkpkLJl7Q9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702409598; c=relaxed/simple; bh=kLW5gvZR7/Xvn0pqoT6ymTy0Y1sNe9eI537hSe36nOI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=vq9/e1jafzTqq0EN4ZK70x3gaonGSSf5MIhQxPQ3cXj9P2fOFh5pOrEsShKCli7zwzJECudcxmME0di1pBy+uvkAhWqA4uVJTVfgEPUdnnKJnYTfswrgi5skPI30BdM03t7XnqZM152IM0f8p08Te5MZe4hc8O//eN1+vwiZ+DU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40c29f7b068so57400905e9.0 for ; Tue, 12 Dec 2023 11:33:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1702409595; x=1703014395; 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=sSuHUA4mdFmIgo7RQ/etAxazrYatB6vswvSr2C5WUpI=; b=JdhhE2w4eS+upiqGruALS/bqP+tJ13QVLopSX9zEcLvfGGzNcf9LGgpA1BEmRBGEpK D1jfPGR6V86Cys0DdcxYYHEZ93TbDhOVME2NXIHrXMLQgxLLj7xOZ5l9IeOPqjbUCHxy JbQaXnwHqjvVMKgTzB5LjOhRafFDrIsxHPoACoD5zzj1mhiOxferjCukd2fHyM1V6N16 hW6YXNcVcs3Gd3FHddQhYvqE2chfeC/CnUJ5cpT3ncy5AgVe6OG4nP8RlC3KkwadUZpG 56l0+B4deaI4BmGRUGEdY40wDuQp5YbMWX0gFNjovdd0dtGJYRSqRzrITCfrJQ3pfAxg eddg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702409595; x=1703014395; 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=sSuHUA4mdFmIgo7RQ/etAxazrYatB6vswvSr2C5WUpI=; b=GO4BHsz+STiBlt3UPnuxmzuiGE/8DsFsOMQEFANH1hujdukw3x67Pqj0yKnp8UrVqi /TT9uPB+yblG60B/b5jKNDHMttPH2+ftL2hAYRlQVjKz+VP7W1T+2joLtXOsBSVbNpUV FaqKff4pLJhB0EIVtVbE18Q9yjj8jnvI4pYmZ/ttWQkUkbJePbjH/URgoww6xcQudU2w gEKBElhPWMJ3U9yw510LYe4g3In2GvDlv0aymw6O8yBxAHhnMVdwjQrJbHSNup6ppAFP f6aXYBrRr9GEjjSfAG5ggf0F5mRcWCags74rTL1JW3+9z7db+uRxwEBXG9VCcm8VzhRR gfjQ== X-Gm-Message-State: AOJu0Yy3RFz5c+wejxVrc733k+B1Sxfhk1T3QCKyR0CPtm7o5k/QzP7+ s3skkacHoWRBFqC5afkg8Uc61QhrNVV9ZMOWzgg= X-Google-Smtp-Source: AGHT+IGZc74ja7x1/gU7bvp3gsqldcyxoOqO0InR/umar/If/DA1pTFN51O4qWjLyvakh9eXhGt0gw== X-Received: by 2002:a05:600c:314f:b0:40c:467a:6a5a with SMTP id h15-20020a05600c314f00b0040c467a6a5amr2016201wmo.122.1702409594737; Tue, 12 Dec 2023 11:33:14 -0800 (PST) Received: from troughton.lym.embecosm-corp.com ([212.69.42.53]) by smtp.gmail.com with ESMTPSA id fm14-20020a05600c0c0e00b00407b93d8085sm19934150wmb.27.2023.12.12.11.33.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 11:33:14 -0800 (PST) From: Mary Bennett To: gcc-patches@gcc.gnu.org Cc: mary.bennett@embecosm.com Subject: [PATCH v4 1/3] RISC-V: Add support for XCVelw extension in CV32E40P Date: Tue, 12 Dec 2023 19:32:51 +0000 Message-Id: <20231212193253.220195-2-mary.bennett@embecosm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212193253.220195-1-mary.bennett@embecosm.com> References: <20231128131615.3986922-1-mary.bennett@embecosm.com> <20231212193253.220195-1-mary.bennett@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org 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: Add XCVelw. * config/riscv/corev.def: Likewise. * config/riscv/corev.md: Likewise. * config/riscv/riscv-builtins.cc (AVAIL): Likewise. * config/riscv/riscv-ftypes.def: Likewise. * config/riscv/riscv.opt: Likewise. * doc/extend.texi: Add XCVelw builtin documentation. * doc/sourcebuild.texi: Likewise. gcc/testsuite/ChangeLog: * gcc.target/riscv/cv-elw-compile-1.c: Create test for cv.elw. * testsuite/lib/target-supports.exp: Add proc for the XCVelw extension. --- gcc/common/config/riscv/riscv-common.cc | 2 ++ gcc/config/riscv/corev.def | 3 +++ gcc/config/riscv/corev.md | 15 +++++++++++++++ gcc/config/riscv/riscv-builtins.cc | 2 ++ gcc/config/riscv/riscv-ftypes.def | 1 + gcc/config/riscv/riscv.opt | 2 ++ gcc/doc/extend.texi | 8 ++++++++ gcc/doc/sourcebuild.texi | 3 +++ .../gcc.target/riscv/cv-elw-elw-compile-1.c | 11 +++++++++++ gcc/testsuite/lib/target-supports.exp | 13 +++++++++++++ 10 files changed, 60 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/cv-elw-elw-compile-1.c diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 5111626157b..c8c0d0a2252 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -312,6 +312,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}, {"xtheadba", ISA_SPEC_CLASS_NONE, 1, 0}, {"xtheadbb", ISA_SPEC_CLASS_NONE, 1, 0}, @@ -1676,6 +1677,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}, {"xtheadba", &gcc_options::x_riscv_xthead_subext, MASK_XTHEADBA}, {"xtheadbb", &gcc_options::x_riscv_xthead_subext, MASK_XTHEADBB}, diff --git a/gcc/config/riscv/corev.def b/gcc/config/riscv/corev.def index 17580df3c41..3b9ec029d06 100644 --- a/gcc/config/riscv/corev.def +++ b/gcc/config/riscv/corev.def @@ -41,3 +41,6 @@ RISCV_BUILTIN (cv_alu_subN, "cv_alu_subN", RISCV_BUILTIN_DIRECT, RISCV_SI_FT RISCV_BUILTIN (cv_alu_subuN, "cv_alu_subuN", RISCV_BUILTIN_DIRECT, RISCV_USI_FTYPE_USI_USI_UQI, cvalu), RISCV_BUILTIN (cv_alu_subRN, "cv_alu_subRN", RISCV_BUILTIN_DIRECT, RISCV_SI_FTYPE_SI_SI_UQI, cvalu), RISCV_BUILTIN (cv_alu_subuRN, "cv_alu_subuRN",RISCV_BUILTIN_DIRECT, RISCV_USI_FTYPE_USI_USI_UQI, cvalu), + +// XCVELW +RISCV_BUILTIN (cv_elw_elw_si, "cv_elw_elw", RISCV_BUILTIN_DIRECT, RISCV_USI_FTYPE_VOID_PTR, cvelw), diff --git a/gcc/config/riscv/corev.md b/gcc/config/riscv/corev.md index 1350bd4b81e..c7a2ba07bcc 100644 --- a/gcc/config/riscv/corev.md +++ b/gcc/config/riscv/corev.md @@ -24,6 +24,9 @@ UNSPEC_CV_ALU_CLIPR UNSPEC_CV_ALU_CLIPU UNSPEC_CV_ALU_CLIPUR + + ;;CORE-V EVENT LOAD + UNSPECV_CV_ELW ]) ;; XCVMAC extension. @@ -691,3 +694,15 @@ cv.suburnr\t%0,%2,%3" [(set_attr "type" "arith") (set_attr "mode" "SI")]) + +;; XCVELW builtins +(define_insn "riscv_cv_elw_elw_si" + [(set (match_operand:SI 0 "register_operand" "=r") + (unspec_volatile [(match_operand:SI 1 "move_operand" "p")] + UNSPECV_CV_ELW))] + + "TARGET_XCVELW && !TARGET_64BIT" + "cv.elw\t%0,%a1" + + [(set_attr "type" "load") + (set_attr "mode" "SI")]) diff --git a/gcc/config/riscv/riscv-builtins.cc b/gcc/config/riscv/riscv-builtins.cc index fc3976f3ba1..5ee11ebe3bc 100644 --- a/gcc/config/riscv/riscv-builtins.cc +++ b/gcc/config/riscv/riscv-builtins.cc @@ -128,6 +128,7 @@ AVAIL (hint_pause, (!0)) // CORE-V AVAIL AVAIL (cvmac, TARGET_XCVMAC && !TARGET_64BIT) AVAIL (cvalu, TARGET_XCVALU && !TARGET_64BIT) +AVAIL (cvelw, TARGET_XCVELW && !TARGET_64BIT) /* Construct a riscv_builtin_description from the given arguments. @@ -168,6 +169,7 @@ AVAIL (cvalu, TARGET_XCVALU && !TARGET_64BIT) #define RISCV_ATYPE_HI intHI_type_node #define RISCV_ATYPE_SI intSI_type_node #define RISCV_ATYPE_VOID_PTR ptr_type_node +#define RISCV_ATYPE_INT_PTR integer_ptr_type_node /* RISCV_FTYPE_ATYPESN takes N RISCV_FTYPES-like type codes and lists their associated RISCV_ATYPEs. */ diff --git a/gcc/config/riscv/riscv-ftypes.def b/gcc/config/riscv/riscv-ftypes.def index 0d1e4dd061e..3e7d5c69503 100644 --- a/gcc/config/riscv/riscv-ftypes.def +++ b/gcc/config/riscv/riscv-ftypes.def @@ -30,6 +30,7 @@ DEF_RISCV_FTYPE (0, (USI)) DEF_RISCV_FTYPE (0, (VOID)) DEF_RISCV_FTYPE (1, (VOID, USI)) DEF_RISCV_FTYPE (1, (VOID, VOID_PTR)) +DEF_RISCV_FTYPE (1, (USI, VOID_PTR)) DEF_RISCV_FTYPE (1, (USI, USI)) DEF_RISCV_FTYPE (1, (UDI, UDI)) DEF_RISCV_FTYPE (1, (USI, UQI)) diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index 11526f9cc2a..bfa0945daca 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -411,6 +411,8 @@ Mask(XCVMAC) Var(riscv_xcv_subext) Mask(XCVALU) Var(riscv_xcv_subext) +Mask(XCVELW) Var(riscv_xcv_subext) + TargetVariable int riscv_xthead_subext diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 9474e9398bb..b89aa915b7e 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -22084,6 +22084,14 @@ Generated assembler @code{cv.subuRN} if the uint8_t operand is a constant and in Generated assembler @code{cv.subuRNr} if the it is a register. @end deftypefn +These built-in functions are available for the CORE-V Event Load machine +architecture. For more information on CORE-V ELW builtins, please see +@uref{https://github.com/openhwgroup/core-v-sw/blob/master/specifications/corev-builtin-spec.md#listing-of-event-load-word-builtins-xcvelw} + +@deftypefn {Built-in Function} {uint32_t} __builtin_riscv_cv_elw_elw (uint32_t *) +Generated assembler @code{cv.elw} +@end deftypefn + @node RX Built-in Functions @subsection RX Built-in Functions GCC supports some of the RX instructions which cannot be expressed in diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi index e27e0fa606c..d63b11d245c 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -2481,6 +2481,9 @@ Test system has support for the CORE-V MAC extension. @item cv_alu Test system has support for the CORE-V ALU extension. +@item cv_elw +Test system has support for the CORE-V ELW extension. + @end table @subsubsection Other hardware attributes diff --git a/gcc/testsuite/gcc.target/riscv/cv-elw-elw-compile-1.c b/gcc/testsuite/gcc.target/riscv/cv-elw-elw-compile-1.c new file mode 100644 index 00000000000..30f951c3f0a --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/cv-elw-elw-compile-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target cv_elw } */ +/* { dg-options "-march=rv32i_xcvelw -mabi=ilp32" } */ + +int +foo (void* b) +{ + return __builtin_riscv_cv_elw_elw (b + 8); +} + +/* { dg-final { scan-assembler-times "cv\\.elw\t\[a-z\]\[0-99\],\[0-99\]\\(\[a-z\]\[0-99\]\\)" 1 } } */ diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 87b2ae58720..c324a7898fc 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -13147,6 +13147,19 @@ proc check_effective_target_cv_alu { } { } "-march=rv32i_xcvalu" ] } +# Return 1 if the CORE-V ELW extension is available. +proc check_effective_target_cv_elw { } { + if { !([istarget riscv*-*-*]) } { + return 0 + } + return [check_no_compiler_messages cv_elw object { + void foo (void) + { + asm ("cv.elw x0, 0(x0)"); + } + } "-march=rv32i_xcvelw" ] +} + proc check_effective_target_loongarch_sx { } { return [check_no_compiler_messages loongarch_lsx assembly { #if !defined(__loongarch_sx) From patchwork Tue Dec 12 19:32:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mary Bennett X-Patchwork-Id: 82002 X-Patchwork-Delegate: kito.cheng@gmail.com Return-Path: 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 CE84C3858C78 for ; Tue, 12 Dec 2023 19:33:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 229693858298 for ; Tue, 12 Dec 2023 19:33:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 229693858298 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 229693858298 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702409599; cv=none; b=XlKAKOLGNb6w8MnTEV7w/skVqosA15MwitWDP0MTrV69mqYQk3EnLUq5OFByjNBJ11IKp64fQVpy3DdoqtMo3C72UtsYEfoQk4u7ge5n9FoqQteMpeR9RsgLbyH4fWc1MRxA2pF7MaOwqFm4q05PySNCXCuYZbioy6OdT3zI23A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702409599; c=relaxed/simple; bh=c4g4L1HVhcEx4voUgNdEp7OXmXsxQctK1+PTGIAwy0I=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=YIV0hKbFQw2F5qtR3vv6SWBi3uSg63NpfyYlTTcOr+TBOQOtMzGQtqt5i5rJVafYIqcROvPepaAWDvLS8BHq8y5LZ6qgx8T0tLNsDvCvgrIOUtg0HFtVct+smM/SO6yaJ8OmQNyLIwL3K6vxj46Z/a3hSSxa9CxjTkk/u5U2sjw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40c25973988so62956535e9.2 for ; Tue, 12 Dec 2023 11:33:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1702409596; x=1703014396; 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=gdagdi7iMIzKnwsj7w7AjThQJGs4qjfnY9NtezQreuc=; b=BUD9v0bq9DTyOdSsA7QGp7788QGsNFlflxHHGa6g75uLfbhL3zXdrHGuPqtOa44DSi XSSSWTGNlXYcxsUEQ/R4elBSH4+94ImQY4NmELQsn7EdGeO+cDBIVg0NP0kq7yEiLbnr UDioxYt3QXIHWHJuCUNduK9tYMUJRVU9W26GoAJ/CXwqIYagNaPzsvcS+I3iTKCY1wlW TNY3bg+8h6b4MsPNbtGhgf0dTs33bR+vJsv9OHmWTx9NfK/JdOVCPl0h5y581mH1jOpS 4jUxUMkI7/2MSyNmIkoNWjFUHxvo4BeyIRWdMImXaHbfv42SUfuS/qmFySefPhif+CUd okRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702409596; x=1703014396; 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=gdagdi7iMIzKnwsj7w7AjThQJGs4qjfnY9NtezQreuc=; b=EG7d5buXx9J2OUeXnFCxVd8qHz7MYNGIdypGYi8yJ+s9vzpKR6bdYveo1oMzGkeJEH NxrmT+uU3tpAuKfeeluFRaaSIE+07GLGMhuny5qe0odjTjpvbKsRK7H4o1sw5tnD3qMy L9NxXxguP098m9sN1r6XPae7lQ5O4An4L5M96aosstiEyqZiLdhKrd09Cyw08jfjo0mL ybtMTrK7lElXSN5Bt4QrMWaWIz7vDFpTvmHajpd6BWjHtAsf/8QX2yjWPINaLH/dYI66 eZaJKkCpvx2wB60a2SDFCk8F4M7qcwoSHpCB4xtb+hR12lJp4Z+eorjrJiyujxGNOCp+ 9ipw== X-Gm-Message-State: AOJu0Ywn6jL+Rf6ojZJtdB86iyE2GJwXr+z1JOfwA3sOToM73tpSj5nM xlaE3WDemQDICL4nAC5KgV2sLqsqICsmkzqgpko= X-Google-Smtp-Source: AGHT+IFIHyWJefFxSAuOowYr+V9YSzna+Zgp6h9UHKdwf37LjyCsxemFWZH4lQK7DQgqKbYRXHvaWA== X-Received: by 2002:a05:600c:30d2:b0:40c:4378:f117 with SMTP id h18-20020a05600c30d200b0040c4378f117mr2649753wmn.76.1702409596021; Tue, 12 Dec 2023 11:33:16 -0800 (PST) Received: from troughton.lym.embecosm-corp.com ([212.69.42.53]) by smtp.gmail.com with ESMTPSA id fm14-20020a05600c0c0e00b00407b93d8085sm19934150wmb.27.2023.12.12.11.33.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 11:33:15 -0800 (PST) From: Mary Bennett To: gcc-patches@gcc.gnu.org Cc: mary.bennett@embecosm.com Subject: [PATCH v4 2/3] RISC-V: Update XCValu constraints to match other vendors Date: Tue, 12 Dec 2023 19:32:52 +0000 Message-Id: <20231212193253.220195-3-mary.bennett@embecosm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212193253.220195-1-mary.bennett@embecosm.com> References: <20231128131615.3986922-1-mary.bennett@embecosm.com> <20231212193253.220195-1-mary.bennett@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org gcc/ChangeLog: * config/riscv/constraints.md: CVP2 -> CV_alu_pow2. * config/riscv/corev.md: Likewise. --- gcc/config/riscv/constraints.md | 15 ++++++++------- gcc/config/riscv/corev.md | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/gcc/config/riscv/constraints.md b/gcc/config/riscv/constraints.md index 68be4515c04..2711efe68c5 100644 --- a/gcc/config/riscv/constraints.md +++ b/gcc/config/riscv/constraints.md @@ -151,13 +151,6 @@ (define_register_constraint "zmvr" "(TARGET_ZFA || TARGET_XTHEADFMV) ? GR_REGS : NO_REGS" "An integer register for ZFA or XTheadFmv.") -;; CORE-V Constraints -(define_constraint "CVP2" - "Checking for CORE-V ALU clip if ival plus 1 is a power of 2" - (and (match_code "const_int") - (and (match_test "IN_RANGE (ival, 0, 1073741823)") - (match_test "exact_log2 (ival + 1) != -1")))) - ;; Vector constraints. (define_register_constraint "vr" "TARGET_VECTOR ? V_REGS : NO_REGS" @@ -246,3 +239,11 @@ A MEM with a valid address for th.[l|s]*ur* instructions." (and (match_code "mem") (match_test "th_memidx_legitimate_index_p (op, true)"))) + +;; CORE-V Constraints +(define_constraint "CV_alu_pow2" + "@internal + Checking for CORE-V ALU clip if ival plus 1 is a power of 2" + (and (match_code "const_int") + (and (match_test "IN_RANGE (ival, 0, 1073741823)") + (match_test "exact_log2 (ival + 1) != -1")))) diff --git a/gcc/config/riscv/corev.md b/gcc/config/riscv/corev.md index c7a2ba07bcc..92bf0b5d6a6 100644 --- a/gcc/config/riscv/corev.md +++ b/gcc/config/riscv/corev.md @@ -516,7 +516,7 @@ (define_insn "riscv_cv_alu_clip" [(set (match_operand:SI 0 "register_operand" "=r,r") (unspec:SI [(match_operand:SI 1 "register_operand" "r,r") - (match_operand:SI 2 "immediate_register_operand" "CVP2,r")] + (match_operand:SI 2 "immediate_register_operand" "CV_alu_pow2,r")] UNSPEC_CV_ALU_CLIP))] "TARGET_XCVALU && !TARGET_64BIT" @@ -529,7 +529,7 @@ (define_insn "riscv_cv_alu_clipu" [(set (match_operand:SI 0 "register_operand" "=r,r") (unspec:SI [(match_operand:SI 1 "register_operand" "r,r") - (match_operand:SI 2 "immediate_register_operand" "CVP2,r")] + (match_operand:SI 2 "immediate_register_operand" "CV_alu_pow2,r")] UNSPEC_CV_ALU_CLIPU))] "TARGET_XCVALU && !TARGET_64BIT" From patchwork Tue Dec 12 19:32:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mary Bennett X-Patchwork-Id: 82003 X-Patchwork-Delegate: kito.cheng@gmail.com Return-Path: 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 6D6183861883 for ; Tue, 12 Dec 2023 19:34:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 7369738582A0 for ; Tue, 12 Dec 2023 19:33:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7369738582A0 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 7369738582A0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::335 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702409600; cv=none; b=NRWGeMFXVEZDlcRFKjPRTzCbSk8r0CWos8o5ANclGHf501xr5k54pri0inFVwJf8v5FRcJOuWeMblbXd9+uX3EBkR8tQY6dAq+lHF2sYzFDi2E7lPri1hi/YZDfN1vDlfxym2FAJcDHkhbtUtGQpmdUTv/NCdaEZt9O+NMMN+EA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702409600; c=relaxed/simple; bh=KsXejU2TGqeui4aW37+pQcS76H07Zd3rwi0eB0pbNZA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=fs4+KScaqKg6vmQegChRksG6ztdI78Fp4QSACMwh0lycyAbbr9e9cX3iPGTAI/HJ6wKbsDijRMOjFjjzO+7vGsC3wmUl3enOLUxK7Od21VRVepdmA2efVf2V+VKfyXL0+PNMZJNwOKMa80dvcLdxbX0yCZl7Fga9+X0h2WzYwgc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40c32df9174so52590535e9.3 for ; Tue, 12 Dec 2023 11:33:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1702409597; x=1703014397; 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=GhLXO9j9UCVuYku0IL63kCaJF4GhLNBIgoxAfAY1AoE=; b=ZIC2HZrZUfB4YwYT11eLjChXNbFJHkjL39axautmY8RJwQJbEavrMWDQcuwhghDd3v AkUtNRnDx1EljEFsEEX9zLy9b7ZaZQenQYrycipkvI1HizNHymFUcwmrjzy2sX90dqeg S8rIKutvv271UzoiI4J/PP393qa3RFBhGWPocNnnUy1fSEVFxu5CiUwJw3VQ2mYpUme8 ANZyb1Qv7A6iwbHwtj5bvvZQI1if5oLz/c4McIyRuWBH2ay5XcJergkO8QFi9YFNJnQ7 s4P7lFfNOuhK/nUr557sB3GgcISHgB7TruTqgA3hK/9fLtHrgb6WTQTiiFE9QOFZd7sj LSHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702409597; x=1703014397; 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=GhLXO9j9UCVuYku0IL63kCaJF4GhLNBIgoxAfAY1AoE=; b=Kr8byvAKGXZHHrmqWlGNN39dWmufc0vmlk+odyb26uipJwA7d3sluAFyKWYLp3LlS3 dj3Lz3Ym6lzGhPiqC3tPEx0z0bdyyFdzWa31bhdbl0tOZsW6nfNpp7qHHHvw14YQnLqt /cl58gmH+LHbO+9lI1FGo60JLPRni7aF67FmfGfbl2BmW+fl7SwTYhbMfMgX2I9QSIih OdjOVGw579qpENU2utmyZLRux3NCSB1fyIco62qhFuVxIkw9nI3SDuwuQ9/kHqTd7Xf9 9MFNgv9Au46H8C7uH81b2x7yJAybnW36yhrxbDQLxL7L0xw1wBJbnR2u3cFMV3AELTZZ 7vSA== X-Gm-Message-State: AOJu0YxY4uCLBwa3Anvj3Vp4oaLAQ1tk9bhQHQn1M59WLivMYF1Y98s1 i8V4u9X7xxmpvQVSG+YppZY9rVbxiGhsvGyGmT0= X-Google-Smtp-Source: AGHT+IFMK14v8WQRyEmkRqjLFCI+Rl0DkRsZ7dZ4wdBIKYGwccciosD0RK13XDl/4zmp7zfe8XjTGg== X-Received: by 2002:a7b:cb95:0:b0:40c:33ab:1b37 with SMTP id m21-20020a7bcb95000000b0040c33ab1b37mr2693363wmi.152.1702409596755; Tue, 12 Dec 2023 11:33:16 -0800 (PST) Received: from troughton.lym.embecosm-corp.com ([212.69.42.53]) by smtp.gmail.com with ESMTPSA id fm14-20020a05600c0c0e00b00407b93d8085sm19934150wmb.27.2023.12.12.11.33.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 11:33:16 -0800 (PST) From: Mary Bennett To: gcc-patches@gcc.gnu.org Cc: mary.bennett@embecosm.com Subject: [PATCH v4 3/3] RISC-V: Add support for XCVbi extension in CV32E40P Date: Tue, 12 Dec 2023 19:32:53 +0000 Message-Id: <20231212193253.220195-4-mary.bennett@embecosm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212193253.220195-1-mary.bennett@embecosm.com> References: <20231128131615.3986922-1-mary.bennett@embecosm.com> <20231212193253.220195-1-mary.bennett@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org 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 | 32 +++++++++++++ gcc/config/riscv/predicates.md | 4 ++ gcc/config/riscv/riscv.md | 2 +- 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, 193 insertions(+), 1 deletion(-) 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..92e30a8ae04 100644 --- a/gcc/config/riscv/corev.md +++ b/gcc/config/riscv/corev.md @@ -706,3 +706,35 @@ [(set_attr "type" "load") (set_attr "mode" "SI")]) + +;; XCVBI Instructions +(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")]) + +(define_insn "*branch" + [(set (pc) + (if_then_else + (match_operator 1 "ordered_comparison_operator" + [(match_operand:X 2 "register_operand" "r") + (match_operand:X 3 "reg_or_0_operand" "rJ")]) + (label_ref (match_operand 0 "" "")) + (pc)))] + "TARGET_XCVBI" +{ + if (get_attr_length (insn) == 12) + return "b%N1\t%2,%z3,1f; jump\t%l0,ra; 1:"; + + return "b%C1\t%2,%z3,%l0"; +} + [(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..884dcb041e6 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -2645,7 +2645,7 @@ (match_operand:X 3 "reg_or_0_operand" "rJ")]) (label_ref (match_operand 0 "" "")) (pc)))] - "" + "!TARGET_XCVBI" { 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)