From patchwork Fri Aug 4 02:58:48 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: 130933 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1542849vqx; Thu, 3 Aug 2023 19:59:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpgjhz1MHBE//2FYgDEAQoIwbaMGilKDLHudCxJi+Y5AOGaVTCZKHEhDwr1/swUY4pEmCi X-Received: by 2002:a17:906:7490:b0:99b:d580:546c with SMTP id e16-20020a170906749000b0099bd580546cmr469470ejl.23.1691117979151; Thu, 03 Aug 2023 19:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691117979; cv=none; d=google.com; s=arc-20160816; b=SjPpzWqzQwzjxk2Fgut4ruwLuzUf29Uz50CqCNyshIbju9uGxIRZR6JfPrU5/Lm3aH fS4tNAPg6xbtRpdraElgkjQgDkBydfMlKZVOw6O0pRjv22bkfwYtpleFDTetUT5/vrPL 3TUjwhUjsJ2rEEhIg0QEjvTwgQF/CbYJVjgVpCtNCeL43BOUMetsreywytiREPPmOfX5 7eCyND2W7PjAD8AbGqe0895DTfU798lN4ybIydIXGmxYfM1D2LksmYSRQjp0vGxtjzfO qYVjqVEclilZwRViNeTX4m8SDuc2lfNugkCJJiUBM+YjhkU0I9xjqhNvv6yhd6YQaKnV ageQ== 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=7PMi/HYV/5emntuq6QELbllEMueoVVLPwrR2NTjJ870=; fh=/JJEj+I5j40/Spkll6HT+Gte92Mjc5mpTnWowlKfaJ8=; b=FBxbVH/dIGiMV/+foHM4zUdxmbLhltgKJVn8h8ciuRKngvbZI0qy3ZVso6kJCwXVvc peD5cdAyRIQ8rwbE8sW7GHFclbyFAJLtFPwQI5yZX8CIe94/YJg3X2s+J5TwflKRol5q POXHURnkNVRIwPLeld3EqcNXFn4P57D5ROr2r3dTTk6D1LsoprBsIscdAQFRAle6CozL 3S5aDDjFhhA5Slh7dHKG6nPmc1KOwJ2W+z3S+iH0Do2PrZv6alywiJVyIk4T4oTaIstB 45L0QnnnwnW3p1GqkkvfYPuj0FocXu8d0D2bBQCN0oml2x7Z5gmBwQsDT3a2S/zASNU8 Oxcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="yQDsK/Lf"; 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 y23-20020a170906559700b009888665e53fsi180884ejp.190.2023.08.03.19.59.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 19:59:39 -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="yQDsK/Lf"; 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 11DE93857700 for ; Fri, 4 Aug 2023 02:59:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11DE93857700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691117978; bh=7PMi/HYV/5emntuq6QELbllEMueoVVLPwrR2NTjJ870=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=yQDsK/LfTApTGwhLRCt/fGuqtzHpYkGPJPlFtfIGXEOwc4VIkKSti7ytJ788IRHp+ Kx+JERRBhjT6xQuK1YpwuYVFDb5KtL6BUA+3Jbcp7UT3UUSo1eEZrPPb+HQtx4gMce 4tpW1BjSc0eS9Ir+qmm81zrnh/wLppN3k15HeiuI= 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.88]) by sourceware.org (Postfix) with ESMTPS id 37C1A3858291 for ; Fri, 4 Aug 2023 02:58:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37C1A3858291 X-IronPort-AV: E=McAfee;i="6600,9927,10791"; a="401005726" X-IronPort-AV: E=Sophos;i="6.01,253,1684825200"; d="scan'208";a="401005726" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2023 19:58:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10791"; a="843873436" X-IronPort-AV: E=Sophos;i="6.01,253,1684825200"; d="scan'208";a="843873436" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by fmsmga002.fm.intel.com with ESMTP; 03 Aug 2023 19:58:50 -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 5002A1007BA4; Fri, 4 Aug 2023 10:58:49 +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 VFMSAC rounding mode intrinsic API Date: Fri, 4 Aug 2023 10:58:48 +0800 Message-Id: <20230804025848.327107-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, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: 1773265726130488668 X-GMAIL-MSGID: 1773265726130488668 From: Pan Li This patch would like to support the rounding mode API for the VFMSAC for the below samples. * __riscv_vfmsac_vv_f32m1_rm * __riscv_vfmsac_vv_f32m1_rm_m * __riscv_vfmsac_vf_f32m1_rm * __riscv_vfmsac_vf_f32m1_rm_m Signed-off-by: Pan Li gcc/ChangeLog: * config/riscv/riscv-vector-builtins-bases.cc (class vfmsac_frm): New class for vfmsac frm. (vfmsac_frm_obj): New declaration. (BASE): Ditto. * config/riscv/riscv-vector-builtins-bases.h: Ditto. * config/riscv/riscv-vector-builtins-functions.def (vfmsac_frm): New function definition. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/float-point-single-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 + .../base/float-point-single-multiply-sub.c | 47 +++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-single-multiply-sub.c diff --git a/gcc/config/riscv/riscv-vector-builtins-bases.cc b/gcc/config/riscv/riscv-vector-builtins-bases.cc index 1d4a5a18bf9..e73051bbd89 100644 --- a/gcc/config/riscv/riscv-vector-builtins-bases.cc +++ b/gcc/config/riscv/riscv-vector-builtins-bases.cc @@ -401,6 +401,28 @@ public: } }; +/* Implements below instructions for frm + - vfmsac +*/ +class vfmsac_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_scalar (MINUS, e.vector_mode ())); + if (e.op_info->op == OP_TYPE_vv) + return e.use_ternop_insn ( + true, code_for_pred_mul (MINUS, e.vector_mode ())); + gcc_unreachable (); + } +}; + /* Implements vrsub. */ class vrsub : public function_base { @@ -2168,6 +2190,7 @@ static CONSTEXPR const vfnmsub vfnmsub_obj; static CONSTEXPR const vfnmacc vfnmacc_obj; static CONSTEXPR const vfnmacc_frm vfnmacc_frm_obj; static CONSTEXPR const vfmsac vfmsac_obj; +static CONSTEXPR const vfmsac_frm vfmsac_frm_obj; static CONSTEXPR const vfnmadd vfnmadd_obj; static CONSTEXPR const vfmsub vfmsub_obj; static CONSTEXPR const vfwmacc vfwmacc_obj; @@ -2405,6 +2428,7 @@ BASE (vfnmsub) BASE (vfnmacc) BASE (vfnmacc_frm) BASE (vfmsac) +BASE (vfmsac_frm) BASE (vfnmadd) BASE (vfmsub) BASE (vfwmacc) diff --git a/gcc/config/riscv/riscv-vector-builtins-bases.h b/gcc/config/riscv/riscv-vector-builtins-bases.h index 247074d0868..ca8a6dc1cc3 100644 --- a/gcc/config/riscv/riscv-vector-builtins-bases.h +++ b/gcc/config/riscv/riscv-vector-builtins-bases.h @@ -167,6 +167,7 @@ extern const function_base *const vfnmsub; extern const function_base *const vfnmacc; extern const function_base *const vfnmacc_frm; extern const function_base *const vfmsac; +extern const function_base *const vfmsac_frm; extern const function_base *const vfnmadd; extern const function_base *const vfmsub; extern const function_base *const vfwmacc; diff --git a/gcc/config/riscv/riscv-vector-builtins-functions.def b/gcc/config/riscv/riscv-vector-builtins-functions.def index 223e8346cd8..8bae7e616ba 100644 --- a/gcc/config/riscv/riscv-vector-builtins-functions.def +++ b/gcc/config/riscv/riscv-vector-builtins-functions.def @@ -352,6 +352,8 @@ DEF_RVV_FUNCTION (vfmacc_frm, alu_frm, full_preds, f_vvvv_ops) DEF_RVV_FUNCTION (vfmacc_frm, alu_frm, full_preds, f_vvfv_ops) 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) // 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-multiply-sub.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-single-multiply-sub.c new file mode 100644 index 00000000000..8fee552dd30 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-single-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_vfmsac_vv_f32m1_rm (vfloat32m1_t vd, vfloat32m1_t op1, + vfloat32m1_t op2, size_t vl) { + return __riscv_vfmsac_vv_f32m1_rm (vd, op1, op2, 0, vl); +} + +vfloat32m1_t +test_vfmsac_vv_f32m1_rm_m (vbool32_t mask, vfloat32m1_t vd, vfloat32m1_t op1, + vfloat32m1_t op2, size_t vl) { + return __riscv_vfmsac_vv_f32m1_rm_m (mask, vd, op1, op2, 1, vl); +} + +vfloat32m1_t +test_vfmsac_vf_f32m1_rm (vfloat32m1_t vd, float32_t op1, vfloat32m1_t op2, + size_t vl) { + return __riscv_vfmsac_vf_f32m1_rm (vd, op1, op2, 2, vl); +} + +vfloat32m1_t +test_vfmsac_vf_f32m1_rm_m (vfloat32m1_t vd, vbool32_t mask, float32_t op1, + vfloat32m1_t op2, size_t vl) { + return __riscv_vfmsac_vf_f32m1_rm_m (mask, vd, op1, op2, 3, vl); +} + +vfloat32m1_t +test_riscv_vfmsac_vv_f32m1 (vfloat32m1_t vd, vfloat32m1_t op1, + vfloat32m1_t op2, size_t vl) { + return __riscv_vfmsac_vv_f32m1 (vd, op1, op2, vl); +} + +vfloat32m1_t +test_vfmsac_vv_f32m1_m (vbool32_t mask, vfloat32m1_t vd, vfloat32m1_t op1, + vfloat32m1_t op2, size_t vl) { + return __riscv_vfmsac_vv_f32m1_m (mask, vd, op1, op2, vl); +} + +/* { dg-final { scan-assembler-times {vfmsac\.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 } } */