From patchwork Fri Sep 6 17:40:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jin Ma X-Patchwork-Id: 1981996 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=l40WUWJG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X0k8g3njKz1y1D for ; Sat, 7 Sep 2024 03:42:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 83B4B384A408 for ; Fri, 6 Sep 2024 17:42:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by sourceware.org (Postfix) with ESMTPS id BD78B385B505 for ; Fri, 6 Sep 2024 17:42:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD78B385B505 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.alibaba.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BD78B385B505 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=115.124.30.100 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725644558; cv=none; b=o0dl3wOlDXUfQ8FnZch1WwbvhJKvzms9zUs4ib9oz0SNm0Pu4s55TIpXh+5t/1/VEKqj4VrBcfZ0r5OVbz4gn37YoCtKkGq8ff6P1Qd3PzK6SSBAa6WglAAUMUlKh+CPOj0a3wjlsSJFU9jBTAoFq6T3nms5/v2er4C+gRsPXDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725644558; c=relaxed/simple; bh=goC3osNjJV0FNnHuvnsnbm2WoBjk+h23LkSVL13bmN8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=A2HPawKhlOQ/iuhkib8zte8AY5a53jMJUJJNx3CX+MEj4qmzGy5MgRaYpLmBjvHvZk3dlArK5g+PYYHJI4CwIvztCofvhZKRxddNnd3lBfqC/u2WipbhtqVs0H1pwt8ZqXxmbgQOThWq7miUQL5Clj1hkwm5SU3fF2rysacNJrQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1725644553; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=1IEWOE9FPLcDVcjMGR23cEPWv4uWG3Ea4y0IKfHOFkc=; b=l40WUWJGqOxR+Sze7ctdu3UnZIhV0c4BNQgpKPt9HnEpbDd7dNszzsGHFgJFVo9HeD257DGXXNwfm7OQRCCUe5HAmWM4aEbtzHo01G2EbsDsIl++3v+9yIpCVSZorGZJYI8tGZALTOqNQV2KAcr4eTLcXrhoDYXDW1q5k/VHvJA= Received: from localhost.localdomain(mailfrom:jinma@linux.alibaba.com fp:SMTPD_---0WEQ6vzn_1725644547) by smtp.aliyun-inc.com; Sat, 07 Sep 2024 01:42:29 +0800 From: Jin Ma To: gcc-patches@gcc.gnu.org Cc: jeffreyalaw@gmail.com, juzhe.zhong@rivai.ai, pan2.li@intel.com, kito.cheng@gmail.com, jinma.contrib@gmail.com, Jin Ma , nihui Subject: [PATCH v4] RISC-V: Fix illegal operands "th.vsetvli zero, 0, e32, m8" for XTheadVector Date: Sat, 7 Sep 2024 01:40:07 +0800 Message-Id: <20240906174007.354-1-jinma@linux.alibaba.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20240906071036.850-1-jinma@linux.alibaba.com> References: <20240906071036.850-1-jinma@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-27.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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~incoming=patchwork.ozlabs.org@gcc.gnu.org Since the THeadVector vsetvli does not support vl as an immediate, we need to convert 0 to zero when outputting asm. PR target/116592 gcc/ChangeLog: * config/riscv/thead.cc (th_asm_output_opcode): Change '0' to "zero" gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/xtheadvector/pr116592.c: New test. Reported-by: nihui Reported-by: nihui --- gcc/config/riscv/thead.cc | 4 +- .../riscv/rvv/xtheadvector/pr116592.c | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/xtheadvector/pr116592.c diff --git a/gcc/config/riscv/thead.cc b/gcc/config/riscv/thead.cc index 2f1d83fbbc7f..707d91076eb5 100644 --- a/gcc/config/riscv/thead.cc +++ b/gcc/config/riscv/thead.cc @@ -960,11 +960,11 @@ th_asm_output_opcode (FILE *asm_out_file, const char *p) if (strstr (p, "zero,zero")) return "th.vsetvli\tzero,zero,e%0,%m1"; else - return "th.vsetvli\tzero,%0,e%1,%m2"; + return "th.vsetvli\tzero,%z0,e%1,%m2"; } else { - return "th.vsetvli\t%0,%1,e%2,%m3"; + return "th.vsetvli\t%z0,%z1,e%2,%m3"; } } diff --git a/gcc/testsuite/gcc.target/riscv/rvv/xtheadvector/pr116592.c b/gcc/testsuite/gcc.target/riscv/rvv/xtheadvector/pr116592.c new file mode 100644 index 000000000000..a7cd8c5bdb72 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/xtheadvector/pr116592.c @@ -0,0 +1,38 @@ +/* { dg-do assemble } */ +/* { dg-options "-march=rv32gc_zfh_xtheadvector -mabi=ilp32d -O2 -save-temps" { target { rv32 } } } */ +/* { dg-options "-march=rv64gc_zfh_xtheadvector -mabi=lp64d -O2 -save-temps" { target { rv64 } } } */ + +#include +#include + +static vfloat32m8_t atan2_ps(vfloat32m8_t a, vfloat32m8_t b, size_t vl) +{ + float tmpx[vl]; + float tmpy[vl]; + __riscv_vse32_v_f32m8(tmpx, a, vl); + __riscv_vse32_v_f32m8(tmpy, b, vl); + for (size_t i = 0; i < vl; i++) + { + tmpx[i] = atan2(tmpx[i], tmpy[i]); + } + return __riscv_vle32_v_f32m8(tmpx, vl); +} + +void my_atan2(const float *x, const float *y, float *out, int size) +{ + int n = size; + while (n > 0) + { + size_t vl = __riscv_vsetvl_e32m8(n); + vfloat32m8_t _x = __riscv_vle32_v_f32m8(x, vl); + vfloat32m8_t _y = __riscv_vle32_v_f32m8(y, vl); + vfloat32m8_t _out = atan2_ps(_x, _y, vl); + __riscv_vse32_v_f32m8(out, _out, vl); + n -= vl; + x += vl; + y += vl; + out += vl; + } +} + +/* { dg-final { scan-assembler-not {th\.vsetvli\s+zero,0} } } */