From patchwork Fri Sep 15 13:23:02 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: 140433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1043596vqi; Fri, 15 Sep 2023 06:24:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaEp4nOuOS96DsrfVZAc1V8Kn9q5ltGHKe0qG43P8LiIIPC1eptgQHLa85Rp2cAjx1SLin X-Received: by 2002:a17:907:75c4:b0:9a5:d657:47ee with SMTP id jl4-20020a17090775c400b009a5d65747eemr1355601ejc.58.1694784248249; Fri, 15 Sep 2023 06:24:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694784248; cv=none; d=google.com; s=arc-20160816; b=szZpTGc7STflu4Mvm/B34I6+CSqK3UqNCZg0lhM98pgV/N1ZSTkRw6Q8nyXPzRniwq KhqqcZg83qO8WzEHxG0uMN1+ardB2/LKtgU6kWhvBZzXG/gmwXx94KdDTtA/5qy1zGl6 C89DJ0BbJk5HixL6fq45laN3VcqfFiJrsTVGT/JHnPMHQF/q34yTorzsWRB63SBmI/Wf GCvhSVE18WBAeJsdctlL+ktuBmPVBwyaNgHf7LKpKLv58rRU+lbi1uzJXSXpumcpafMN 0/D3PErwTNvCqfbzkXtBvOfHc5DSjmeBHjLc0AbAlos3xmpGUQsuzwl/FPz4E1ih79lC s8sw== 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=CjcOj1VMEj1jl/iG1k4jbEA13BDP3q4d0der9w962TU=; fh=yqBQmCEeFYB2Wjmf8l8QkV/dOy5iKwSEx/iU/FYQjxU=; b=xXvhdSCeONHhG2nD3T+VrT3WCyGSVK2FIGcrAXNUqWls9wZw2AguPFytsTiC6LWlSw Y368yA9Q4cjd5jUIqKgWACCIkWoGx2arOoVimIA/B9roNjGf2/UC7yg33vpA/n6LFKgX v1Z7tfG7TA+d3bZZg1gDCWDYEAFYFgfsixubG/Y6gdHU2Txi2/tWw3i+TiuSwboEJkMc rOKswLPTb0eeg8IknjKZ4XD0LCTjlfpKqjI6JRgi4kz+GaIJmt4OyvaqprSt8vK4HmfM pzokiCUbiAbd/GmXgd/ihmgnvl2CNscjgbQOUz4h4i4UVQG2qLhVGRUAvUFsHg93Xc69 SRwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vJLGrThS; 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 gv23-20020a170906f11700b00987acac4c40si3475887ejb.596.2023.09.15.06.24.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 06:24:08 -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=vJLGrThS; 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 EB594385841E for ; Fri, 15 Sep 2023 13:24:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB594385841E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694784247; bh=CjcOj1VMEj1jl/iG1k4jbEA13BDP3q4d0der9w962TU=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=vJLGrThSMmHscIehuCHxsQABLkd0x3jURCNWqm9DMmVSuTFIxyGsoSSsZu3HPY8Zm jliqeO040smdZcjMig6HH9Q3xH7QfhB50bsmo6KS5J1vsiEqCKwWVvGyo1v3RvmBKA 8QXiVv7/ePB8u/eAsToOWe7ELfsFhdMVBTtI+xiM= 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.120]) by sourceware.org (Postfix) with ESMTPS id A38D53858C52 for ; Fri, 15 Sep 2023 13:23:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A38D53858C52 X-IronPort-AV: E=McAfee;i="6600,9927,10834"; a="378160100" X-IronPort-AV: E=Sophos;i="6.02,149,1688454000"; d="scan'208";a="378160100" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2023 06:23:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10834"; a="774318311" X-IronPort-AV: E=Sophos;i="6.02,149,1688454000"; d="scan'208";a="774318311" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by orsmga008.jf.intel.com with ESMTP; 15 Sep 2023 06:23:13 -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 5B2161005669; Fri, 15 Sep 2023 21:23:12 +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 FP SGNJX autovec for VLS mode Date: Fri, 15 Sep 2023 21:23:02 +0800 Message-Id: <20230915132302.3468514-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, 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.30 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: 1777110087795304616 X-GMAIL-MSGID: 1777110087795304616 From: Pan Li This patch would like to allow the VLS mode autovec for the floating-point binary operation SGNJX. Give sample code as below: void test (float * restrict out, float * restrict in1, float * restrict in2) { for (int i = 0; i < 128; i++) out[i] = in1[i] * copysignf (1.0, in2[i]); } Before this patch: test: li a5,128 vsetvli zero,a5,e32,m1,ta,ma vle32.v v2,0(a1) lui a4,%hi(.LC0) flw fa5,%lo(.LC0)(a4) vfmv.v.f v1,fa5 vle32.v v3,0(a2) vfsgnj.vv v1,v1,v3 vfmul.vv v1,v1,v2 vse32.v v1,0(a0) ret After this patch: test: li a5,128 vsetvli zero,a5,e32,m1,ta,ma vle32.v v1,0(a1) vle32.v v2,0(a2) vfsgnjx.vv v1,v1,v2 vse32.v v1,0(a0) ret This SGNJX autovec acts on function call copysignf/copysignf in math.h too. And it depends on the option -ffast-math. gcc/ChangeLog: * config/riscv/autovec-vls.md (xorsign3): New pattern. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/vls/def.h: New macro. * gcc.target/riscv/rvv/autovec/vls/floating-point-sgnjx-1.c: New test. * gcc.target/riscv/rvv/autovec/vls/floating-point-sgnjx-2.c: New test. Signed-off-by: Pan Li Signed-off-by: Pan Li Signed-off-by: Pan Li > --- gcc/config/riscv/autovec-vls.md | 21 +++++++++ .../gcc.target/riscv/rvv/autovec/vls/def.h | 8 ++++ .../rvv/autovec/vls/floating-point-sgnjx-1.c | 43 +++++++++++++++++++ .../rvv/autovec/vls/floating-point-sgnjx-2.c | 31 +++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnjx-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnjx-2.c diff --git a/gcc/config/riscv/autovec-vls.md b/gcc/config/riscv/autovec-vls.md index 6f48f7d6232..d4ed2081537 100644 --- a/gcc/config/riscv/autovec-vls.md +++ b/gcc/config/riscv/autovec-vls.md @@ -289,6 +289,27 @@ (define_insn_and_split "copysign3" [(set_attr "type" "vector")] ) +;; ------------------------------------------------------------------------- +;; Includes: +;; - vfsgnjx.vv +;; - vfsgnjx.vf +;; ------------------------------------------------------------------------- +(define_insn_and_split "xorsign3" + [(set (match_operand:VLSF 0 "register_operand") + (unspec:VLSF + [(match_operand:VLSF 1 "register_operand") + (match_operand:VLSF 2 "register_operand")] UNSPEC_VXORSIGN))] + "TARGET_VECTOR && can_create_pseudo_p ()" + "#" + "&& 1" + [(const_int 0)] + { + riscv_vector::emit_vlmax_insn (code_for_pred (UNSPEC_VXORSIGN, mode), + riscv_vector::BINARY_OP, operands); + DONE; + } +) + ;; ------------------------------------------------------------------------------- ;; ---- [INT] Unary operations ;; ------------------------------------------------------------------------------- diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/def.h b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/def.h index 1edc1910920..81c4570836b 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/def.h +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/def.h @@ -258,3 +258,11 @@ typedef double v512df __attribute__ ((vector_size (4096))); for (int i = 0; i < NUM; ++i) \ a[i] = (b[i] > c[i]) OP (d[i] < e[i]); \ } + +#define DEF_SGNJX_VV(PREFIX, NUM, TYPE, CALL) \ + void __attribute__ ((noinline, noclone)) \ + PREFIX##_##TYPE##NUM (TYPE *restrict a, TYPE *restrict b, TYPE *restrict c) \ + { \ + for (int i = 0; i < NUM; ++i) \ + a[i] = b[i] * CALL (1.0, c[i]); \ + } diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnjx-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnjx-1.c new file mode 100644 index 00000000000..86c23ef0436 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnjx-1.c @@ -0,0 +1,43 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvfh_zvl4096b -mabi=lp64d -O3 -fno-schedule-insns -fno-schedule-insns2 --param=riscv-autovec-lmul=m8 -ffast-math" } */ + +#include "def.h" + +DEF_SGNJX_VV (sgnj, 1, _Float16, __builtin_copysignf16) +DEF_SGNJX_VV (sgnj, 2, _Float16, __builtin_copysignf16) +DEF_SGNJX_VV (sgnj, 4, _Float16, __builtin_copysignf16) +DEF_SGNJX_VV (sgnj, 8, _Float16, __builtin_copysignf16) +DEF_SGNJX_VV (sgnj, 16, _Float16, __builtin_copysignf16) +DEF_SGNJX_VV (sgnj, 32, _Float16, __builtin_copysignf16) +DEF_SGNJX_VV (sgnj, 64, _Float16, __builtin_copysignf16) +DEF_SGNJX_VV (sgnj, 128, _Float16, __builtin_copysignf16) +DEF_SGNJX_VV (sgnj, 256, _Float16, __builtin_copysignf16) +DEF_SGNJX_VV (sgnj, 512, _Float16, __builtin_copysignf16) +DEF_SGNJX_VV (sgnj, 1024, _Float16, __builtin_copysignf16) +DEF_SGNJX_VV (sgnj, 2048, _Float16, __builtin_copysignf16) + +DEF_SGNJX_VV (sgnj, 1, float, __builtin_copysignf) +DEF_SGNJX_VV (sgnj, 2, float, __builtin_copysignf) +DEF_SGNJX_VV (sgnj, 4, float, __builtin_copysignf) +DEF_SGNJX_VV (sgnj, 8, float, __builtin_copysignf) +DEF_SGNJX_VV (sgnj, 16, float, __builtin_copysignf) +DEF_SGNJX_VV (sgnj, 32, float, __builtin_copysignf) +DEF_SGNJX_VV (sgnj, 64, float, __builtin_copysignf) +DEF_SGNJX_VV (sgnj, 128, float, __builtin_copysignf) +DEF_SGNJX_VV (sgnj, 256, float, __builtin_copysignf) +DEF_SGNJX_VV (sgnj, 512, float, __builtin_copysignf) +DEF_SGNJX_VV (sgnj, 1024, float, __builtin_copysignf) + +DEF_SGNJX_VV (sgnj, 1, double, __builtin_copysign) +DEF_SGNJX_VV (sgnj, 2, double, __builtin_copysign) +DEF_SGNJX_VV (sgnj, 4, double, __builtin_copysign) +DEF_SGNJX_VV (sgnj, 8, double, __builtin_copysign) +DEF_SGNJX_VV (sgnj, 16, double, __builtin_copysign) +DEF_SGNJX_VV (sgnj, 32, double, __builtin_copysign) +DEF_SGNJX_VV (sgnj, 64, double, __builtin_copysign) +DEF_SGNJX_VV (sgnj, 128, double, __builtin_copysign) +DEF_SGNJX_VV (sgnj, 256, double, __builtin_copysign) +DEF_SGNJX_VV (sgnj, 512, double, __builtin_copysign) + +/* { dg-final { scan-assembler-times {vfsgnjx\.vv\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 30 } } */ +/* { dg-final { scan-assembler-not {csrr} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnjx-2.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnjx-2.c new file mode 100644 index 00000000000..7e017de6a25 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls/floating-point-sgnjx-2.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvfh_zvl4096b -mabi=lp64d -O3 -fno-schedule-insns -fno-schedule-insns2 --param=riscv-autovec-lmul=m8 -ffast-math" } */ + +#include "def.h" +#include + +DEF_SGNJX_VV (sgnj, 1, float, copysignf) +DEF_SGNJX_VV (sgnj, 2, float, copysignf) +DEF_SGNJX_VV (sgnj, 4, float, copysignf) +DEF_SGNJX_VV (sgnj, 8, float, copysignf) +DEF_SGNJX_VV (sgnj, 16, float, copysignf) +DEF_SGNJX_VV (sgnj, 32, float, copysignf) +DEF_SGNJX_VV (sgnj, 64, float, copysignf) +DEF_SGNJX_VV (sgnj, 128, float, copysignf) +DEF_SGNJX_VV (sgnj, 256, float, copysignf) +DEF_SGNJX_VV (sgnj, 512, float, copysignf) +DEF_SGNJX_VV (sgnj, 1024, float, copysignf) + +DEF_SGNJX_VV (sgnj, 1, double, copysign) +DEF_SGNJX_VV (sgnj, 2, double, copysign) +DEF_SGNJX_VV (sgnj, 4, double, copysign) +DEF_SGNJX_VV (sgnj, 8, double, copysign) +DEF_SGNJX_VV (sgnj, 16, double, copysign) +DEF_SGNJX_VV (sgnj, 32, double, copysign) +DEF_SGNJX_VV (sgnj, 64, double, copysign) +DEF_SGNJX_VV (sgnj, 128, double, copysign) +DEF_SGNJX_VV (sgnj, 256, double, copysign) +DEF_SGNJX_VV (sgnj, 512, double, copysign) + +/* { dg-final { scan-assembler-times {vfsgnjx\.vv\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 19 } } */ +/* { dg-final { scan-assembler-not {csrr} } } */