From nobody Thu Dec 18 22:25:40 2025 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1673997135; cv=none; d=zohomail.com; s=zohoarc; b=jijdCVBcrRyqnVbgxpQbiRr4buP1uwG3mFhSHlDkJMdDgmJgiCIY13bBqpo+D121kk/K8eR/D2fmDObdSedBA6hL5phDvUYFxaLnTLNDta0zQ+OV6Okya559xY/pgIivE3wdxXlHGfYJounxuY99LHFiUFpbqCOERuOjfZGj4Dw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673997135; 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=ZuZ+Hlic4RgbTEoQoC4Ww4XDg1V1LGDarx8WVkmv+vY=; b=grg/42n533NIePA9P2yMZDIifCUh9gI8V0WWJNT4IrNGJjCT/iVD931O5HzBbaU7sF488nmobrDSivTO7e/a9ukj4O/PWY6mw/P5yL4snExF3eVCIHYLhzZ5aV9T64U3Ek/iKxnz40SDkyoLyNxozTBtoAZLnkDljXon7T5q0fc= 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 1673997135770495.36440890924985; Tue, 17 Jan 2023 15:12:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHv79-0003yn-3n; Tue, 17 Jan 2023 18:11:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHv74-0003w1-AU for qemu-devel@nongnu.org; Tue, 17 Jan 2023 18:11:30 -0500 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHv72-0001Tf-LB for qemu-devel@nongnu.org; Tue, 17 Jan 2023 18:11:30 -0500 Received: by mail-pg1-x52f.google.com with SMTP id f3so23199108pgc.2 for ; Tue, 17 Jan 2023 15:11:28 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id b193-20020a621bca000000b005810c4286d6sm20747070pfb.0.2023.01.17.15.11.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 15:11:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZuZ+Hlic4RgbTEoQoC4Ww4XDg1V1LGDarx8WVkmv+vY=; b=xG07Td2XBomHO6kcHPNpLLrfd4zCdS4qaPIhOeqBRSLWDq8t8jmWuyq0EwRIoHSPxX 1eaWzYB2+iQlZnMzx8K5VTC7IJCI1kYFcXIJZYrwrLbB6YEJUXAUlTBLqU8Uejqf8w2r fo5OoP5MHQZqQvjATzFK03H8xnia0HnzC1YG7pXuRe/YhEqMFLPL/vhB6Gu0a9M+n5PI fP+I716/VoGX2srxsOPo1MBmHl+Bkk0fDUQdqTIlM7HDryBHFeILM9Ta9LfhEhEguRwU 0dDfffrFHiQb5Plm2L8AJCrl8cqcCAT4OdOoZBWKeuE7UzSJ7jqRRFBi0ucXoynLBXO0 cEMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZuZ+Hlic4RgbTEoQoC4Ww4XDg1V1LGDarx8WVkmv+vY=; b=H7nedWwhXNUOyKNWW3psZjBJ9SV51vArjyS7dOW+fjHfd2r4g3KpkZDDd0+QjUY6Kg dq2cIlG+5Ix28EemFTW/ShuIzihuvLmkRfbCfhkPBvHmt0jhmit0vCRPIyc4yh/0ToYh nkKXx2JvAnbyfHmdVcGhCyV39IHxvYMZ8Wl6hsqSCAfNDA0139vOizBvFhPOjVO9f3Ga r6eC/S7w+qzSmFnjSDzGXq07M/9RA/Muyyt+5SLi8EcaFdLnFI2gBNqCoA5buM+vpS56 PpBdcjjgsdfGPK6dT58qClMxWeTUqZ0T1JcRco5VP01F08M9Y5Sw3yQ+f71WnHhCTO2S JN8g== X-Gm-Message-State: AFqh2koCSJZhPVPP/LZssH4E2f9Fy/av8EE/sHqPRRjkJQGorqYj8aS/ HzgfnsBIHzxPcC7/Xoluwg2rlR9D0PJ9ZpiT X-Google-Smtp-Source: AMrXdXuLFN1TZRnRZBh72aKUIGtQxtGMxHEz35bK2Y3h1UVvKCIbOvEPnmZlKZGym6/r09MCyES/tA== X-Received: by 2002:a62:4e8e:0:b0:580:fb8e:3044 with SMTP id c136-20020a624e8e000000b00580fb8e3044mr5846864pfb.22.1673997087205; Tue, 17 Jan 2023 15:11:27 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 20/22] tcg/arm: Implement direct branch for goto_tb Date: Tue, 17 Jan 2023 13:10:49 -1000 Message-Id: <20230117231051.354444-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230117231051.354444-1-richard.henderson@linaro.org> References: <20230117231051.354444-1-richard.henderson@linaro.org> 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=2607:f8b0:4864:20::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1673997137907100007 Now that tcg can handle direct and indirect goto_tb simultaneously, we can optimistically leave space for a direct branch and fall back to loading the pointer from the TB for an indirect branch. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.c.inc | 52 ++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc index e1e1c2620d..6abe94137e 100644 --- a/tcg/arm/tcg-target.c.inc +++ b/tcg/arm/tcg-target.c.inc @@ -135,6 +135,8 @@ typedef enum { ARITH_BIC =3D 0xe << 21, ARITH_MVN =3D 0xf << 21, =20 + INSN_B =3D 0x0a000000, + INSN_CLZ =3D 0x016f0f10, INSN_RBIT =3D 0x06ff0f30, =20 @@ -546,7 +548,7 @@ static bool tcg_target_const_match(int64_t val, TCGType= type, int ct) =20 static void tcg_out_b_imm(TCGContext *s, ARMCond cond, int32_t offset) { - tcg_out32(s, (cond << 28) | 0x0a000000 | + tcg_out32(s, (cond << 28) | INSN_B | (((offset - 8) >> 2) & 0x00ffffff)); } =20 @@ -1941,32 +1943,52 @@ static void tcg_out_exit_tb(TCGContext *s, uintptr_= t arg) =20 static void tcg_out_goto_tb(TCGContext *s, int which) { - /* Indirect jump method */ - intptr_t ptr, dif, dil; - TCGReg base =3D TCG_REG_PC; + uintptr_t i_addr; + intptr_t i_disp; =20 - ptr =3D get_jmp_target_addr(s, which); - dif =3D tcg_pcrel_diff(s, (void *)ptr) - 8; - dil =3D sextract32(dif, 0, 12); - if (dif !=3D dil) { + /* Direct branch will be patched by tb_target_set_jmp_target. */ + set_jmp_insn_offset(s, which); + tcg_out32(s, INSN_NOP); + + /* When branch is out of range, fall through to indirect. */ + i_addr =3D get_jmp_target_addr(s, which); + i_disp =3D tcg_pcrel_diff(s, (void *)i_addr) - 8; + tcg_debug_assert(i_disp < 0); + if (i_disp >=3D -0xfff) { + tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, i_disp); + } else { /* * The TB is close, but outside the 12 bits addressable by * the load. We can extend this to 20 bits with a sub of a - * shifted immediate from pc. In the vastly unlikely event - * the code requires more than 1MB, we'll use 2 insns and - * be no worse off. + * shifted immediate from pc. */ - base =3D TCG_REG_R0; - tcg_out_movi32(s, COND_AL, base, ptr - dil); + int h =3D -i_disp; + int l =3D h & 0xfff; + + h =3D encode_imm_nofail(h - l); + tcg_out_dat_imm(s, COND_AL, ARITH_SUB, TCG_REG_R0, TCG_REG_PC, h); + tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_R0, l); } - tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, base, dil); set_jmp_reset_offset(s, which); } =20 void tb_target_set_jmp_target(const TranslationBlock *tb, int n, uintptr_t jmp_rx, uintptr_t jmp_rw) { - /* Always indirect, nothing to do */ + uintptr_t addr =3D tb->jmp_target_addr[n]; + ptrdiff_t offset =3D addr - (jmp_rx + 8); + tcg_insn_unit insn; + + /* Either directly branch, or fall through to indirect branch. */ + if (offset =3D=3D sextract64(offset, 0, 26)) { + /* B */ + insn =3D deposit32((COND_AL << 28) | INSN_B, 0, 24, offset >> 2); + } else { + insn =3D INSN_NOP; + } + + qatomic_set((uint32_t *)jmp_rw, insn); + flush_idcache_range(jmp_rx, jmp_rw, 4); } =20 static void tcg_out_op(TCGContext *s, TCGOpcode opc, --=20 2.34.1