From nobody Fri May 3 00:17:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass 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=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1658273397; cv=none; d=zohomail.com; s=zohoarc; b=W4oifUBNsv5Dl4pdGGxP1oIFbN4ELDCbshQzL8kBJzSj5cpBnIGmDp3NaDFSUGEvAsg0zIDStYFi7nVmPNtb7hUfWqJMfIHmIWOahCsCMo6cJ010iGUQbW86FsBmNFC7YqiZTqX7pV5NqvJZ2ZVMr8c53XBpDyErCqUJ1Id95Jc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658273397; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=d6FaWUOag8iP/9WOQBkQciYmECIUHkxz2/ziesNytL0=; b=PqZI/JI/gyeWOn5J5iukHOAwFBJ5Gn/3jlz3JxxQGJdoC0Ray5c1/6gh/94EePkUk4zPVa/1fhZll9EkyPx8yjIvqT6ozLjFFs5tIuc/WQzOfNbksvmGg5KtXvbyM2i1DI2dtHieiYjSByVrobiEuoaFCrc8zjsBwfsSxiuIzgI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658273397206640.3486983626875; Tue, 19 Jul 2022 16:29:57 -0700 (PDT) Received: from localhost ([::1]:33542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDwf5-0001kU-9L for importer@patchew.org; Tue, 19 Jul 2022 19:29:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDwcO-0006LG-AQ for qemu-devel@nongnu.org; Tue, 19 Jul 2022 19:27:08 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:5716) by eggs.gnu.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1oDwcM-0003MS-97 for qemu-devel@nongnu.org; Tue, 19 Jul 2022 19:27:08 -0400 Received: from ironmsg09-lv.qualcomm.com ([10.47.202.153]) by alexa-out.qualcomm.com with ESMTP; 19 Jul 2022 16:27:04 -0700 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; 19 Jul 2022 16:27:04 -0700 Received: by hu-devc-lv-u18-c.qualcomm.com (Postfix, from userid 47164) id 6F2B35005B7; Tue, 19 Jul 2022 16:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1658273226; x=1689809226; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=d6FaWUOag8iP/9WOQBkQciYmECIUHkxz2/ziesNytL0=; b=DmAVWgwIZFwTaD7NL14UVMlRGDP0Qi/YMghQpuyTO3jaugNWP4Wp15tt 7v+7yB4aMs+IVZM2QFY9oWh69D4jw4iyTHHpNfMX1z9qwcb3KPK2sFFca EV9ShoMyAcMkMHjZzwzaXahLRA/WBJieHKeF1V8j+MjpSPdZBXsT0xCk7 g=; X-QCInternal: smtphost From: Taylor Simpson To: qemu-devel@nongnu.org Cc: tsimpson@quicinc.com, richard.henderson@linaro.org, f4bug@amsat.org, peter.maydell@linaro.org, Brian Cain Subject: [PULL 1/2] Hexagon (target/hexagon) fix store w/mem_noshuf & predicated load Date: Tue, 19 Jul 2022 16:26:30 -0700 Message-Id: <20220719232631.25316-2-tsimpson@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220719232631.25316-1-tsimpson@quicinc.com> References: <20220719232631.25316-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.249, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1658273398421100001 Call the CHECK_NOSHUF macro multiple times: once in the fGEN_TCG_PRED_LOAD() and again in fLOAD(). Before this commit, a packet with a store and a predicated load with mem_noshuf that gets encoded like this: { P0 =3D cmp.eq(R17,#0x0) memw(R18+#0x0) =3D R2 if (!P0.new) R3 =3D memw(R17+#0x4) } ... would end up generating a branch over both the load and the store like so: ... brcond_i32 loc17,$0x0,eq,$L1 mov_i32 loc18,store_addr_1 qemu_st_i32 store_val32_1,store_addr_1,leul,0 qemu_ld_i32 loc16,loc7,leul,0 set_label $L1 ... Test cases added to tests/tcg/hexagon/mem_noshuf.c Co-authored-by: Taylor Simpson Signed-off-by: Brian Cain Signed-off-by: Taylor Simpson Reviewed-by: Richard Henderson Message-Id: <20220707210546.15985-2-tsimpson@quicinc.com> --- target/hexagon/gen_tcg.h | 2 + tests/tcg/hexagon/mem_noshuf.c | 122 +++++++++++++++++++++++++++++++-- 2 files changed, 119 insertions(+), 5 deletions(-) diff --git a/target/hexagon/gen_tcg.h b/target/hexagon/gen_tcg.h index c6f0879b6e..b0b6b3644e 100644 --- a/target/hexagon/gen_tcg.h +++ b/target/hexagon/gen_tcg.h @@ -343,6 +343,7 @@ PRED; \ PRED_LOAD_CANCEL(LSB, EA); \ tcg_gen_movi_tl(RdV, 0); \ + CHECK_NOSHUF; \ tcg_gen_brcondi_tl(TCG_COND_EQ, LSB, 0, label); \ fLOAD(1, SIZE, SIGN, EA, RdV); \ gen_set_label(label); \ @@ -402,6 +403,7 @@ PRED; \ PRED_LOAD_CANCEL(LSB, EA); \ tcg_gen_movi_i64(RddV, 0); \ + CHECK_NOSHUF; \ tcg_gen_brcondi_tl(TCG_COND_EQ, LSB, 0, label); \ fLOAD(1, 8, u, EA, RddV); \ gen_set_label(label); \ diff --git a/tests/tcg/hexagon/mem_noshuf.c b/tests/tcg/hexagon/mem_noshuf.c index dd714d5e98..0f4064e700 100644 --- a/tests/tcg/hexagon/mem_noshuf.c +++ b/tests/tcg/hexagon/mem_noshuf.c @@ -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 @@ -84,6 +84,70 @@ MEM_NOSHUF32(mem_noshuf_sd_luh, long long, unsigned s= hort, memd, memuh) MEM_NOSHUF32(mem_noshuf_sd_lw, long long, signed int, memd, memw) MEM_NOSHUF64(mem_noshuf_sd_ld, long long, signed long long, memd, memd) =20 +static inline int pred_lw_sw(int pred, int *p, int *q, int x, int y) +{ + int ret; + asm volatile("p0 =3D cmp.eq(%5, #0)\n\t" + "%0 =3D %3\n\t" + "{\n\t" + " memw(%1) =3D %4\n\t" + " if (!p0) %0 =3D memw(%2)\n\t" + "}:mem_noshuf\n" + : "=3D&r"(ret) + : "r"(p), "r"(q), "r"(x), "r"(y), "r"(pred) + : "p0", "memory"); + return ret; +} + +static inline int pred_lw_sw_pi(int pred, int *p, int *q, int x, int y) +{ + int ret; + asm volatile("p0 =3D cmp.eq(%5, #0)\n\t" + "%0 =3D %3\n\t" + "r7 =3D %2\n\t" + "{\n\t" + " memw(%1) =3D %4\n\t" + " if (!p0) %0 =3D memw(r7++#4)\n\t" + "}:mem_noshuf\n" + : "=3D&r"(ret) + : "r"(p), "r"(q), "r"(x), "r"(y), "r"(pred) + : "r7", "p0", "memory"); + return ret; +} + +static inline long long pred_ld_sd(int pred, long long *p, long long *q, + long long x, long long y) +{ + unsigned long long ret; + asm volatile("p0 =3D cmp.eq(%5, #0)\n\t" + "%0 =3D %3\n\t" + "{\n\t" + " memd(%1) =3D %4\n\t" + " if (!p0) %0 =3D memd(%2)\n\t" + "}:mem_noshuf\n" + : "=3D&r"(ret) + : "r"(p), "r"(q), "r"(x), "r"(y), "r"(pred) + : "p0", "memory"); + return ret; +} + +static inline long long pred_ld_sd_pi(int pred, long long *p, long long *q, + long long x, long long y) +{ + long long ret; + asm volatile("p0 =3D cmp.eq(%5, #0)\n\t" + "%0 =3D %3\n\t" + "r7 =3D %2\n\t" + "{\n\t" + " memd(%1) =3D %4\n\t" + " if (!p0) %0 =3D memd(r7++#8)\n\t" + "}:mem_noshuf\n" + : "=3D&r"(ret) + : "r"(p), "r"(q), "r"(x), "r"(y), "r"(pred) + : "p0", "memory"); + return ret; +} + static inline unsigned int cancel_sw_lb(int pred, int *p, signed char *q, = int x) { unsigned int ret; @@ -126,18 +190,22 @@ typedef union { =20 int err; =20 -static void check32(int n, int expect) +#define check32(n, expect) check32_(n, expect, __LINE__) + +static void check32_(int n, int expect, int line) { if (n !=3D expect) { - printf("ERROR: 0x%08x !=3D 0x%08x\n", n, expect); + printf("ERROR: 0x%08x !=3D 0x%08x, line %d\n", n, expect, line); err++; } } =20 -static void check64(long long n, long long expect) +#define check64(n, expect) check64_(n, expect, __LINE__) + +static void check64_(long long n, long long expect, int line) { if (n !=3D expect) { - printf("ERROR: 0x%08llx !=3D 0x%08llx\n", n, expect); + printf("ERROR: 0x%08llx !=3D 0x%08llx, line %d\n", n, expect, line= ); err++; } } @@ -323,6 +391,50 @@ int main() res64 =3D mem_noshuf_sd_ld(&n.d[0], &n.d[1], 0x123456789abcdef0LL); check64(res64, 0xffffffffffffffffLL); =20 + n.w[0] =3D ~0; + res32 =3D pred_lw_sw(0, &n.w[0], &n.w[0], 0x12345678, 0xc0ffeeda); + check32(res32, 0x12345678); + check32(n.w[0], 0xc0ffeeda); + + n.w[0] =3D ~0; + res32 =3D pred_lw_sw(1, &n.w[0], &n.w[0], 0x12345678, 0xc0ffeeda); + check32(res32, 0xc0ffeeda); + check32(n.w[0], 0xc0ffeeda); + + n.w[0] =3D ~0; + res32 =3D pred_lw_sw_pi(0, &n.w[0], &n.w[0], 0x12345678, 0xc0ffeeda); + check32(res32, 0x12345678); + check32(n.w[0], 0xc0ffeeda); + + n.w[0] =3D ~0; + res32 =3D pred_lw_sw_pi(1, &n.w[0], &n.w[0], 0x12345678, 0xc0ffeeda); + check32(res32, 0xc0ffeeda); + check32(n.w[0], 0xc0ffeeda); + + n.d[0] =3D ~0LL; + res64 =3D pred_ld_sd(0, &n.d[0], &n.d[0], + 0x1234567812345678LL, 0xc0ffeedac0ffeedaLL); + check64(res64, 0x1234567812345678LL); + check64(n.d[0], 0xc0ffeedac0ffeedaLL); + + n.d[0] =3D ~0LL; + res64 =3D pred_ld_sd(1, &n.d[0], &n.d[0], + 0x1234567812345678LL, 0xc0ffeedac0ffeedaLL); + check64(res64, 0xc0ffeedac0ffeedaLL); + check64(n.d[0], 0xc0ffeedac0ffeedaLL); + + n.d[0] =3D ~0LL; + res64 =3D pred_ld_sd_pi(0, &n.d[0], &n.d[0], + 0x1234567812345678LL, 0xc0ffeedac0ffeedaLL); + check64(res64, 0x1234567812345678LL); + check64(n.d[0], 0xc0ffeedac0ffeedaLL); + + n.d[0] =3D ~0LL; + res64 =3D pred_ld_sd_pi(1, &n.d[0], &n.d[0], + 0x1234567812345678LL, 0xc0ffeedac0ffeedaLL); + check64(res64, 0xc0ffeedac0ffeedaLL); + check64(n.d[0], 0xc0ffeedac0ffeedaLL); + puts(err ? "FAIL" : "PASS"); return err; } --=20 2.17.1 From nobody Fri May 3 00:17:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1658273301; cv=none; d=zohomail.com; s=zohoarc; b=ARz7QPyx1n1n1NAjq4H0NdwMq6d3677NIL4jmXWV93Vms+MyXVAYdR+AcIq7hd36l0svs/rg9fhahqiZRkp/f/jDhG9SflZXokEdxxSlwu+5scUGG2q/JxECxTiMJePlvIhuIP8mfHvpCrflD3bxmqmZVhSzMFDk3xCR/sxCEUU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658273301; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FRczhvTGf0IwqZe8q1dpAsFSq2qM8+TAlWozg0slPVA=; b=DVL1tDC/0VfO7baFEgiNQAcvPoK/1pqickSWIjMGzJpqXXmRuNhf9rTW2kvVlhnpbVF5P8kmAG+C7khbDpckiofSm8z/lJok9LmsK9tkRsLVPhY+L0daWLr8oPbO0kWr0CJ1QvPNQHSGCkZsI++hW29xZUImUB8tfPybe4KIoy0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1658273301751433.4770572582205; Tue, 19 Jul 2022 16:28:21 -0700 (PDT) Received: from localhost ([::1]:57814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDwdY-0007Rg-8V for importer@patchew.org; Tue, 19 Jul 2022 19:28:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDwcB-000608-GI for qemu-devel@nongnu.org; Tue, 19 Jul 2022 19:26:55 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]:34152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDwc8-0003Ez-DO for qemu-devel@nongnu.org; Tue, 19 Jul 2022 19:26:54 -0400 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26JNPdJq018464; Tue, 19 Jul 2022 23:26:46 GMT Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3hdqqm24tt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jul 2022 23:26:45 +0000 Received: from pps.filterd (NALASPPMTA04.qualcomm.com [127.0.0.1]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 26JNQiPi016670; Tue, 19 Jul 2022 23:26:44 GMT Received: from pps.reinject (localhost [127.0.0.1]) by NALASPPMTA04.qualcomm.com (PPS) with ESMTPS id 3hc6s3haf0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 19 Jul 2022 23:26:44 +0000 Received: from NALASPPMTA04.qualcomm.com (NALASPPMTA04.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 26JNQiZg016661; Tue, 19 Jul 2022 23:26:44 GMT Received: from hu-devc-lv-u18-c.qualcomm.com (hu-tsimpson-lv.qualcomm.com [10.47.235.220]) by NALASPPMTA04.qualcomm.com (PPS) with ESMTP id 26JNQi73016660; Tue, 19 Jul 2022 23:26:44 +0000 Received: by hu-devc-lv-u18-c.qualcomm.com (Postfix, from userid 47164) id 728825005BE; Tue, 19 Jul 2022 16:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=qcppdkim1; bh=FRczhvTGf0IwqZe8q1dpAsFSq2qM8+TAlWozg0slPVA=; b=OgAosYp5KbB++7tLPog9Vx4KLRwVywgpkukgvVa6wgJQSlvD3yi+6mJS5kHCG8FgRrVu iBEJReutzAY/mryFP5DC29jzL9Z79a3wlmIbhlhD/0XnxoL3STlfuSAwb6vSBaTMIgSd OT2mz3XLtL249Ilw/LIGoNT4zLV0pldRKbbdoKIQ/dDFll6oiN25YMpjNpGVdpJeR7pT 66bDHL/JckkPtyAnynzkzDO6TtdXSOJuPpuEfMBpyOYWauGdp80kqALlniWl9UmfzOj7 1FKu66NsDEdFEKMu/h72gfsQYjI/rEZGcvGX60XmIzMPbklDqeXzELr9X4O6th+KXeoB Sw== From: Taylor Simpson To: qemu-devel@nongnu.org Cc: tsimpson@quicinc.com, richard.henderson@linaro.org, f4bug@amsat.org, peter.maydell@linaro.org Subject: [PULL 2/2] Hexagon (target/hexagon) fix bug in mem_noshuf load exception Date: Tue, 19 Jul 2022 16:26:31 -0700 Message-Id: <20220719232631.25316-3-tsimpson@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220719232631.25316-1-tsimpson@quicinc.com> References: <20220719232631.25316-1-tsimpson@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: JKk_UsgrmfYC9iJNV_pAcf2aBtxUGUpr X-Proofpoint-ORIG-GUID: JKk_UsgrmfYC9iJNV_pAcf2aBtxUGUpr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-19_10,2022-07-19_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 impostorscore=0 adultscore=0 spamscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 phishscore=0 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190095 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=205.220.180.131; envelope-from=tsimpson@qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @quicinc.com) X-ZM-MESSAGEID: 1658273303977100001 The semantics of a mem_noshuf packet are that the store effectively happens before the load. However, in cases where the load raises an exception, we cannot simply execute the store first. This change adds a probe to check that the load will not raise an exception before executing the store. If the load is predicated, this requires special handling. We check the condition before performing the probe. Since, we need the EA to perform the check, we move the GET_EA portion inside CHECK_NOSHUF_PRED. Test case added in tests/tcg/hexagon/mem_noshuf_exception.c Suggested-by: Alessandro Di Federico Suggested-by: Anton Johansson Signed-off-by: Taylor Simpson Reviewed-by: Richard Henderson Message-Id: <20220707210546.15985-3-tsimpson@quicinc.com> --- target/hexagon/gen_tcg.h | 12 +- target/hexagon/helper.h | 1 + target/hexagon/macros.h | 37 ++++-- target/hexagon/genptr.c | 7 ++ target/hexagon/op_helper.c | 23 +++- tests/tcg/hexagon/mem_noshuf_exception.c | 146 +++++++++++++++++++++++ tests/tcg/hexagon/Makefile.target | 1 + 7 files changed, 206 insertions(+), 21 deletions(-) create mode 100644 tests/tcg/hexagon/mem_noshuf_exception.c diff --git a/target/hexagon/gen_tcg.h b/target/hexagon/gen_tcg.h index b0b6b3644e..50634ac459 100644 --- a/target/hexagon/gen_tcg.h +++ b/target/hexagon/gen_tcg.h @@ -339,13 +339,13 @@ do { \ TCGv LSB =3D tcg_temp_local_new(); \ TCGLabel *label =3D gen_new_label(); \ - GET_EA; \ + tcg_gen_movi_tl(EA, 0); \ PRED; \ + CHECK_NOSHUF_PRED(GET_EA, SIZE, LSB); \ PRED_LOAD_CANCEL(LSB, EA); \ tcg_gen_movi_tl(RdV, 0); \ - CHECK_NOSHUF; \ tcg_gen_brcondi_tl(TCG_COND_EQ, LSB, 0, label); \ - fLOAD(1, SIZE, SIGN, EA, RdV); \ + fLOAD(1, SIZE, SIGN, EA, RdV); \ gen_set_label(label); \ tcg_temp_free(LSB); \ } while (0) @@ -399,13 +399,13 @@ do { \ TCGv LSB =3D tcg_temp_local_new(); \ TCGLabel *label =3D gen_new_label(); \ - GET_EA; \ + tcg_gen_movi_tl(EA, 0); \ PRED; \ + CHECK_NOSHUF_PRED(GET_EA, 8, LSB); \ PRED_LOAD_CANCEL(LSB, EA); \ tcg_gen_movi_i64(RddV, 0); \ - CHECK_NOSHUF; \ tcg_gen_brcondi_tl(TCG_COND_EQ, LSB, 0, label); \ - fLOAD(1, 8, u, EA, RddV); \ + fLOAD(1, 8, u, EA, RddV); \ gen_set_label(label); \ tcg_temp_free(LSB); \ } while (0) diff --git a/target/hexagon/helper.h b/target/hexagon/helper.h index c89aa4ed4d..368f0b5708 100644 --- a/target/hexagon/helper.h +++ b/target/hexagon/helper.h @@ -104,6 +104,7 @@ DEF_HELPER_1(vwhist128q, void, env) DEF_HELPER_2(vwhist128m, void, env, s32) DEF_HELPER_2(vwhist128qm, void, env, s32) =20 +DEF_HELPER_4(probe_noshuf_load, void, env, i32, int, int) DEF_HELPER_2(probe_pkt_scalar_store_s0, void, env, int) DEF_HELPER_2(probe_hvx_stores, void, env, int) DEF_HELPER_3(probe_pkt_scalar_hvx_stores, void, env, int, int) diff --git a/target/hexagon/macros.h b/target/hexagon/macros.h index a78e84faa4..92eb8bbf05 100644 --- a/target/hexagon/macros.h +++ b/target/hexagon/macros.h @@ -87,11 +87,28 @@ * * * For qemu, we look for a load in slot 0 when there is a store in slot 1 - * in the same packet. When we see this, we call a helper that merges the - * bytes from the store buffer with the value loaded from memory. + * in the same packet. When we see this, we call a helper that probes the + * load to make sure it doesn't fault. Then, we process the store ahead of + * the actual load. + */ -#define CHECK_NOSHUF \ +#define CHECK_NOSHUF(VA, SIZE) \ do { \ + if (insn->slot =3D=3D 0 && pkt->pkt_has_store_s1) { \ + probe_noshuf_load(VA, SIZE, ctx->mem_idx); \ + process_store(ctx, pkt, 1); \ + } \ + } while (0) + +#define CHECK_NOSHUF_PRED(GET_EA, SIZE, PRED) \ + do { \ + TCGLabel *label =3D gen_new_label(); \ + tcg_gen_brcondi_tl(TCG_COND_EQ, PRED, 0, label); \ + GET_EA; \ + if (insn->slot =3D=3D 0 && pkt->pkt_has_store_s1) { \ + probe_noshuf_load(EA, SIZE, ctx->mem_idx); \ + } \ + gen_set_label(label); \ if (insn->slot =3D=3D 0 && pkt->pkt_has_store_s1) { \ process_store(ctx, pkt, 1); \ } \ @@ -99,37 +116,37 @@ =20 #define MEM_LOAD1s(DST, VA) \ do { \ - CHECK_NOSHUF; \ + CHECK_NOSHUF(VA, 1); \ tcg_gen_qemu_ld8s(DST, VA, ctx->mem_idx); \ } while (0) #define MEM_LOAD1u(DST, VA) \ do { \ - CHECK_NOSHUF; \ + CHECK_NOSHUF(VA, 1); \ tcg_gen_qemu_ld8u(DST, VA, ctx->mem_idx); \ } while (0) #define MEM_LOAD2s(DST, VA) \ do { \ - CHECK_NOSHUF; \ + CHECK_NOSHUF(VA, 2); \ tcg_gen_qemu_ld16s(DST, VA, ctx->mem_idx); \ } while (0) #define MEM_LOAD2u(DST, VA) \ do { \ - CHECK_NOSHUF; \ + CHECK_NOSHUF(VA, 2); \ tcg_gen_qemu_ld16u(DST, VA, ctx->mem_idx); \ } while (0) #define MEM_LOAD4s(DST, VA) \ do { \ - CHECK_NOSHUF; \ + CHECK_NOSHUF(VA, 4); \ tcg_gen_qemu_ld32s(DST, VA, ctx->mem_idx); \ } while (0) #define MEM_LOAD4u(DST, VA) \ do { \ - CHECK_NOSHUF; \ + CHECK_NOSHUF(VA, 4); \ tcg_gen_qemu_ld32s(DST, VA, ctx->mem_idx); \ } while (0) #define MEM_LOAD8u(DST, VA) \ do { \ - CHECK_NOSHUF; \ + CHECK_NOSHUF(VA, 8); \ tcg_gen_qemu_ld64(DST, VA, ctx->mem_idx); \ } while (0) =20 diff --git a/target/hexagon/genptr.c b/target/hexagon/genptr.c index cd6af4bceb..8a334ba07b 100644 --- a/target/hexagon/genptr.c +++ b/target/hexagon/genptr.c @@ -638,5 +638,12 @@ static void vec_to_qvec(size_t size, intptr_t dstoff, = intptr_t srcoff) tcg_temp_free_i64(mask); } =20 +static void probe_noshuf_load(TCGv va, int s, int mi) +{ + TCGv size =3D tcg_constant_tl(s); + TCGv mem_idx =3D tcg_constant_tl(mi); + gen_helper_probe_noshuf_load(cpu_env, va, size, mem_idx); +} + #include "tcg_funcs_generated.c.inc" #include "tcg_func_table_generated.c.inc" diff --git a/target/hexagon/op_helper.c b/target/hexagon/op_helper.c index a5ed819c04..085afc3274 100644 --- a/target/hexagon/op_helper.c +++ b/target/hexagon/op_helper.c @@ -442,6 +442,17 @@ static void probe_store(CPUHexagonState *env, int slot= , int mmu_idx) } } =20 +/* + * Called from a mem_noshuf packet to make sure the load doesn't + * raise an exception + */ +void HELPER(probe_noshuf_load)(CPUHexagonState *env, target_ulong va, + int size, int mmu_idx) +{ + uintptr_t retaddr =3D GETPC(); + probe_read(env, va, size, mmu_idx, retaddr); +} + /* Called during packet commit when there are two scalar stores */ void HELPER(probe_pkt_scalar_store_s0)(CPUHexagonState *env, int mmu_idx) { @@ -514,10 +525,12 @@ void HELPER(probe_pkt_scalar_hvx_stores)(CPUHexagonSt= ate *env, int mask, * If the load is in slot 0 and there is a store in slot1 (that * wasn't cancelled), we have to do the store first. */ -static void check_noshuf(CPUHexagonState *env, uint32_t slot) +static void check_noshuf(CPUHexagonState *env, uint32_t slot, + target_ulong vaddr, int size) { if (slot =3D=3D 0 && env->pkt_has_store_s1 && ((env->slot_cancelled & (1 << 1)) =3D=3D 0)) { + HELPER(probe_noshuf_load)(env, vaddr, size, MMU_USER_IDX); HELPER(commit_store)(env, 1); } } @@ -526,7 +539,7 @@ static uint8_t mem_load1(CPUHexagonState *env, uint32_t= slot, target_ulong vaddr) { uintptr_t ra =3D GETPC(); - check_noshuf(env, slot); + check_noshuf(env, slot, vaddr, 1); return cpu_ldub_data_ra(env, vaddr, ra); } =20 @@ -534,7 +547,7 @@ static uint16_t mem_load2(CPUHexagonState *env, uint32_= t slot, target_ulong vaddr) { uintptr_t ra =3D GETPC(); - check_noshuf(env, slot); + check_noshuf(env, slot, vaddr, 2); return cpu_lduw_data_ra(env, vaddr, ra); } =20 @@ -542,7 +555,7 @@ static uint32_t mem_load4(CPUHexagonState *env, uint32_= t slot, target_ulong vaddr) { uintptr_t ra =3D GETPC(); - check_noshuf(env, slot); + check_noshuf(env, slot, vaddr, 4); return cpu_ldl_data_ra(env, vaddr, ra); } =20 @@ -550,7 +563,7 @@ static uint64_t mem_load8(CPUHexagonState *env, uint32_= t slot, target_ulong vaddr) { uintptr_t ra =3D GETPC(); - check_noshuf(env, slot); + check_noshuf(env, slot, vaddr, 8); return cpu_ldq_data_ra(env, vaddr, ra); } =20 diff --git a/tests/tcg/hexagon/mem_noshuf_exception.c b/tests/tcg/hexagon/m= em_noshuf_exception.c new file mode 100644 index 0000000000..08660ea3e1 --- /dev/null +++ b/tests/tcg/hexagon/mem_noshuf_exception.c @@ -0,0 +1,146 @@ +/* + * Copyright(c) 2022 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +/* + * Test the VLIW semantics of exceptions with mem_noshuf + * + * When a packet has the :mem_noshuf attribute, the semantics dictate + * That the load will get the data from the store if the addresses overlap. + * To accomplish this, we perform the store first. However, we have to + * handle the case where the store raises an exception. In that case, the + * store should not alter the machine state. + * + * We test this with a mem_noshuf packet with a store to a global variable, + * "should_not_change" and a load from NULL. After the SIGSEGV is caught, + * we check * that the "should_not_change" value is the same. + * + * We also check that a predicated load where the predicate is false doesn= 't + * raise an exception and allows the store to happen. + */ + +#include +#include +#include +#include +#include +#include +#include + +int err; +int segv_caught; + +#define SHOULD_NOT_CHANGE_VAL 5 +int should_not_change =3D SHOULD_NOT_CHANGE_VAL; + +#define OK_TO_CHANGE_VAL 13 +int ok_to_change =3D OK_TO_CHANGE_VAL; + +static void __check(const char *filename, int line, int x, int expect) +{ + if (x !=3D expect) { + printf("ERROR %s:%d - %d !=3D %d\n", + filename, line, x, expect); + err++; + } +} + +#define check(x, expect) __check(__FILE__, __LINE__, (x), (expect)) + +static void __chk_error(const char *filename, int line, int ret) +{ + if (ret < 0) { + printf("ERROR %s:%d - %d\n", filename, line, ret); + err++; + } +} + +#define chk_error(ret) __chk_error(__FILE__, __LINE__, (ret)) + +jmp_buf jmp_env; + +static void sig_segv(int sig, siginfo_t *info, void *puc) +{ + check(sig, SIGSEGV); + segv_caught =3D 1; + longjmp(jmp_env, 1); +} + +int main() +{ + struct sigaction act; + int dummy32; + long long dummy64; + void *p; + + /* SIGSEGV test */ + act.sa_sigaction =3D sig_segv; + sigemptyset(&act.sa_mask); + act.sa_flags =3D SA_SIGINFO; + chk_error(sigaction(SIGSEGV, &act, NULL)); + if (setjmp(jmp_env) =3D=3D 0) { + asm volatile("r18 =3D ##should_not_change\n\t" + "r19 =3D #0\n\t" + "{\n\t" + " memw(r18) =3D #7\n\t" + " %0 =3D memw(r19)\n\t" + "}:mem_noshuf\n\t" + : "=3Dr"(dummy32) : : "r18", "r19", "memory"); + } + + act.sa_handler =3D SIG_DFL; + sigemptyset(&act.sa_mask); + act.sa_flags =3D 0; + chk_error(sigaction(SIGSEGV, &act, NULL)); + + check(segv_caught, 1); + check(should_not_change, SHOULD_NOT_CHANGE_VAL); + + /* + * Check that a predicated load where the predicate is false doesn't + * raise an exception and allows the store to happen. + */ + asm volatile("r18 =3D ##ok_to_change\n\t" + "r19 =3D #0\n\t" + "p0 =3D cmp.gt(r0, r0)\n\t" + "{\n\t" + " memw(r18) =3D #7\n\t" + " if (p0) %0 =3D memw(r19)\n\t" + "}:mem_noshuf\n\t" + : "=3Dr"(dummy32) : : "r18", "r19", "p0", "memory"); + + check(ok_to_change, 7); + + /* + * Also check that the post-increment doesn't happen when the + * predicate is false. + */ + ok_to_change =3D OK_TO_CHANGE_VAL; + p =3D NULL; + asm volatile("r18 =3D ##ok_to_change\n\t" + "p0 =3D cmp.gt(r0, r0)\n\t" + "{\n\t" + " memw(r18) =3D #9\n\t" + " if (p0) %1 =3D memd(%0 ++ #8)\n\t" + "}:mem_noshuf\n\t" + : "+r"(p), "=3Dr"(dummy64) : : "r18", "p0", "memory"); + + check(ok_to_change, 9); + check((int)p, (int)NULL); + + puts(err ? "FAIL" : "PASS"); + return err ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/tests/tcg/hexagon/Makefile.target b/tests/tcg/hexagon/Makefile= .target index 23b9870534..96a4d7a614 100644 --- a/tests/tcg/hexagon/Makefile.target +++ b/tests/tcg/hexagon/Makefile.target @@ -35,6 +35,7 @@ HEX_TESTS +=3D preg_alias HEX_TESTS +=3D dual_stores HEX_TESTS +=3D multi_result HEX_TESTS +=3D mem_noshuf +HEX_TESTS +=3D mem_noshuf_exception HEX_TESTS +=3D circ HEX_TESTS +=3D brev HEX_TESTS +=3D load_unpack --=20 2.17.1