From nobody Tue Sep 22 02:45:35 2026 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1784044346; cv=none; d=zohomail.com; s=zohoarc; b=Q8nfCuvZLRNbtU55AuKbhjnu6SJ1Mst/wnDFWaMgojXa6dG9gxki8yzDMsGIRTaD2fN+juOvOTb7ailqKUBwvJkSF+NixqVo0Sbyoie5rpGHooEpw8iDWS68TnjamcxYF2cql24wN3KZyrV55yLszaeDjjZsTt/TK+OwjaEiyzw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784044346; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=v9TEZ/r+WdyXkCh0jPLt6TPCbm8hNKa/SZ+tY3PO/BU=; b=YaWyeEjeuwPTNx3wSFcLqrY96sBMQ/QnfbZHHAHphoyCG8ThDeAzjqkv0bhHhqYrjIQV3OcleiUOaFYeeUFIsqQcY20KtAkuMieSHs8bm8zsu6kzjAh3y2tYVkcvXCdLlz39cml1pRN40pMknw6pe+/YLp30tl3J4BAm1qR+LG4= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784044346392388.36153997972474; Tue, 14 Jul 2026 08:52:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjfQ0-0000y5-Ir; Tue, 14 Jul 2026 11:51:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wjfPz-0000xk-Oh for qemu-devel@nongnu.org; Tue, 14 Jul 2026 11:51:35 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wjfPx-00013y-Rb for qemu-devel@nongnu.org; Tue, 14 Jul 2026 11:51:35 -0400 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 66EEdKwf889069 for ; Tue, 14 Jul 2026 15:51:32 GMT Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4fdgudhyb2-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 14 Jul 2026 15:51:32 +0000 (GMT) Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-c894391f000so2490157a12.1 for ; Tue, 14 Jul 2026 08:51:32 -0700 (PDT) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13b987fc629sm41343581c88.0.2026.07.14.08.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 08:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= v9TEZ/r+WdyXkCh0jPLt6TPCbm8hNKa/SZ+tY3PO/BU=; b=cfwxzWM8MHWz6/Nd rA3cTaXo8HeSBNIcibnh2OtDXj0D6OEPmpQsHqZokYlBpyTy7YbdN2hhqWzcb+HA dnLHgS+PSgRdbAKeRBgM+VPO5U/swLuqeOPycXhP1DlVrb/J9RvtPosTAnwSrzac CrY3vXD81byB7tivs5i8k/9mDRtTfq7eDCykQQulY0UslN40MruuMTue75K4w9ya AevFwCvOoMzzNdOi1/Ntitx26v97htuuNl7x/PeyuOPkwumCqru+6l+wCtqV6lz4 MqraLGVWnixDNO9AHVkt2pwQn5QAscQQw0j96GE0bt87IEIuS71geQt2ivz+zfQW Q44q2A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1784044291; x=1784649091; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=v9TEZ/r+WdyXkCh0jPLt6TPCbm8hNKa/SZ+tY3PO/BU=; b=c9/rRSGV0OOH+z2UlBQCTPmns1tdvhNEC5VemCMgu7vOwA+gb+5QT4vX2P8akM4bk8 BCoQUilcmU4yo0k91AsIeGOfchTvNattGJA/zFS3rhzU6rrxzJBvt1AEGXZvZ/aeDZZI WEtgUjiSVcvzfnLM0k4jvsvX7v2CYhfU1uTyomGwE3hH0yCU/8400J4mGzdJXamAlS+8 pG5jvg5vPDG1UDeV68JFqW8NllYVkQAymJ5314AkGs+FSv6MRQhOCDbC5mBWaMlDIM94 3m1ttR5fMo+9+vAWL4uty+42BVcDpmI75ToBM/mW06HlpT91e2AAdEFHZY3fZH03dd1J ueaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784044291; x=1784649091; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message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wH9HTFk= X-Received: by 2002:a05:6a20:430f:b0:3b4:7758:e397 with SMTP id adf61e73a8af0-3c110157a16mr15358173637.16.1784044291519; Tue, 14 Jul 2026 08:51:31 -0700 (PDT) X-Received: by 2002:a05:6a20:430f:b0:3b4:7758:e397 with SMTP id adf61e73a8af0-3c110157a16mr15358127637.16.1784044291004; Tue, 14 Jul 2026 08:51:31 -0700 (PDT) From: Brian Cain To: qemu-devel@nongnu.org Cc: ltaylorsimpson@gmail.com, Laurent Vivier , Thomas Huth , Paolo Bonzini , matheus.bernardino@oss.qualcomm.com, Fabiano Rosas , Brian Cain , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , philmd@oss.qualcomm.com, pierrick.bouvier@oss.qualcomm.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 2/7] target/hexagon: fix PC not advancing for non-COF TB-ending packets Date: Tue, 14 Jul 2026 08:51:21 -0700 Message-Id: <20260714155126.3509544-3-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260714155126.3509544-1-brian.cain@oss.qualcomm.com> References: <20260714155126.3509544-1-brian.cain@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: 2Yz7ulqKmOfaNGm30k5nPYOvTUQr1npL X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzE0MDE2NCBTYWx0ZWRfX0nbFDspqYvYn RawjQx/Mq71XkWTOs+8gMgehrOFcMB5z95BK11bYnrVLBydoa2xkHU5mNsTSHKKjC5Roc4h/v3W J6xLDg9vhQQ5/YrQaKmBqsyVM8wXq2PloZoZt3UqrYCMe9ZqnLPmv4XEcj5kN0AmOYIeLof+KhX oVdYQuz6CwUjbkd4XaNlIQHmVa/zAshtOrMOJJDG0BtrRHXR4YjPl+i8bCoyXfm1elxLhEUXAMD 677LelucDfMYG76sAJEO8ucltepre8o3OJWQqpj4aTWFzICGBslFlISTmqLsDPaSbAKqI5X8kvH CT5YHUiwwnUCH5tbbUDyu1DSNsqvbHrSWe8ivrWw5iWAdE1vDr8jcuDZfNXCDOrBBgzTPKbbKVX hHuyX4fPMrZlhfPz+CjjXCJytymRoE9Y/LXYX5xzbzQT6Q2BzRpPnVIKg6vB81d4H1b+iS2GddM CPiE3tlg3vGws8yfrIA== X-Authority-Analysis: v=2.4 cv=T/O8ifKQ c=1 sm=1 tr=0 ts=6a565b04 cx=c_pps a=rz3CxIlbcmazkYymdCej/Q==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=EUspDBNiAAAA:8 a=j_Ogrd1p5-rMj9Zg3YEA:9 a=QEXdDO2ut3YA:10 a=bFCP_H2QrGi7Okbo017w:22 X-Proofpoint-Spam-Info: AW1haW4tMjYwNzE0MDE2NCBTYWx0ZWRfXy5iIS9H2Gmvb YVMIGG5qE372gd2BXyn5XWHW6HBVAd/gs/5kowI92C398WLY9H3R5Wb4GrYsgWw+0gDVzj3nyCX CvcVEKpqi74spPGFbdMEA/MDtxS1bRE= X-Proofpoint-ORIG-GUID: 2Yz7ulqKmOfaNGm30k5nPYOvTUQr1npL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-14_03,2026-07-14_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 adultscore=0 spamscore=0 phishscore=0 clxscore=1015 bulkscore=0 suspectscore=0 impostorscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607140164 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=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1784044347458158500 Add hex_next_PC, a global mirroring CPUHexagonState::next_PC, and ctx->need_next_pc, so that gen_write_new_pc_addr() can write the branch target through hex_next_PC instead of hex_gpr[HEX_REG_PC] when a later unconditional write of PC is expected. gen_end_tb() then commits hex_next_PC into hex_gpr[HEX_REG_PC] at the end of the packet. Previously, non-COF instructions that still end a TB did not advance the PC, since next_PC's value was never written back into the PC register. Reviewed-by: Pierrick Bouvier Signed-off-by: Brian Cain --- target/hexagon/translate.h | 3 +++ target/hexagon/genptr.c | 14 ++++++++--- target/hexagon/translate.c | 51 ++++++++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/target/hexagon/translate.h b/target/hexagon/translate.h index 0a7f37d5842..2fca157553b 100644 --- a/target/hexagon/translate.h +++ b/target/hexagon/translate.h @@ -40,6 +40,7 @@ typedef struct DisasContext { int reg_log_idx; DECLARE_BITMAP(regs_written, TOTAL_PER_THREAD_REGS); DECLARE_BITMAP(predicated_regs, TOTAL_PER_THREAD_REGS); + bool pkt_ends_tb; bool implicit_usr_write; #ifndef CONFIG_USER_ONLY int greg_log[GREG_WRITES_MAX]; @@ -75,6 +76,7 @@ typedef struct DisasContext { DECLARE_BITMAP(insn_qregs_read, NUM_QREGS); bool pre_commit; bool need_commit; + bool need_next_pc; TCGCond branch_cond; target_ulong branch_dest; bool is_tight_loop; @@ -310,6 +312,7 @@ extern TCGv hex_gpr[TOTAL_PER_THREAD_REGS]; extern TCGv hex_pred[NUM_PREGS]; extern TCGv hex_slot_cancelled; extern TCGv hex_new_value_usr; +extern TCGv hex_next_PC; extern TCGv hex_store_addr[STORES_MAX]; extern TCGv_i32 hex_store_width[STORES_MAX]; extern TCGv hex_store_val32[STORES_MAX]; diff --git a/target/hexagon/genptr.c b/target/hexagon/genptr.c index 1ebc7471409..dc9ba8a0060 100644 --- a/target/hexagon/genptr.c +++ b/target/hexagon/genptr.c @@ -613,14 +613,22 @@ static void gen_write_new_pc_addr(DisasContext *ctx, = TCGv addr, tcg_gen_brcondi_tl(cond, pred, 1, pred_false); } =20 + /* + * If gen_end_tb() will unconditionally overwrite PC with hex_next_PC + * (because this packet has a predicated COF that may not execute), + * write the branch target there instead of directly into the PC + * global, or the overwrite in gen_end_tb() would clobber it. + */ + TCGv pc_wr =3D ctx->need_next_pc ? hex_next_PC : hex_gpr[HEX_REG_PC]; + if (ctx->pkt.pkt_has_multi_cof) { /* If there are multiple branches in a packet, ignore the second o= ne */ - tcg_gen_movcond_tl(TCG_COND_NE, hex_gpr[HEX_REG_PC], + tcg_gen_movcond_tl(TCG_COND_NE, pc_wr, ctx->branch_taken, tcg_constant_tl(0), - hex_gpr[HEX_REG_PC], addr); + pc_wr, addr); tcg_gen_movi_tl(ctx->branch_taken, 1); } else { - tcg_gen_mov_tl(hex_gpr[HEX_REG_PC], addr); + tcg_gen_mov_tl(pc_wr, addr); } =20 if (cond !=3D TCG_COND_ALWAYS) { diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c index 28a171bf623..22f0ff5b891 100644 --- a/target/hexagon/translate.c +++ b/target/hexagon/translate.c @@ -54,6 +54,7 @@ static const AnalyzeInsn opcode_analyze[XX_LAST_OPCODE] = =3D { TCGv hex_gpr[TOTAL_PER_THREAD_REGS]; TCGv hex_pred[NUM_PREGS]; TCGv hex_slot_cancelled; +TCGv hex_next_PC; TCGv hex_new_value_usr; TCGv hex_store_addr[STORES_MAX]; TCGv_i32 hex_store_width[STORES_MAX]; @@ -184,10 +185,16 @@ static void gen_goto_tb(DisasContext *ctx, unsigned t= b_slot_idx, } } =20 +static bool need_next_PC(DisasContext *ctx); + static void gen_end_tb(DisasContext *ctx) { gen_exec_counters(ctx); =20 + if (ctx->need_next_pc) { + tcg_gen_mov_tl(hex_gpr[HEX_REG_PC], hex_next_PC); + } + if (ctx->branch_cond !=3D TCG_COND_NEVER) { if (ctx->branch_cond !=3D TCG_COND_ALWAYS) { TCGLabel *skip =3D gen_new_label(); @@ -391,17 +398,25 @@ static bool pkt_ends_tb(Packet *pkt) =20 static bool need_next_PC(DisasContext *ctx) { - /* Check for conditional control flow or HW loop end */ - for (int i =3D 0; i < ctx->pkt.num_insns; i++) { - uint16_t opcode =3D ctx->pkt.insn[i].opcode; - if (GET_ATTRIB(opcode, A_CONDEXEC) && GET_ATTRIB(opcode, A_COF)) { - return true; - } - if (GET_ATTRIB(opcode, A_HWLOOP0_END) || - GET_ATTRIB(opcode, A_HWLOOP1_END)) { - return true; + Packet *pkt =3D &ctx->pkt; + if (pkt->pkt_has_cof || ctx->pkt_ends_tb) { + for (int i =3D 0; i < pkt->num_insns; i++) { + uint16_t opcode =3D pkt->insn[i].opcode; + if ((GET_ATTRIB(opcode, A_CONDEXEC) && GET_ATTRIB(opcode, A_CO= F)) || + GET_ATTRIB(opcode, A_HWLOOP0_END) || + GET_ATTRIB(opcode, A_HWLOOP1_END)) { + return true; + } } } + /* + * We end the TB on some instructions that do not change the flow (for + * other reasons). In these cases, we must set pc too, as the insn won= 't + * do it themselves. + */ + if (ctx->pkt_ends_tb && !check_for_attrib(pkt, A_COF)) { + return true; + } return false; } =20 @@ -637,12 +652,14 @@ static void gen_start_packet(DisasContext *ctx) ctx->branch_taken =3D NULL; if (ctx->pkt.pkt_has_cof) { ctx->branch_taken =3D tcg_temp_new(); - if (ctx->pkt.pkt_has_multi_cof) { - tcg_gen_movi_tl(ctx->branch_taken, 0); - } - if (need_next_PC(ctx)) { - tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], next_PC); - } + } + if (ctx->pkt.pkt_has_multi_cof) { + tcg_gen_movi_tl(ctx->branch_taken, 0); + } + ctx->pkt_ends_tb =3D pkt_ends_tb(&ctx->pkt); + ctx->need_next_pc =3D need_next_PC(ctx); + if (ctx->need_next_pc) { + tcg_gen_movi_tl(hex_next_PC, next_PC); } =20 /* Preload the predicated registers into get_result_gpr(ctx, i) */ @@ -1142,7 +1159,7 @@ static void gen_commit_packet(DisasContext *ctx) ctx->pkt.vhist_insn->generate(ctx); } =20 - if (pkt_ends_tb(&ctx->pkt) || ctx->base.is_jmp =3D=3D DISAS_NORETURN) { + if (ctx->pkt_ends_tb || ctx->base.is_jmp =3D=3D DISAS_NORETURN) { gen_end_tb(ctx); } } @@ -1327,6 +1344,8 @@ void hexagon_translate_init(void) } hex_new_value_usr =3D tcg_global_mem_new(tcg_env, offsetof(CPUHexagonState, new_value_usr), "new_value_usr"); + hex_next_PC =3D tcg_global_mem_new(tcg_env, + offsetof(CPUHexagonState, next_PC), "next_PC"); =20 for (i =3D 0; i < NUM_PREGS; i++) { hex_pred[i] =3D tcg_global_mem_new(tcg_env, --=20 2.34.1