From patchwork Mon Dec 14 14:03:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 343545 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp3046203jai; Mon, 14 Dec 2020 06:32:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJz8kSyl/+q4S19OPGAh1goK3dY3IZprZdByR9BxovDHiMTuZtCrD/r4y325c6C78U0VR3Nf X-Received: by 2002:a25:e6c2:: with SMTP id d185mr16504319ybh.304.1607956326247; Mon, 14 Dec 2020 06:32:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607956326; cv=none; d=google.com; s=arc-20160816; b=RObtFMxkajtEw0k1MoDZMJHwgti0Kb2V97/99pC2SxPO3Zkpm19ux0dP0zua1Wr5Rd 2vsaXkli6cEOaxQQ0cJ9faXicqRi1n2LCTmmPqmM2L00yzfhBG/jT1uZEZnxeAnVSAZv jhFyd4rJR5C/Y79FmdL1qgC7X0HD8J1+WTJ7cbwR4zSkvleFLn/i76w3u6mUzr0Gfm48 CaxuKPq2o1bo+fi+Ty5Nn6JaGAw4xuL4MWU34PXaPnmlxWUkHMn7viYHn3k7VAq/ZW3n PnarBlJzTyiyHg8ZyjvihcVXFVHoShDDcNVn9JvoVePzUKK2mKP/bGhLh1spw8p/CE8p YspA== 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:to:from :dkim-signature; bh=LiVRLDdLRLwNh3EAfOwsqGZsrXFOtm3LiOx00UdIraE=; b=WNPtB8AIv5MMP4plHvJIRKPlUFty1t1HGwwttcA5qBWY3Io5UaJiLsvipLNPwJxd0k gq1qOW5x3PdefpOEF7G8ANKHj1xaiPCLi7ao0bBOJ7pQ0jqhF1yz6llqdaxGC9mHJY15 X3Vhh4/MrUo1DQLlZBvVAeIJFqlxDCLnuOkdrJTtqrFEzzw+DBVCe+zN3UxKCjvTTSJh YVHbvI+EYJ+wsDUd0+HQI/Q1aOl5Ve5X0N5ws13RDsREQPhnOOPWEExtEVxFyWUOTGv/ 5S8XHY4r2B9gIxZQpzn9/X8fUGkN4agSSWctTeTMhHCaiWacykJccBWyWcwTNdz6Jxga OBYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yp539SXc; 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 g13si10504342ybe.58.2020.12.14.06.32.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Dec 2020 06:32:06 -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=Yp539SXc; 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]:40890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kootR-0002Rn-LV for patch@linaro.org; Mon, 14 Dec 2020 09:32:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kooSY-0002GA-6J for qemu-devel@nongnu.org; Mon, 14 Dec 2020 09:04:18 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:46731) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kooSW-00041t-AS for qemu-devel@nongnu.org; Mon, 14 Dec 2020 09:04:17 -0500 Received: by mail-ot1-x341.google.com with SMTP id w3so15757739otp.13 for ; Mon, 14 Dec 2020 06:04:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LiVRLDdLRLwNh3EAfOwsqGZsrXFOtm3LiOx00UdIraE=; b=Yp539SXcv2vVYvEqOD/L8Yr9KE2L4Jm69B9GJKrh46zdLmup4HJoKxVfdE3Plhty2F mBaxZ3T2MDEL4U82om742B7cz6Efc9DVDscPrRLdPO9eGtmpVFmiqlKIX/luT7SYQynR vXq/fIpYm6knq4uG0Bl7mZVPIKcmFReRRJp2LxQ9yu1d+4qxLzrEuQepW9Bd7eh/vf9T JT2z7+xGiQxFnNP9OYhpmdlJVtYrOLKPQxozO0ZuEzEy3Wr5EBG2HBwKctAtTOZ5oNKI Qc4S/Rr3nm8HOXJY0C4pNmd7PtfHXLtRVT8br/LSzm/fnjpcUE687RCnybQfimHsGXch 8WRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LiVRLDdLRLwNh3EAfOwsqGZsrXFOtm3LiOx00UdIraE=; b=fbPBMbZZaKg2IiJl/QeQPfJlMIomgSAmFLNTJMBN9wEJ8RhioOxe7qu2pHxrNnWmkx cm8oEE7fOlIk+SAewiAhsOT2qzbskXCk0+FL/RQnHcWrP/ojEXF1mxc8knX4EdvRwiBV 4xTsvwGv60024kKojPzWpcFlFFKvokzPtJcpt7w5K+J4slKVdOcBgbBsfITTMzxTCZE9 /8VxhAg4QN9fxbjwRIJbJ/jEY3dPkZ7EZ20y2GKsNdBzT/xaCA+3L2nNu+mm2rDWJ6h9 cOUdaENJDqnjbgrThUwyspYegDNdim7vZwpmP9QK9zKcJDO+Eue3NsazJg9c6ohIW7O0 qYUA== X-Gm-Message-State: AOAM531ki6mmSN+vQoJJQIz0W/5iJoFmX3zuq9oXTyhc4e3eDTYY8d8s QRzjEnPrxH4K58LPoF6v8phoJ5FdDbmZiGMH X-Received: by 2002:a9d:4b81:: with SMTP id k1mr19980131otf.371.1607954654859; Mon, 14 Dec 2020 06:04:14 -0800 (PST) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id t24sm3940146oou.4.2020.12.14.06.04.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Dec 2020 06:04:14 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 35/43] tcg/riscv: Remove branch-over-branch fallback Date: Mon, 14 Dec 2020 08:03:06 -0600 Message-Id: <20201214140314.18544-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201214140314.18544-1-richard.henderson@linaro.org> References: <20201214140314.18544-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::341; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x341.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.23 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" Since 7ecd02a06f8, we are prepared to re-start code generation with a smaller TB if a relocation is out of range. We no longer need to leave a nop in the stream Just In Case. Signed-off-by: Richard Henderson --- tcg/riscv/tcg-target.c.inc | 56 ++++---------------------------------- 1 file changed, 6 insertions(+), 50 deletions(-) -- 2.25.1 Reviewed-by: Alistair Francis diff --git a/tcg/riscv/tcg-target.c.inc b/tcg/riscv/tcg-target.c.inc index 195c3eff03..02beb86977 100644 --- a/tcg/riscv/tcg-target.c.inc +++ b/tcg/riscv/tcg-target.c.inc @@ -469,43 +469,16 @@ static bool reloc_call(tcg_insn_unit *code_ptr, const tcg_insn_unit *target) static bool patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) { - uint32_t insn = *code_ptr; - intptr_t diff; - bool short_jmp; - tcg_debug_assert(addend == 0); - switch (type) { case R_RISCV_BRANCH: - diff = value - (uintptr_t)code_ptr; - short_jmp = diff == sextreg(diff, 0, 12); - if (short_jmp) { - return reloc_sbimm12(code_ptr, (tcg_insn_unit *)value); - } else { - /* Invert the condition */ - insn = insn ^ (1 << 12); - /* Clear the offset */ - insn &= 0x01fff07f; - /* Set the offset to the PC + 8 */ - insn |= encode_sbimm12(8); - - /* Move forward */ - code_ptr[0] = insn; - - /* Overwrite the NOP with jal x0,value */ - diff = value - (uintptr_t)(code_ptr + 1); - insn = encode_uj(OPC_JAL, TCG_REG_ZERO, diff); - code_ptr[1] = insn; - - return true; - } - break; + return reloc_sbimm12(code_ptr, (tcg_insn_unit *)value); case R_RISCV_JAL: return reloc_jimm20(code_ptr, (tcg_insn_unit *)value); case R_RISCV_CALL: return reloc_call(code_ptr, (tcg_insn_unit *)value); default: - tcg_abort(); + g_assert_not_reached(); } } @@ -779,21 +752,8 @@ static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGReg arg1, arg2 = t; } - if (l->has_value) { - intptr_t diff = tcg_pcrel_diff(s, l->u.value_ptr); - if (diff == sextreg(diff, 0, 12)) { - tcg_out_opc_branch(s, op, arg1, arg2, diff); - } else { - /* Invert the conditional branch. */ - tcg_out_opc_branch(s, op ^ (1 << 12), arg1, arg2, 8); - tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, diff - 4); - } - } else { - tcg_out_reloc(s, s->code_ptr, R_RISCV_BRANCH, l, 0); - tcg_out_opc_branch(s, op, arg1, arg2, 0); - /* NOP to allow patching later */ - tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_ZERO, TCG_REG_ZERO, 0); - } + tcg_out_reloc(s, s->code_ptr, R_RISCV_BRANCH, l, 0); + tcg_out_opc_branch(s, op, arg1, arg2, 0); } static void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGReg ret, @@ -1009,8 +969,6 @@ static void tcg_out_tlb_load(TCGContext *s, TCGReg addrl, /* Compare masked address with the TLB entry. */ label_ptr[0] = s->code_ptr; tcg_out_opc_branch(s, OPC_BNE, TCG_REG_TMP0, TCG_REG_TMP1, 0); - /* NOP to allow patching later */ - tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_ZERO, TCG_REG_ZERO, 0); /* TLB Hit - translate address using addend. */ if (TCG_TARGET_REG_BITS > TARGET_LONG_BITS) { @@ -1054,8 +1012,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l) } /* resolve label address */ - if (!patch_reloc(l->label_ptr[0], R_RISCV_BRANCH, - (intptr_t) s->code_ptr, 0)) { + if (!reloc_sbimm12(l->label_ptr[0], s->code_ptr)) { return false; } @@ -1089,8 +1046,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l) } /* resolve label address */ - if (!patch_reloc(l->label_ptr[0], R_RISCV_BRANCH, - (intptr_t) s->code_ptr, 0)) { + if (!reloc_sbimm12(l->label_ptr[0], s->code_ptr)) { return false; }