From nobody Tue Feb 10 11:12:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@quicinc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=quicinc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644578920472874.9905122576279; Fri, 11 Feb 2022 03:28:40 -0800 (PST) Received: from localhost ([::1]:50576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nIU6Q-0004r9-Pp for importer@patchew.org; Fri, 11 Feb 2022 06:28:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nITw1-0007Q2-VX for qemu-devel@nongnu.org; Fri, 11 Feb 2022 06:17:55 -0500 Received: from alexa-out.qualcomm.com ([129.46.98.28]:50440) by eggs.gnu.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1nITvv-00017l-AT for qemu-devel@nongnu.org; Fri, 11 Feb 2022 06:17:52 -0500 Received: from ironmsg09-lv.qualcomm.com ([10.47.202.153]) by alexa-out.qualcomm.com with ESMTP; 11 Feb 2022 03:17:44 -0800 Received: from hu-tsimpson-lv.qualcomm.com (HELO hu-devc-lv-u18-c.qualcomm.com) ([10.47.235.220]) by ironmsg09-lv.qualcomm.com with ESMTP; 11 Feb 2022 03:17:44 -0800 Received: by hu-devc-lv-u18-c.qualcomm.com (Postfix, from userid 47164) id 8FB46500599; Fri, 11 Feb 2022 03:17:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1644578267; x=1676114267; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0dzTvKqq3MYpLs4VTzXjgN149JmYV9f6PlWC6qR44+I=; b=t2e5gv34GkJE1n/+A6bXfQXlKZaU9eJwDvf76Exra80I7OwU2ylDN3pQ aV8VVriv80KoRhbu0hraqTadjxz1RbEX8yWYcCHh5mT/1r30oRGyWTQZK ZsQQirdiWa1XSOymcQOMdBFTr/8YQJIP9De4+coWGjxeuMYOs6hC6QnPN o=; X-QCInternal: smtphost From: Taylor Simpson To: qemu-devel@nongnu.org Subject: [PULL 02/12] Hexagon HVX (target/hexagon) fix bug in HVX saturate instructions Date: Fri, 11 Feb 2022 03:17:12 -0800 Message-Id: <20220211111722.31036-3-tsimpson@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220211111722.31036-1-tsimpson@quicinc.com> References: <20220211111722.31036-1-tsimpson@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=129.46.98.28; envelope-from=tsimpson@qualcomm.com; helo=alexa-out.qualcomm.com X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, tsimpson@quicinc.com, richard.henderson@linaro.org, f4bug@amsat.org, zongyuan.li@smartx.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1644578921080100003 Two tests added to tests/tcg/hexagon/hvx_misc.c v21.uw =3D vadd(v11.uw, v10.uw):sat v25:24.uw =3D vsub(v17:16.uw, v27:26.uw):sat Signed-off-by: Taylor Simpson Message-Id: <20220210021556.9217-3-tsimpson@quicinc.com> Reviewed-by: Richard Henderson --- target/hexagon/macros.h | 4 +- tests/tcg/hexagon/hvx_misc.c | 71 +++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/target/hexagon/macros.h b/target/hexagon/macros.h index 19d103cad5..a78e84faa4 100644 --- a/target/hexagon/macros.h +++ b/target/hexagon/macros.h @@ -1,5 +1,5 @@ /* - * Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Res= erved. + * Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Res= erved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -268,7 +268,7 @@ static inline void gen_pred_cancel(TCGv pred, int slot_= num) =20 #define fVSATUVALN(N, VAL) \ ({ \ - (((int)(VAL)) < 0) ? 0 : ((1LL << (N)) - 1); \ + (((int64_t)(VAL)) < 0) ? 0 : ((1LL << (N)) - 1); \ }) #define fSATUVALN(N, VAL) \ ({ \ diff --git a/tests/tcg/hexagon/hvx_misc.c b/tests/tcg/hexagon/hvx_misc.c index 312bb98b41..b896f5897e 100644 --- a/tests/tcg/hexagon/hvx_misc.c +++ b/tests/tcg/hexagon/hvx_misc.c @@ -1,5 +1,5 @@ /* - * Copyright(c) 2021 Qualcomm Innovation Center, Inc. All Rights Reserved. + * Copyright(c) 2021-2022 Qualcomm Innovation Center, Inc. All Rights Res= erved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ #include #include #include +#include =20 int err; =20 @@ -432,6 +433,71 @@ TEST_PRED_OP2(pred_and, and, &, "") TEST_PRED_OP2(pred_and_n, and, &, "!") TEST_PRED_OP2(pred_xor, xor, ^, "") =20 +static void test_vadduwsat(void) +{ + /* + * Test for saturation by adding two numbers that add to more than UIN= T_MAX + * and make sure the result saturates to UINT_MAX + */ + const uint32_t x =3D 0xffff0000; + const uint32_t y =3D 0x000fffff; + + memset(expect, 0x12, sizeof(MMVector)); + memset(output, 0x34, sizeof(MMVector)); + + asm volatile ("v10 =3D vsplat(%0)\n\t" + "v11 =3D vsplat(%1)\n\t" + "v21.uw =3D vadd(v11.uw, v10.uw):sat\n\t" + "vmem(%2+#0) =3D v21\n\t" + : /* no outputs */ + : "r"(x), "r"(y), "r"(output) + : "v10", "v11", "v21", "memory"); + + for (int j =3D 0; j < MAX_VEC_SIZE_BYTES / 4; j++) { + expect[0].uw[j] =3D UINT_MAX; + } + + check_output_w(__LINE__, 1); +} + +static void test_vsubuwsat_dv(void) +{ + /* + * Test for saturation by subtracting two numbers where the result is + * negative and make sure the result saturates to zero + * + * vsubuwsat_dv operates on an HVX register pair, so we'll have a + * pair of subtractions + * w - x < 0 + * y - z < 0 + */ + const uint32_t w =3D 0x000000b7; + const uint32_t x =3D 0xffffff4e; + const uint32_t y =3D 0x31fe88e7; + const uint32_t z =3D 0x7fffff79; + + memset(expect, 0x12, sizeof(MMVector) * 2); + memset(output, 0x34, sizeof(MMVector) * 2); + + asm volatile ("v16 =3D vsplat(%0)\n\t" + "v17 =3D vsplat(%1)\n\t" + "v26 =3D vsplat(%2)\n\t" + "v27 =3D vsplat(%3)\n\t" + "v25:24.uw =3D vsub(v17:16.uw, v27:26.uw):sat\n\t" + "vmem(%4+#0) =3D v24\n\t" + "vmem(%4+#1) =3D v25\n\t" + : /* no outputs */ + : "r"(w), "r"(y), "r"(x), "r"(z), "r"(output) + : "v16", "v17", "v24", "v25", "v26", "v27", "memory"); + + for (int j =3D 0; j < MAX_VEC_SIZE_BYTES / 4; j++) { + expect[0].uw[j] =3D 0x00000000; + expect[1].uw[j] =3D 0x00000000; + } + + check_output_w(__LINE__, 2); +} + int main() { init_buffers(); @@ -464,6 +530,9 @@ int main() test_pred_and_n(true); test_pred_xor(false); =20 + test_vadduwsat(); + test_vsubuwsat_dv(); + puts(err ? "FAIL" : "PASS"); return err ? 1 : 0; } --=20 2.17.1