From patchwork Fri Aug 4 03:28:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 130942 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:419:b0:139:fa0d:b2d with SMTP id 25csp770361rwd; Thu, 3 Aug 2023 20:29:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3NK76nCqwdcyQc2byeOJt80CiSMz6NMdVGxQwX8HBttPYvBo8tZrbe0NlwLEcFqWjiQtd X-Received: by 2002:a05:6402:8c6:b0:523:10c0:9dc with SMTP id d6-20020a05640208c600b0052310c009dcmr501153edz.8.1691119759460; Thu, 03 Aug 2023 20:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691119759; cv=none; d=google.com; s=arc-20160816; b=mdanrmH+KYQ9m8QENyIqLP2Sp8RdkHpueiprw6iMlTfLVQPk4XViz237x01fBNAOkQ CnrvzZ0IttHxMhLruHdoVSxtp2l2CLo4RVUrO6wmmzPjXZTBVIqY26O17pPZJM5GVee5 6hRkUexULTWqwRxIo7X6sr6qzFELRluLWT35v56C6Ypb9Zer4mhrLhKumuR14dYcuUci gp0l7AvYEwDsjPb2j5kybrBMv6uXiR+XKjWV/uRD9kO0PbsrH5xz89pr5UF2ukEdjWV5 Er/abhZjTP4k7ctwaHpG8KH85PghzbpvPb8EMowzvNtHfTWLQZtN9Ct2dJYgS5BYYF7r TEFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=xL0+593NqvO95PY3ao6wDI40svGiJaDG+hmtEzXnnOc=; fh=/JJEj+I5j40/Spkll6HT+Gte92Mjc5mpTnWowlKfaJ8=; b=T+tTeLOpriPZFdnYYBgOqScAQxrrEdmPaVzgWBN8n4EbPCc2LLuEZARmeADe2q0aNe PndituePnyOHmTHux/mmeerhHoIyOkrVQjU8Kv/ChiunVtisXE7gQhiR72K7fHKZdzCF HcxCcEZ7N5WE/7mg554OWGedJw/58kqiBAD/GYl0YbqhpPhoxevcIVBxPoCs/stYirfz 637QEbqn++7Z7sxf4KcNAmUaWdxbBnQb5bh+95jXRvq1KJJTTiO9P+QAbCWIqTt+n3QW ZfRHpFnZopByFiO4Sd9qAtBznY+QMgDGX8Lh93F2TJY/Fh6tFhu+qSu09dNMW4vOJgC3 grrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MmzaRG4i; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w14-20020a056402070e00b00523095eedfbsi934529edx.681.2023.08.03.20.29.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 20:29:19 -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=@gcc.gnu.org header.s=default header.b=MmzaRG4i; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6452B3857C5A for ; Fri, 4 Aug 2023 03:29:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6452B3857C5A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691119758; bh=xL0+593NqvO95PY3ao6wDI40svGiJaDG+hmtEzXnnOc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=MmzaRG4iXb+zhD0tJjEgZGqkkPX+mtnJMEW685260+Sln7qlm2+Vhgv6nDAqzLDbB 33iaapqxfHx7cxnnZ/+p2hXmpL86x6lLsPXKQCoDiID0RJpc4+IYi84RUDUwXWMd6u RNgBNpu5M32Ocwei5vNsXcqD0M1h8RYRYElfWqlI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by sourceware.org (Postfix) with ESMTPS id 35A423858C27 for ; Fri, 4 Aug 2023 03:28:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35A423858C27 X-IronPort-AV: E=McAfee;i="6600,9927,10791"; a="456428540" X-IronPort-AV: E=Sophos;i="6.01,254,1684825200"; d="scan'208";a="456428540" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2023 20:28:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10791"; a="764930817" X-IronPort-AV: E=Sophos;i="6.01,254,1684825200"; d="scan'208";a="764930817" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by orsmga001.jf.intel.com with ESMTP; 03 Aug 2023 20:28:30 -0700 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail02.sh.intel.com (Postfix) with ESMTP id 3A8DC10083A2; Fri, 4 Aug 2023 11:28:29 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, kito.cheng@sifive.com, pan2.li@intel.com, yanzhang.wang@intel.com Subject: [PATCH v1] RISC-V: Support RVV VFNMSAC rounding mode intrinsic API Date: Fri, 4 Aug 2023 11:28:28 +0800 Message-Id: <20230804032828.596526-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, 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: , X-Patchwork-Original-From: Pan Li via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: pan2.li@intel.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773267593231412623 X-GMAIL-MSGID: 1773267593231412623 From: Pan Li This patch would like to support the rounding mode API for the VFNMSAC for the below samples. * __riscv_vfnmsac_vv_f32m1_rm * __riscv_vfnmsac_vv_f32m1_rm_m * __riscv_vfnmsac_vf_f32m1_rm * __riscv_vfnmsac_vf_f32m1_rm_m Signed-off-by: Pan Li gcc/ChangeLog: * config/riscv/riscv-vector-builtins-bases.cc (class vfnmsac_frm): New class for vfnmsac frm. (vfnmsac_frm_obj): New declaration. (BASE): Ditto. * config/riscv/riscv-vector-builtins-bases.h: Ditto. * config/riscv/riscv-vector-builtins-functions.def (vfnmsac_frm): New function definition. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/float-point-single-negate-multiply-sub.c: New test. Signed-off-by: Pan Li --- .../riscv/riscv-vector-builtins-bases.cc | 24 ++++++++++ .../riscv/riscv-vector-builtins-bases.h | 1 + .../riscv/riscv-vector-builtins-functions.def | 2 + .../float-point-single-negate-multiply-sub.c | 47 +++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-single-negate-multiply-sub.c diff --git a/gcc/config/riscv/riscv-vector-builtins-bases.cc b/gcc/config/riscv/riscv-vector-builtins-bases.cc index e73051bbd89..9c6ca8d1ddc 100644 --- a/gcc/config/riscv/riscv-vector-builtins-bases.cc +++ b/gcc/config/riscv/riscv-vector-builtins-bases.cc @@ -423,6 +423,28 @@ public: } }; +/* Implements below instructions for frm + - vfnmsac +*/ +class vfnmsac_frm : public function_base +{ +public: + bool has_rounding_mode_operand_p () const override { return true; } + + bool has_merge_operand_p () const override { return false; } + + rtx expand (function_expander &e) const override + { + if (e.op_info->op == OP_TYPE_vf) + return e.use_ternop_insn ( + true, code_for_pred_mul_neg_scalar (PLUS, e.vector_mode ())); + if (e.op_info->op == OP_TYPE_vv) + return e.use_ternop_insn ( + true, code_for_pred_mul_neg (PLUS, e.vector_mode ())); + gcc_unreachable (); + } +}; + /* Implements vrsub. */ class vrsub : public function_base { @@ -2185,6 +2207,7 @@ static CONSTEXPR const widen_binop_frm vfwmul_frm_obj; static CONSTEXPR const vfmacc vfmacc_obj; static CONSTEXPR const vfmacc_frm vfmacc_frm_obj; static CONSTEXPR const vfnmsac vfnmsac_obj; +static CONSTEXPR const vfnmsac_frm vfnmsac_frm_obj; static CONSTEXPR const vfmadd vfmadd_obj; static CONSTEXPR const vfnmsub vfnmsub_obj; static CONSTEXPR const vfnmacc vfnmacc_obj; @@ -2423,6 +2446,7 @@ BASE (vfwmul_frm) BASE (vfmacc) BASE (vfmacc_frm) BASE (vfnmsac) +BASE (vfnmsac_frm) BASE (vfmadd) BASE (vfnmsub) BASE (vfnmacc) diff --git a/gcc/config/riscv/riscv-vector-builtins-bases.h b/gcc/config/riscv/riscv-vector-builtins-bases.h index ca8a6dc1cc3..28eec2c3e99 100644 --- a/gcc/config/riscv/riscv-vector-builtins-bases.h +++ b/gcc/config/riscv/riscv-vector-builtins-bases.h @@ -162,6 +162,7 @@ extern const function_base *const vfwmul_frm; extern const function_base *const vfmacc; extern const function_base *const vfmacc_frm; extern const function_base *const vfnmsac; +extern const function_base *const vfnmsac_frm; extern const function_base *const vfmadd; extern const function_base *const vfnmsub; extern const function_base *const vfnmacc; diff --git a/gcc/config/riscv/riscv-vector-builtins-functions.def b/gcc/config/riscv/riscv-vector-builtins-functions.def index 8bae7e616ba..9c964ae6fcb 100644 --- a/gcc/config/riscv/riscv-vector-builtins-functions.def +++ b/gcc/config/riscv/riscv-vector-builtins-functions.def @@ -354,6 +354,8 @@ DEF_RVV_FUNCTION (vfnmacc_frm, alu_frm, full_preds, f_vvvv_ops) DEF_RVV_FUNCTION (vfnmacc_frm, alu_frm, full_preds, f_vvfv_ops) DEF_RVV_FUNCTION (vfmsac_frm, alu_frm, full_preds, f_vvvv_ops) DEF_RVV_FUNCTION (vfmsac_frm, alu_frm, full_preds, f_vvfv_ops) +DEF_RVV_FUNCTION (vfnmsac_frm, alu_frm, full_preds, f_vvvv_ops) +DEF_RVV_FUNCTION (vfnmsac_frm, alu_frm, full_preds, f_vvfv_ops) // 13.7. Vector Widening Floating-Point Fused Multiply-Add Instructions DEF_RVV_FUNCTION (vfwmacc, alu, full_preds, f_wwvv_ops) diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-single-negate-multiply-sub.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-single-negate-multiply-sub.c new file mode 100644 index 00000000000..c3089234272 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-single-negate-multiply-sub.c @@ -0,0 +1,47 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +typedef float float32_t; + +vfloat32m1_t +test_riscv_vfnmsac_vv_f32m1_rm (vfloat32m1_t vd, vfloat32m1_t op1, + vfloat32m1_t op2, size_t vl) { + return __riscv_vfnmsac_vv_f32m1_rm (vd, op1, op2, 0, vl); +} + +vfloat32m1_t +test_vfnmsac_vv_f32m1_rm_m (vbool32_t mask, vfloat32m1_t vd, vfloat32m1_t op1, + vfloat32m1_t op2, size_t vl) { + return __riscv_vfnmsac_vv_f32m1_rm_m (mask, vd, op1, op2, 1, vl); +} + +vfloat32m1_t +test_vfnmsac_vf_f32m1_rm (vfloat32m1_t vd, float32_t op1, vfloat32m1_t op2, + size_t vl) { + return __riscv_vfnmsac_vf_f32m1_rm (vd, op1, op2, 2, vl); +} + +vfloat32m1_t +test_vfnmsac_vf_f32m1_rm_m (vfloat32m1_t vd, vbool32_t mask, float32_t op1, + vfloat32m1_t op2, size_t vl) { + return __riscv_vfnmsac_vf_f32m1_rm_m (mask, vd, op1, op2, 3, vl); +} + +vfloat32m1_t +test_riscv_vfnmsac_vv_f32m1 (vfloat32m1_t vd, vfloat32m1_t op1, + vfloat32m1_t op2, size_t vl) { + return __riscv_vfnmsac_vv_f32m1 (vd, op1, op2, vl); +} + +vfloat32m1_t +test_vfnmsac_vv_f32m1_m (vbool32_t mask, vfloat32m1_t vd, vfloat32m1_t op1, + vfloat32m1_t op2, size_t vl) { + return __riscv_vfnmsac_vv_f32m1_m (mask, vd, op1, op2, vl); +} + +/* { dg-final { scan-assembler-times {vfnmsac\.v[vf]\s+v[0-9]+,\s*[fav]+[0-9]+,\s*v[0-9]+} 6 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 4 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 4 } } */ +/* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 4 } } */