From patchwork Thu Aug 17 03:08:29 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: 135842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp426370vqi; Wed, 16 Aug 2023 20:09:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJvrqFzR41A+vZdnwjkRU4dfuyBt7PdMKfk6/gqk2agkDeK8f29pJcivKon/cJo41VWFSZ X-Received: by 2002:a17:906:5354:b0:99b:d977:c00c with SMTP id j20-20020a170906535400b0099bd977c00cmr3074485ejo.45.1692241768888; Wed, 16 Aug 2023 20:09:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692241768; cv=none; d=google.com; s=arc-20160816; b=CHulTZdTOVqyC8XRAqM9isnkC15sxNVeT6kMp/m8OPvGs+ZYvuhqnufPleJm4Meidp bV6zgEOzFDCW8BC4eq2zIc9C5WJ7Fe8PcqVH3DV4zDwkcHGcf1DoQMCX7TPKnsXKi/WL molEAWD5APM5wQkGNKa0SjQZqylfPQ97BEoAxPyQ2muWnMCMePKSsW9csu0Fd6cMjgK2 a37oIITdP0fNQopSzdlObzGKF6s36TkQRtJuCA38b4vNZMu2pwWNhqBccTHPOxX49Ap+ /Q+skAb+JUxFvQHnyyvgnU8QHfihR6ovzNm4rvWHguIWmmNvSNQ6vE0EUXL3bhxAzlxe YiYw== 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=ysoRIsPzAHnGVvIP1f5esapU5PFFAspw8uFz4z5sV3M=; fh=9EZcvfVI324lLsRm78AR5trG4A9hqVpSpoTtyXFX1N4=; b=BHVUntP7kuEAxduGE0qTr/JXaMjcvddgdx+rm90uIOuBimqO2K/ybzSdPtTpqZVBk0 AWN9idqvwE7rGyXXtE2YToXckMBdhl5pdDRNiZYOWRfRDt/BTI+drfPiEwbvTd0HSvSf axFvLV01K0g26VEYih5EjI4PGVAUlIpyXNzeVVOC3x1RvuDO7zElwVrRuHDUSU2U492j YPffylfaVGYMHYSG14kw0Z/Vl8RjC6jKG6iChHExB8PLEsQ0NauuVD4Okcxd/8jFFs/H rMgfC+ElkFnw76k16lqpkDc3pAlbEXWKurMpWKVn/pB8CgbLN4Iah/8HQbdF8Bwkw6Q2 syPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=khhTrlaf; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j24-20020a17090643d800b0099c49a11e78si11666235ejn.975.2023.08.16.20.09.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 20:09:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=khhTrlaf; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 8EB0B3857027 for ; Thu, 17 Aug 2023 03:09:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EB0B3857027 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692241767; bh=ysoRIsPzAHnGVvIP1f5esapU5PFFAspw8uFz4z5sV3M=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=khhTrlafteIkKtwkR130++pwhQPvqSITmKpwj7HbMEQEfkaO0JTy6DbR30P4VdP55 WU+s5aDNCSqb0bp+OtzVf6Nt1xJRg9+1tGZADfW34vtTTwNXDDx08Z+VXyGmFD0Ouw kRvU0dVjfhAhEWEp7h4j1IFIaS+fuSGjQ5GcFUjE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by sourceware.org (Postfix) with ESMTPS id 9D4FF3858C2A for ; Thu, 17 Aug 2023 03:08:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D4FF3858C2A X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="362850818" X-IronPort-AV: E=Sophos;i="6.01,179,1684825200"; d="scan'208";a="362850818" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2023 20:08:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10803"; a="799859525" X-IronPort-AV: E=Sophos;i="6.01,179,1684825200"; d="scan'208";a="799859525" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by fmsmga008.fm.intel.com with ESMTP; 16 Aug 2023 20:08:35 -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 785B210056F8; Thu, 17 Aug 2023 11:08:30 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, pan2.li@intel.com, yanzhang.wang@intel.com, kito.cheng@gmail.com Subject: [PATCH v1] RISC-V: Support RVV VFREDUSUM.VS rounding mode intrinsic API Date: Thu, 17 Aug 2023 11:08:29 +0800 Message-Id: <20230817030829.3352171-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 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: 1774444105069868948 X-GMAIL-MSGID: 1774444105069868948 From: Pan Li This patch would like to support the rounding mode API for the VFREDUSUM.VS as the below samples. * __riscv_vfredusum_vs_f32m1_f32m1_rm * __riscv_vfredusum_vs_f32m1_f32m1_rm_m Signed-off-by: Pan Li gcc/ChangeLog: * config/riscv/riscv-vector-builtins-bases.cc (class freducop): Add frm_op_type template arg. (vfredusum_frm_obj): New declaration. (BASE): Ditto. * config/riscv/riscv-vector-builtins-bases.h: Ditto. * config/riscv/riscv-vector-builtins-functions.def (vfredusum_frm): New intrinsic function def. * config/riscv/riscv-vector-builtins-shapes.cc (struct reduc_alu_frm_def): New class for frm shape. (SHAPE): New declaration. * config/riscv/riscv-vector-builtins-shapes.h: Ditto. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/float-point-redusum.c: New test. Signed-off-by: Pan Li > --- .../riscv/riscv-vector-builtins-bases.cc | 9 ++++- .../riscv/riscv-vector-builtins-bases.h | 1 + .../riscv/riscv-vector-builtins-functions.def | 2 + .../riscv/riscv-vector-builtins-shapes.cc | 39 +++++++++++++++++++ .../riscv/riscv-vector-builtins-shapes.h | 1 + .../riscv/rvv/base/float-point-redusum.c | 33 ++++++++++++++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-redusum.c diff --git a/gcc/config/riscv/riscv-vector-builtins-bases.cc b/gcc/config/riscv/riscv-vector-builtins-bases.cc index ad04647f9ba..65f1d9c8ff7 100644 --- a/gcc/config/riscv/riscv-vector-builtins-bases.cc +++ b/gcc/config/riscv/riscv-vector-builtins-bases.cc @@ -1847,10 +1847,15 @@ public: }; /* Implements floating-point reduction instructions. */ -template +template class freducop : public function_base { public: + bool has_rounding_mode_operand_p () const override + { + return FRM_OP == HAS_FRM; + } + bool apply_mask_policy_p () const override { return false; } rtx expand (function_expander &e) const override @@ -2532,6 +2537,7 @@ static CONSTEXPR const reducop vredxor_obj; static CONSTEXPR const widen_reducop vwredsum_obj; static CONSTEXPR const widen_reducop vwredsumu_obj; static CONSTEXPR const freducop vfredusum_obj; +static CONSTEXPR const freducop vfredusum_frm_obj; static CONSTEXPR const freducop vfredosum_obj; static CONSTEXPR const reducop vfredmax_obj; static CONSTEXPR const reducop vfredmin_obj; @@ -2789,6 +2795,7 @@ BASE (vredxor) BASE (vwredsum) BASE (vwredsumu) BASE (vfredusum) +BASE (vfredusum_frm) BASE (vfredosum) BASE (vfredmax) BASE (vfredmin) diff --git a/gcc/config/riscv/riscv-vector-builtins-bases.h b/gcc/config/riscv/riscv-vector-builtins-bases.h index c8c649c4bb0..fd1a84f3e68 100644 --- a/gcc/config/riscv/riscv-vector-builtins-bases.h +++ b/gcc/config/riscv/riscv-vector-builtins-bases.h @@ -239,6 +239,7 @@ extern const function_base *const vredxor; extern const function_base *const vwredsum; extern const function_base *const vwredsumu; extern const function_base *const vfredusum; +extern const function_base *const vfredusum_frm; extern const function_base *const vfredosum; extern const function_base *const vfredmax; extern const function_base *const vfredmin; diff --git a/gcc/config/riscv/riscv-vector-builtins-functions.def b/gcc/config/riscv/riscv-vector-builtins-functions.def index cfbc125dcd8..90a83c02d52 100644 --- a/gcc/config/riscv/riscv-vector-builtins-functions.def +++ b/gcc/config/riscv/riscv-vector-builtins-functions.def @@ -500,6 +500,8 @@ DEF_RVV_FUNCTION (vfredosum, reduc_alu, no_mu_preds, f_vs_ops) DEF_RVV_FUNCTION (vfredmax, reduc_alu, no_mu_preds, f_vs_ops) DEF_RVV_FUNCTION (vfredmin, reduc_alu, no_mu_preds, f_vs_ops) +DEF_RVV_FUNCTION (vfredusum_frm, reduc_alu_frm, no_mu_preds, f_vs_ops) + // 14.4. Vector Widening Floating-Point Reduction Instructions DEF_RVV_FUNCTION (vfwredosum, reduc_alu, no_mu_preds, wf_vs_ops) DEF_RVV_FUNCTION (vfwredusum, reduc_alu, no_mu_preds, wf_vs_ops) diff --git a/gcc/config/riscv/riscv-vector-builtins-shapes.cc b/gcc/config/riscv/riscv-vector-builtins-shapes.cc index 80329113af3..f8fdec863e6 100644 --- a/gcc/config/riscv/riscv-vector-builtins-shapes.cc +++ b/gcc/config/riscv/riscv-vector-builtins-shapes.cc @@ -371,6 +371,44 @@ struct narrow_alu_frm_def : public build_frm_base } }; +/* reduc_alu_frm_def class. */ +struct reduc_alu_frm_def : public build_frm_base +{ + char *get_name (function_builder &b, const function_instance &instance, + bool overloaded_p) const override + { + char base_name[BASE_NAME_MAX_LEN] = {}; + + normalize_base_name (base_name, instance.base_name, sizeof (base_name)); + + b.append_base_name (base_name); + + /* vop_ --> vop__. */ + if (!overloaded_p) + { + b.append_name (operand_suffixes[instance.op_info->op]); + b.append_name (type_suffixes[instance.type.index].vector); + vector_type_index ret_type_idx + = instance.op_info->ret.get_function_type_index (instance.type.index); + b.append_name (type_suffixes[ret_type_idx].vector); + } + + /* According to rvv-intrinsic-doc, it does not add "_rm" suffix + for vop_rm C++ overloaded API. */ + if (!overloaded_p) + b.append_name ("_rm"); + + /* According to rvv-intrinsic-doc, it does not add "_m" suffix + for vop_m C++ overloaded API. */ + if (overloaded_p && instance.pred == PRED_TYPE_m) + return b.finish_name (); + + b.append_name (predication_suffixes[instance.pred]); + + return b.finish_name (); + } +}; + /* widen_alu_def class. Handle vwadd/vwsub. Unlike vadd.vx/vadd.vv/vwmul.vv/vwmul.vx, vwadd.vv/vwadd.vx/vwadd.wv/vwadd.wx has 'OP' suffix in overloaded API. */ @@ -898,6 +936,7 @@ SHAPE(narrow_alu_frm, narrow_alu_frm) SHAPE(move, move) SHAPE(mask_alu, mask_alu) SHAPE(reduc_alu, reduc_alu) +SHAPE(reduc_alu_frm, reduc_alu_frm) SHAPE(scalar_move, scalar_move) SHAPE(vundefined, vundefined) SHAPE(misc, misc) diff --git a/gcc/config/riscv/riscv-vector-builtins-shapes.h b/gcc/config/riscv/riscv-vector-builtins-shapes.h index b53ab451902..92eb8bc9d71 100644 --- a/gcc/config/riscv/riscv-vector-builtins-shapes.h +++ b/gcc/config/riscv/riscv-vector-builtins-shapes.h @@ -39,6 +39,7 @@ extern const function_shape *const narrow_alu_frm; extern const function_shape *const move; extern const function_shape *const mask_alu; extern const function_shape *const reduc_alu; +extern const function_shape *const reduc_alu_frm; extern const function_shape *const scalar_move; extern const function_shape *const vundefined; extern const function_shape *const misc; diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-redusum.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-redusum.c new file mode 100644 index 00000000000..36da6dd46f7 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-redusum.c @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +vfloat32m1_t +test_riscv_vfredusum_vs_f32m1_f32m1_rm (vfloat32m1_t op1, vfloat32m1_t op2, + size_t vl) { + return __riscv_vfredusum_vs_f32m1_f32m1_rm (op1, op2, 0, vl); +} + +vfloat32m1_t +test_vfredusum_vs_f32m1_f32m1_rm_m (vbool32_t mask, vfloat32m1_t op1, + vfloat32m1_t op2, size_t vl) { + return __riscv_vfredusum_vs_f32m1_f32m1_rm_m (mask, op1, op2, 1, vl); +} + +vfloat32m1_t +test_riscv_vfredusum_vs_f32m1_f32m1 (vfloat32m1_t op1, vfloat32m1_t op2, + size_t vl) { + return __riscv_vfredusum_vs_f32m1_f32m1 (op1, op2, vl); +} + +vfloat32m1_t +test_vfredusum_vs_f32m1_f32m1_m (vbool32_t mask, vfloat32m1_t op1, + vfloat32m1_t op2, size_t vl) { + return __riscv_vfredusum_vs_f32m1_f32m1_m (mask, op1, op2, vl); +} + +/* { dg-final { scan-assembler-times {vfredusum\.vs\s+v[0-9]+,\s*v[0-9]+} 4 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 2 } } */