From patchwork Tue Jan 17 23:10:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 643420 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp1443198pvb; Tue, 17 Jan 2023 15:12:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXs27zXPI/XGODhsiKE2sHlcL0YPlpTvCrd7LlfxKksuRcN/DIN0tiH9CEFmU/kV642EGgIL X-Received: by 2002:a05:6214:5093:b0:534:aeae:f37 with SMTP id kk19-20020a056214509300b00534aeae0f37mr8988315qvb.28.1673997144234; Tue, 17 Jan 2023 15:12:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673997144; cv=none; d=google.com; s=arc-20160816; b=ZvZwEoAttgFJF3aceggq0BaaE25vT+e5ms2utyO9LQkj0vGVNcdHmz3x+jobFhYygq uGNDkuktzB+2/JVrE6zkCJyd0zIPE1ULe0ZKetzFdnWCosxAI9mmfN1DhlJeFV3b15Y6 ZTyVn7EkK2wlV2asOWV7G72gRd+kRXVGYFIeUqpAXwfOJ9UsentN5+27Rul/et63ZIQg MFBpwlhOzdFcuZ5MWTxRvbEf4OL+h6HiA/+QhUAc/ZnA1Vyjk/6XeBrWfylH7yX/Nyho tGEV9pGTo1doD5WbaPwu1qp18tQGMaYUKqvAj/CfllYfoi9Yg3xuKj9os9oeLO9Ul1ks 5GXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oIHXkQP1DRpOptMrudVFP2nZqqF+K6pmNG9baQp/CCA=; b=yOlHC4hglngtuJ2sGUYKWbQfOuU41aeklijIIr132j69ORQ9+nMj77adx1IBgtPsM/ GZfVRpmnzYv/ClNATn2JItwCSU3ByWl6kiZOYfmAN1VvMIayD0z3ftPjzJwkmolCccH2 02q64UDTyONsjdNN6QlZ+u3yO3hwACfz8c8FUE+J5ryyelrrU0QZk735spIa0V7OgnWR H+q4hj3GfLEXHQlJPFBKwtiovHAoV8pjE/lNbz46cwOtH1ibFjPUCmc/sKD7X/4tFcYV Y3havjEzdzupG9ZtnZ0u/hQjxmJ0v/BTABtgS4xzhoyZa+LXedPbVM1wZVgedKkmUQak 1jwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yQWl3rYB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s13-20020a05620a254d00b006fa2412eec6si20362155qko.589.2023.01.17.15.12.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jan 2023 15:12:24 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yQWl3rYB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHv79-00041r-S9; 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 1pHv78-0003y5-AK for qemu-devel@nongnu.org; Tue, 17 Jan 2023 18:11:34 -0500 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHv76-0001Js-NZ for qemu-devel@nongnu.org; Tue, 17 Jan 2023 18:11:34 -0500 Received: by mail-pg1-x531.google.com with SMTP id 141so23224555pgc.0 for ; Tue, 17 Jan 2023 15:11:30 -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=oIHXkQP1DRpOptMrudVFP2nZqqF+K6pmNG9baQp/CCA=; b=yQWl3rYBqWkzSEK2NhZO8e0qLXBqImpkmsrwcr8q6MjByyI9I/NKMJXPBHs6DP53L8 gGumYTsEMrSa4P4zBygcgXOJGpTX5Nko7Vx8vDieyqBe8CezsCdmncBiFxO7JjqZDso9 p4MabaCOVy1Z37AoxrPhcPrBBsnHkEJriLzhxkOtkyI4f6IcpGVc3IsGbG7+nLl03yHX xeKJsfTW9sCfaB7GXphdGIY4wcmnSmehDfSdIYbi9IXUfo2DtMfscLU3alr3IQgv8fyk LSC03VL+icwI5fZl0K6PtHojV1PMMNScM4hIolqU+fBGVf00691dLT6UuyGtUczoGDJL 8ACw== 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=oIHXkQP1DRpOptMrudVFP2nZqqF+K6pmNG9baQp/CCA=; b=DzIP1d7UikDZa+KlfbCp69svAL2pvcSdjOssk2W3zyPfeY5klXL/J+Jdc7ZDTEc/aj 75c/02Sw8PLzU6Jf8Fwv7iZnlIja3Tglc0chgXE6StXESTCo4TlIkZ2eP8bWWLoHm9eO C32VPbi7GaQY07WJzL++42xo2sE66x19o+U9Mmv3wf/A90dQuKBdfVfyLtPkD1pSqv8n 4SzsyX2wYx/8+m+0F+Ml87nEloFFwro7uIM4cEwpYqhy1N4YLtAbvvoJxAUoQ69XDztf yuGBINqa3mRcnXGYiIeGrANW5lT2ZeS5Qrh8ExrQVeTq94RNtQ1qqOJgGfSeLJ1CFx07 vI3A== X-Gm-Message-State: AFqh2kqAbOFqM86zgKfQKRcIw6mFWi5Svsu1Yh7wBvG2e6K8yLgVgRnv yiIffSZu5r7UwybeTMxjsTtBA89HldQGQmzm X-Received: by 2002:a62:f203:0:b0:58a:59d4:25aa with SMTP id m3-20020a62f203000000b0058a59d425aamr4633455pfh.31.1673997090406; Tue, 17 Jan 2023 15:11:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 15:11:29 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 22/22] tcg/riscv: Implement direct branch for goto_tb Date: Tue, 17 Jan 2023 13:10:51 -1000 Message-Id: <20230117231051.354444-23-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 Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x531.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée Signed-off-by: Richard Henderson --- 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..fc0edd811f 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) 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_JAL); + + /* 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 = tb->jmp_target_addr[n]; + ptrdiff_t offset = addr - jmp_rx; + tcg_insn_unit insn; + + /* Either directly branch, or fall through to indirect branch. */ + if (offset == sextreg(offset, 0, 20)) { + insn = encode_uj(OPC_JAL, TCG_REG_ZERO, offset); + } else { + insn = OPC_NOP; + } + qatomic_set((uint32_t *)jmp_rw, insn); + flush_idcache_range(jmp_rx, jmp_rw, 4); } static void tcg_out_op(TCGContext *s, TCGOpcode opc,