From nobody Tue Feb 10 13:36:53 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=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1673229199; cv=none; d=zohomail.com; s=zohoarc; b=UfLCAw35wNpmnOC3nL9bAkKA7wYdvQhZpvwJXDp7qIFUqkB5ttHGv1E3qzNTnsn5n3JeKQtR34QE7rkAJu/7ODlqavhI/F4Sh5edUseVBniApYVjwf+S5/ajPvl0gNwuH5JE6ADvj9/BWnxpR4qKxpgPJEQaG7GVriqYw1oesQg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673229199; h=Content-Transfer-Encoding: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=+h7RCn1T3BLlChRBESm2AUKCCLXsKfuBBeFApIcrDxY=; b=ZuHlq79H0jiSMLrjW3hiXpmFstk3q4Lj6SdHhCnJuSaRv40aptY+08qXkPSAuGzVWpU2Motw1W1oPN7C+/w/L0P4ddMhpFyphXtTSLp9sPo1wyJdD68qE3n5qq+ZooblWR0cNBC1P1KbsqsMTlc7CBjiZpOje9KoTqxwyeVIEbo= 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 1673229199139624.7995222147208; Sun, 8 Jan 2023 17:53:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pEhBx-0000tG-3e; Sun, 08 Jan 2023 20:43:13 -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 1pEhBw-0000sL-3N for qemu-devel@nongnu.org; Sun, 08 Jan 2023 20:43:12 -0500 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pEhBu-0001af-Iv for qemu-devel@nongnu.org; Sun, 08 Jan 2023 20:43:11 -0500 Received: by mail-pj1-x102a.google.com with SMTP id fz16-20020a17090b025000b002269d6c2d83so10246398pjb.0 for ; Sun, 08 Jan 2023 17:43:10 -0800 (PST) Received: from stoup.. ([2602:47:d48c:8101:a909:891c:953d:a6b0]) by smtp.gmail.com with ESMTPSA id w13-20020a170902ca0d00b00178b77b7e71sm4743617pld.188.2023.01.08.17.43.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 17:43:08 -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:to:from:from:to:cc:subject:date:message-id :reply-to; bh=+h7RCn1T3BLlChRBESm2AUKCCLXsKfuBBeFApIcrDxY=; b=wT5yyM6zUtVSQbCKL2TDavKToH9e8JA9+hT1i1OxFgH/ju8yO/ZtL8kNn8SZct9cd3 g8BTi8HtM0oMCBdWlUk7WeYtMx0EWg1fRwI2EXqcfEL+eLWmEsEXa3xuT3uxUEWC1Oq+ olz+v5s3akkt8dlEjES2Od8iV6WSMQCI5f16FIqb2y2IlyjO0boehZUorJoM2wT5jYFe /Fsmvz8KVbLIntREquCtzf5Vr3A9ep4kyh1qkWArDRZ6aKiRBRbpgbjvKtqQ4OGpebZi ZYyD2980sVUFeEEqg7NJsDLXGrrZrNERmep3O6qccaehMeYNfQCl8rICjpKr+4CByf4T OLxw== 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+h7RCn1T3BLlChRBESm2AUKCCLXsKfuBBeFApIcrDxY=; b=RL2r5IfT7jDYbrlwnNsqEwUcs3tJ3cdkD1QjmxBfGxu1GeAzCqwMF4VNU5gAWLrsb+ eklX7FUSmvrwDFA8gAjA333ThACgSfopeBAyLYyaxluxXa1C63awCRaVzLj1TCMpaQ66 m1U+3d5KYGf1gNg9pXxlAnhtnlp05bm/a+vR8GZokjbdtRalYKt3S2GPZvoD1MJttyX8 kxqvyqpfqkvoids8OvnQWW6RxQ5SoRI4CR1HKUbp9vbTkFzKFObv2hoX+SmJcHa0RHiK T1X6qJUtplaQcY3MfjmKQoE3OTGHZnKdnRDdH1RiWYT9LhtTqmh9ca915RQRrMjo+r98 I/jQ== X-Gm-Message-State: AFqh2kr2+4tY08yeuImVSHXD79YY3lsH8BlLslo+cZInvicpyUb7ACc1 8ARMZ5EQRbyejyD1AV9w35NmjI50wLXQhKBH X-Google-Smtp-Source: AMrXdXs1XSpJY09O/o7ZgeVFSMs3fHou25EthMRo5FEUfCJ+odrofa6afsa4vK/WlTOoprrBsaagFg== X-Received: by 2002:a17:903:240b:b0:192:8bee:3e29 with SMTP id e11-20020a170903240b00b001928bee3e29mr53786136plo.2.1673228589290; Sun, 08 Jan 2023 17:43:09 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 22/22] tcg/riscv: Implement direct branch for goto_tb Date: Sun, 8 Jan 2023 17:42:48 -0800 Message-Id: <20230109014248.2894281-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230109014248.2894281-1-richard.henderson@linaro.org> References: <20230109014248.2894281-1-richard.henderson@linaro.org> MIME-Version: 1.0 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::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.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: 1673229199963100001 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e --- tcg/riscv/tcg-target.c.inc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tcg/riscv/tcg-target.c.inc b/tcg/riscv/tcg-target.c.inc index 82ca86431e..f0b0a98e2c 100644 --- a/tcg/riscv/tcg-target.c.inc +++ b/tcg/riscv/tcg-target.c.inc @@ -1303,7 +1303,11 @@ static void tcg_out_exit_tb(TCGContext *s, uintptr_t= a0) =20 static void tcg_out_goto_tb(TCGContext *s, int which) { - /* indirect jump method */ + /* Direct branch will be patched by tb_target_set_jmp_target. */ + set_jmp_insn_offset(s, which); + tcg_out32(s, OPC_NOP); + + /* When branch is out of range, fall through to indirect. */ tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_TMP0, TCG_REG_ZERO, get_jmp_target_addr(s, which)); tcg_out_opc_imm(s, OPC_JALR, TCG_REG_ZERO, TCG_REG_TMP0, 0); @@ -1313,7 +1317,18 @@ static void tcg_out_goto_tb(TCGContext *s, int which) 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; + tcg_insn_unit insn; + + /* Either directly branch, or fall through to indirect branch. */ + if (offset =3D=3D sextreg(offset, 0, 20)) { + insn =3D encode_uj(OPC_JAL, TCG_REG_ZERO, offset); + } else { + insn =3D OPC_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