From nobody Fri May 17 11:58:53 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=1654553599; cv=none; d=zohomail.com; s=zohoarc; b=IUn888DLbLWJG581UIQc/xvH/MooUwxXf6RV6LAD7JcUqpTYo3lkEiHb9E8Gz6b+lvbpOW9OlohFLc82vRE2JqGCiBvm4BJH+k+XOTOq7EoVaxjjt51n2XzfGKdKJ+pPFEwTHdhMuqFTcxCCu4KgytFHVIGn+crz9X0SUvg7/PE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654553599; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=zKW2CpuxScjTvBcDtpnGFgIdI/6rYa/kAO/nCFERLFU=; b=Arr4WleAL3FQ7LqG3LmAsA+TX+bjGPXi9+j4e4iCebA6gWyA7yBVpF1ufvmWQoLuvBIGQXiVCtaL6Dhx7SzMHDK60y9k91WWZib900FziZLDZabsAXbJpNWXjCyWWRdCi4/w+K1tBcVhW7GfTlYQPbFIc3SO9KVk++dBNnotJb0= 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 1654553599476836.728529859501; Mon, 6 Jun 2022 15:13:19 -0700 (PDT) Received: from localhost ([::1]:49556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyKyL-00088l-HW for importer@patchew.org; Mon, 06 Jun 2022 18:13:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyKxR-0007Tc-Vv for qemu-devel@nongnu.org; Mon, 06 Jun 2022 18:12:22 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:26495) by eggs.gnu.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1nyKxP-0003Zq-FJ for qemu-devel@nongnu.org; Mon, 06 Jun 2022 18:12:21 -0400 Received: from ironmsg09-lv.qualcomm.com ([10.47.202.153]) by alexa-out.qualcomm.com with ESMTP; 06 Jun 2022 15:12:15 -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; 06 Jun 2022 15:12:00 -0700 Received: by hu-devc-lv-u18-c.qualcomm.com (Postfix, from userid 47164) id 0F0525005B6; Mon, 6 Jun 2022 15:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1654553539; x=1686089539; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=zKW2CpuxScjTvBcDtpnGFgIdI/6rYa/kAO/nCFERLFU=; b=dqZj9muPBNuZSjgvrzxumrDUSm6HxC5Hn5IRDIqTLNzQVQJRk5xl3gBX jw7m298RD/3OtYjurSqXhmBHFR2ORIiCixVtWGWgKMW1u1vXZcn7zlOiL 5l2YQoobeArq8wbRwaOpEe2uSSdqsjR6Fw62WSf1ZZvdC613jkDxn3Nla w=; X-QCInternal: smtphost From: Taylor Simpson To: qemu-devel@nongnu.org Cc: tsimpson@quicinc.com, richard.henderson@linaro.org, f4bug@amsat.org, ale@rev.ng, bcain@quicinc.com, mlambert@quicinc.com Subject: [PATCH] Hexagon (target/hexagon) fix store w/mem_noshuf & predicated load Date: Mon, 6 Jun 2022 15:10:43 -0700 Message-Id: <20220606221043.11425-1-tsimpson@quicinc.com> X-Mailer: git-send-email 2.17.1 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: 1654553601594100001 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 --- 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