From patchwork Fri Sep 6 07:10:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jin Ma X-Patchwork-Id: 1981646 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=HBV+zKNU; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4X0S826Vbyz1ygP for ; Fri, 6 Sep 2024 17:11:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A8BFA384A84C for ; Fri, 6 Sep 2024 07:11:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by sourceware.org (Postfix) with ESMTPS id D65BB3858D28; Fri, 6 Sep 2024 07:11:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D65BB3858D28 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 D65BB3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=115.124.30.98 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725606669; cv=none; b=hx4vOnXp7I4X159aXpQCTx9x+9lEksK8t8ALKsz/l9olZb6JJz+AMYdtNvAfOtW/NXMGVHbeJTZHtycTDGLOmWtpZil8zBJ1i9VHvAtYKxUu7LKxTbt9+tMypUoQQibgtVTfI71fLsT9t8/j5zFrVjCOw1uq8Z5fcSVPQ3jKrvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725606669; c=relaxed/simple; bh=J/dKqMagEe85jNDYDYgKW8m85a6U38JORjcEFofJuFo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=jz0rsKWhrDbGQSuDUg1LQkji4CyDNgwOBuaF3kujw91U82+O9mBZAt3yCeyPWS7fLzdg+4tLVJx6bzNy/X1wUNnKK7bCXbAdxgZKjRE9kRn5vbVsIbWSQ+FtI2QNt6SYjoge6iJjfr++YzJZV1LRiYLAfZZ2dZrc+fh0o/G8cdA= 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=1725606658; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=qVkvJV8I3t+KYI3ELLR+fyxULObJtHdihE/SDgPNAqo=; b=HBV+zKNUQKCCEum8VPEaON5/ZJ1dk+6IpQKXZDIONefQpaShaxnYuJYMaUhtcrTzN+ebBH5zkqk0GdkeNs11EY3G1mdYz/E5MshL2HH06EZbHuccAvEElVRZrPWT2ewMX4U1oEmYEyn651zFaJr7XeLhy1IG5HP21PzLD6K228k= Received: from localhost.localdomain(mailfrom:jinma@linux.alibaba.com fp:SMTPD_---0WEOhsK4_1725606647) by smtp.aliyun-inc.com; Fri, 06 Sep 2024 15:10:48 +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, christoph.muellner@vrull.eu, shuizhuyuanluo@gmail.com, pinskia@gcc.gnu.org, jinma.contrib@gmail.com, Jin Ma Subject: [PATCH] RISC-V: Fix illegal operands "th.vsetvli zero, 0, e32, m8" for xtheadvector Date: Fri, 6 Sep 2024 15:10:36 +0800 Message-Id: <20240906071036.850-1-jinma@linux.alibaba.com> X-Mailer: git-send-email 2.21.0 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. Ref: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116592 gcc/ChangeLog: * config/riscv/thead.cc (th_asm_output_opcode): Change '0' to "zero" gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/xtheadvector/bug-116592.c: New test. Reported-by: nihui --- gcc/config/riscv/thead.cc | 4 +-- .../riscv/rvv/xtheadvector/bug-116592.c | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/xtheadvector/bug-116592.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/bug-116592.c b/gcc/testsuite/gcc.target/riscv/rvv/xtheadvector/bug-116592.c new file mode 100644 index 000000000000..937efbfd1b09 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/xtheadvector/bug-116592.c @@ -0,0 +1,36 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv32gc_zfh_xtheadvector -mabi=ilp32d -O2" { target { rv32 } } } */ +/* { dg-options "-march=rv64gc_zfh_xtheadvector -mabi=lp64d -O2" { 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; + } +}