From patchwork Thu Sep 29 02:31:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Simpson X-Patchwork-Id: 1684216 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=kKxFDJnj; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MdHVt1WwDz1ypH for ; Thu, 29 Sep 2022 12:34:14 +1000 (AEST) Received: from localhost ([::1]:37998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odjNL-00006F-LO for incoming@patchwork.ozlabs.org; Wed, 28 Sep 2022 22:34:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odjL4-0007IJ-Iw for qemu-devel@nongnu.org; Wed, 28 Sep 2022 22:31:58 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]:32212) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odjL1-0002j1-Jn for qemu-devel@nongnu.org; Wed, 28 Sep 2022 22:31:49 -0400 Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28SMXDFd029188; Thu, 29 Sep 2022 02:31:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=qcppdkim1; bh=HxFLd67o98q74l9ijQTRbSOqeFghNHhk377Ai4GVGek=; b=kKxFDJnjaCK5xvJu+kW4pSDpumIR07JA0WM5jiGVzc9gKIkUGDcvEOPeI9t1t2MzPYXh /tVJ2wyjJZJ2JGSyqQ0wV2VpVEbkdBrvEWOjtLNfncp8LCUyWszJ7pnS9l41TjdPaBho nQQzPk0ANixdRmvkuytmGsOnh4AYjYGR1j4UfUTYJQyaMzRg+JAl+iBDF0bRIIbFwi44 J8JVWEtWnzZj+dKkRxvvX7dRRKdU8S4c+upgjJsatBjrtdUTB+rVcp8gXkeX0N8N99np abr985J0vXuw3xwuF3VWqK6GSU4wtGI/HZBJSwlL9TeBTCEzSuSnXmkhy5vAjANF8rSf 2w== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3jvfp3ufrf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Sep 2022 02:31:38 +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 28T2Qtgh015814; Thu, 29 Sep 2022 02:31:37 GMT Received: from pps.reinject (localhost [127.0.0.1]) by NALASPPMTA04.qualcomm.com (PPS) with ESMTP id 3jvm5sjrte-1; Thu, 29 Sep 2022 02:31:37 +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 28T2UD7q020489; Thu, 29 Sep 2022 02:31:37 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 28T2VaAq021794; Thu, 29 Sep 2022 02:31:37 +0000 Received: by hu-devc-lv-u18-c.qualcomm.com (Postfix, from userid 47164) id BD1E35000A7; Wed, 28 Sep 2022 19:31:36 -0700 (PDT) From: Taylor Simpson To: qemu-devel@nongnu.org Cc: tsimpson@quicinc.com, richard.henderson@linaro.org, f4bug@amsat.org, ale@rev.ng, anjo@rev.ng, bcain@quicinc.com, quic_mathbern@quicinc.com Subject: [PATCH] Hexagon (target/hexagon) Fix predicated assignment to .tmp Date: Wed, 28 Sep 2022 19:31:31 -0700 Message-Id: <20220929023131.22935-1-tsimpson@quicinc.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 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-ORIG-GUID: sKZJ20nauFGPHtolGKbb3I08uPtvYZiA X-Proofpoint-GUID: sKZJ20nauFGPHtolGKbb3I08uPtvYZiA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-29_01,2022-09-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 phishscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=668 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209290014 Received-SPF: pass client-ip=205.220.168.131; envelope-from=tsimpson@qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 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.25, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Here is an example of an instruction with a predicated assignment to a .tmp HVX register if (p1) v12.tmp = vmem(%1 + #0) Note that the .tmp indicates that references to v12 in the same packet take the result of the load. However, when the predicate is false, the value at the start of the packet should be used. To fix this bug, we preload the temporary with the value from the HVX register. Test case added to tests/tcg/hexagon/hvx_misc.c Signed-off-by: Taylor Simpson --- target/hexagon/translate.h | 5 +++++ tests/tcg/hexagon/hvx_misc.c | 39 +++++++++++++++++++++++++++++++++ target/hexagon/gen_tcg_funcs.py | 12 ++++++++++ 3 files changed, 56 insertions(+) diff --git a/target/hexagon/translate.h b/target/hexagon/translate.h index a245172827..1256899dfa 100644 --- a/target/hexagon/translate.h +++ b/target/hexagon/translate.h @@ -83,6 +83,11 @@ static inline bool is_preloaded(DisasContext *ctx, int num) return test_bit(num, ctx->regs_written); } +static inline bool is_tmp_vreg_preloaded(DisasContext *ctx, int num) +{ + return test_bit(num, ctx->vregs_updated_tmp); +} + intptr_t ctx_future_vreg_off(DisasContext *ctx, int regnum, int num, bool alloc_ok); intptr_t ctx_tmp_vreg_off(DisasContext *ctx, int regnum, diff --git a/tests/tcg/hexagon/hvx_misc.c b/tests/tcg/hexagon/hvx_misc.c index 6e2c9ab3cd..3eb4705fb3 100644 --- a/tests/tcg/hexagon/hvx_misc.c +++ b/tests/tcg/hexagon/hvx_misc.c @@ -541,6 +541,43 @@ static void test_vshuff(void) check_output_b(__LINE__, 1); } +static void test_load_tmp_predicated(void) +{ + void *p0 = buffer0; + void *p1 = buffer1; + void *pout = output; + + for (int i = 0; i < BUFSIZE; i++) { + /* + * Load into v12 as .tmp with a false predicate, then + * use it in the next packet + * Should get old new value within the same packet and + * the old value in the next packet + */ + asm("v3 = vmem(%0 + #0)\n\t" + "r1 = #1\n\t" + "v12 = vsplat(r1)\n\t" + "p1 = cmp.gt(r0, r0)\n\t" + "{\n\t" + " if (p1) v12.tmp = vmem(%1 + #0)\n\t" + " v4.w = vadd(v12.w, v3.w)\n\t" + "}\n\t" + "v4.w = vadd(v4.w, v12.w)\n\t" + "vmem(%2 + #0) = v4\n\t" + : : "r"(p0), "r"(p1), "r"(pout) + : "r1", "p1", "v12", "v3", "v4", "v6", "memory"); + p0 += sizeof(MMVector); + p1 += sizeof(MMVector); + pout += sizeof(MMVector); + + for (int j = 0; j < MAX_VEC_SIZE_BYTES / 4; j++) { + expect[i].w[j] = buffer0[i].w[j] + 2; + } + } + + check_output_w(__LINE__, BUFSIZE); +} + int main() { init_buffers(); @@ -578,6 +615,8 @@ int main() test_vshuff(); + test_load_tmp_predicated(); + puts(err ? "FAIL" : "PASS"); return err ? 1 : 0; } diff --git a/target/hexagon/gen_tcg_funcs.py b/target/hexagon/gen_tcg_funcs.py index d72c689ad7..0e13fcbe1f 100755 --- a/target/hexagon/gen_tcg_funcs.py +++ b/target/hexagon/gen_tcg_funcs.py @@ -169,6 +169,18 @@ def genptr_decl(f, tag, regtype, regid, regno): elif (hex_common.is_tmp_result(tag)): f.write(" ctx_tmp_vreg_off(ctx, %s%sN, 1, true);\n" % \ (regtype, regid)) + if ('A_CONDEXEC' in hex_common.attribdict[tag]): + f.write(" if (!is_tmp_vreg_preloaded(ctx, %s)) {\n" % \ + regN) + f.write(" intptr_t src_off =") + f.write(" offsetof(CPUHexagonState, VRegs[%s%sN]);\n"% \ + (regtype, regid)) + f.write(" tcg_gen_gvec_mov(MO_64, %s%sV_off,\n" % \ + (regtype, regid)) + f.write(" src_off,\n") + f.write(" sizeof(MMVector),\n") + f.write(" sizeof(MMVector));\n") + f.write(" }\n") else: f.write(" ctx_future_vreg_off(ctx, %s%sN," % \ (regtype, regid))