From patchwork Tue Jan 5 17:19:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 356903 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp187005jai; Tue, 5 Jan 2021 09:44:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJzNKU8epMx0JsaPNslfLTsfAq4pqOJfP8VPfIaMtJFmHrttc51MY9/ricWs1AysZHN2xhz6 X-Received: by 2002:a25:9906:: with SMTP id z6mr751236ybn.238.1609868660276; Tue, 05 Jan 2021 09:44:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609868660; cv=none; d=google.com; s=arc-20160816; b=vsmpugO9i3kCXkRtXxGl4hi7QtaSNl8UMtyLcfuzCpIySmFPDbhQtZO6skb3aXRFFZ wQytvQH717DLyRAQ6Q53nPueQAMgujWTkHJiu87eETN4vAsh3gv54CYsUeFomf3hc2sc K2L0ZU3q/KXatvphvTKA3TKUoCcz6SJfIS4prz5cyHysos2iaX0YSVqOwgkbLzBC8r0V +xgA1SMeNv5jrofEi7GCS8izTMkkykr6DMFvpEgAy79XITKgB0mlAuZqjLUk59V9HF57 PqhglIgvxrrOzYVpuWuW+h1WL7wilh6BPr8e44Sx+Sso3mw0B1Z0LQSUpN6F7RZU1QVy iu1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=Q/5vpDX6rjCPgvb/9YU60IegGHSAx+QWhFDunev+ydE=; b=Gd8uAzPpjkHLSG6R38J0/VgiDdX7OsEKYpYagbSOmiJuKMCcvRm0hq4jAfib+ylj0z ScNWsjGQUgVx3M8Q72KPuPHeOWR3WJDR4jhmKNy5DSy/pGbhYtq0+ecFrWXn2Qalmsck uAPycNy2PL9955My4pHNy0LwzZQTYH6jLUHW7oDnzBKFq9f54beOJPoZVznXGcEtFcOe IsZ+W0xuVXPRcEGhnPnH4kkhnbk5o38NusaGhtqbbsorNkT7fxyiEIq28s+EI7ZFeGzN 5GLH3hFhDMydJlN926HDnQbRdV4vIcuXL5HC96VtMKhghb5aXpRlGK3p/YwyIhbOvPIG 5VcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ZV/RDqiD"; 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 x36si518784ybd.122.2021.01.05.09.44.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jan 2021 09:44:20 -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="ZV/RDqiD"; 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]:45066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kwqNX-0000Ps-Ot for patch@linaro.org; Tue, 05 Jan 2021 12:44:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwq0w-00030G-QI for qemu-devel@nongnu.org; Tue, 05 Jan 2021 12:20:58 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:47019) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kwq0u-0006kM-UO for qemu-devel@nongnu.org; Tue, 05 Jan 2021 12:20:58 -0500 Received: by mail-pl1-x630.google.com with SMTP id v3so39056plz.13 for ; Tue, 05 Jan 2021 09:20:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q/5vpDX6rjCPgvb/9YU60IegGHSAx+QWhFDunev+ydE=; b=ZV/RDqiDkgBL4Jpfvc70f3eWatofFqf6B1fWJOedilxqkUt+1psshOWpOH+0dQs/cu IEftZBVQboMUtSwO0N/vx3yS5eeEPRomEIbEOqEUojJOLvWC/OqvlH/dPoS8abBLZdC2 Fbd/hAeFUFso4l/GV7Nb9MsoaxmjrvnfMZKz2fZCntuI0I8+bqujn2ko5VGlwS4RsnyA 2kWr9sDs9Ckp9BDvMszTSTKDwzxMWzXQPCB23SBRYX+I442alRWhW2mRKVQW9uXqMndg anjq5VVtuqHTaS08i2/+166V/IcSjuv8u/KIdd0Mpw+PBe/3fcCLp34/QHzp6+QNRMTI LgqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q/5vpDX6rjCPgvb/9YU60IegGHSAx+QWhFDunev+ydE=; b=fiTRp6tSu44VNonYxYstpgs0/jVtiX8Pc3Qm9vTtFke+lzCWVGzoOZ6LYeQLXk2t91 y/j677AYfDY5QfNDHGUW8qL9BQO6yE+yE1ZIdSLfyY2xOZXyb0/q4WxcKTCznyW6STZZ UMxNjdhHKMRanMsN9cX3I5+17hhEOpkCSd+sKYJq9alaJuU19o7ycdgHiPYv8pz6MvKU s+PXXyIhA7lioqKYQJV56mD/c3Moicj7oOjAiLrdQCgBovYCCy/LEtgSM3tQvRdzQ/13 JuPsR9KUCnRXu1ADcgqoR25gqTSZNooohmMrt4dUvWgaeE2SKAvxbcoRVCMqdvfYSCzs uccg== X-Gm-Message-State: AOAM5310RTL+iKcV2kCfCPtWoRsI+87UT19cPVZ0yFcxOMz44uagyGjo w0r9SaYjqHtJcInlD7JdKgxIzClYp++Szw== X-Received: by 2002:a17:90a:fa81:: with SMTP id cu1mr253513pjb.39.1609867255438; Tue, 05 Jan 2021 09:20:55 -0800 (PST) Received: from localhost.localdomain (rrcs-173-197-107-21.west.biz.rr.com. [173.197.107.21]) by smtp.gmail.com with ESMTPSA id u12sm2010pfh.98.2021.01.05.09.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 09:20:54 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v5 36/43] tcg/riscv: Support split-wx code generation Date: Tue, 5 Jan 2021 07:19:43 -1000 Message-Id: <20210105171950.415486-37-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210105171950.415486-1-richard.henderson@linaro.org> References: <20210105171950.415486-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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: , Cc: Alistair Francis Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Alistair Francis Signed-off-by: Richard Henderson --- tcg/riscv/tcg-target.h | 2 +- tcg/riscv/tcg-target.c.inc | 41 +++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 19 deletions(-) -- 2.25.1 diff --git a/tcg/riscv/tcg-target.h b/tcg/riscv/tcg-target.h index 6263af4dd1..c50ecf4dab 100644 --- a/tcg/riscv/tcg-target.h +++ b/tcg/riscv/tcg-target.h @@ -171,6 +171,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t); #define TCG_TARGET_NEED_POOL_LABELS #define TCG_TARGET_HAS_MEMORY_BSWAP 0 -#define TCG_TARGET_SUPPORT_MIRROR 0 +#define TCG_TARGET_SUPPORT_MIRROR 1 #endif diff --git a/tcg/riscv/tcg-target.c.inc b/tcg/riscv/tcg-target.c.inc index 34bee9c5a7..4d595b01d6 100644 --- a/tcg/riscv/tcg-target.c.inc +++ b/tcg/riscv/tcg-target.c.inc @@ -425,41 +425,44 @@ static void tcg_out_nop_fill(tcg_insn_unit *p, int count) * Relocations */ -static bool reloc_sbimm12(tcg_insn_unit *code_ptr, tcg_insn_unit *target) +static bool reloc_sbimm12(tcg_insn_unit *src_rw, const tcg_insn_unit *target) { - intptr_t offset = (intptr_t)target - (intptr_t)code_ptr; + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + intptr_t offset = (intptr_t)target - (intptr_t)src_rx; tcg_debug_assert((offset & 1) == 0); if (offset == sextreg(offset, 0, 12)) { - code_ptr[0] |= encode_sbimm12(offset); + *src_rw |= encode_sbimm12(offset); return true; } return false; } -static bool reloc_jimm20(tcg_insn_unit *code_ptr, tcg_insn_unit *target) +static bool reloc_jimm20(tcg_insn_unit *src_rw, const tcg_insn_unit *target) { - intptr_t offset = (intptr_t)target - (intptr_t)code_ptr; + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + intptr_t offset = (intptr_t)target - (intptr_t)src_rx; tcg_debug_assert((offset & 1) == 0); if (offset == sextreg(offset, 0, 20)) { - code_ptr[0] |= encode_ujimm20(offset); + *src_rw |= encode_ujimm20(offset); return true; } return false; } -static bool reloc_call(tcg_insn_unit *code_ptr, const tcg_insn_unit *target) +static bool reloc_call(tcg_insn_unit *src_rw, const tcg_insn_unit *target) { - intptr_t offset = (intptr_t)target - (intptr_t)code_ptr; + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); + intptr_t offset = (intptr_t)target - (intptr_t)src_rx; int32_t lo = sextreg(offset, 0, 12); int32_t hi = offset - lo; if (offset == hi + lo) { - code_ptr[0] |= encode_uimm20(hi); - code_ptr[1] |= encode_imm12(lo); + src_rw[0] |= encode_uimm20(hi); + src_rw[1] |= encode_imm12(lo); return true; } @@ -532,7 +535,7 @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd, if (tmp == (int32_t)tmp) { tcg_out_opc_upper(s, OPC_AUIPC, rd, 0); tcg_out_opc_imm(s, OPC_ADDI, rd, rd, 0); - ret = reloc_call(s->code_ptr - 2, (tcg_insn_unit *)val); + ret = reloc_call(s->code_ptr - 2, (const tcg_insn_unit *)val); tcg_debug_assert(ret == true); return; } @@ -917,7 +920,7 @@ QEMU_BUILD_BUG_ON(TCG_TARGET_REG_BITS < TARGET_LONG_BITS); QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) > 0); QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) < -(1 << 11)); -static void tcg_out_goto(TCGContext *s, tcg_insn_unit *target) +static void tcg_out_goto(TCGContext *s, const tcg_insn_unit *target) { tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, 0); bool ok = reloc_jimm20(s->code_ptr - 1, target); @@ -993,7 +996,8 @@ static void add_qemu_ldst_label(TCGContext *s, int is_ld, TCGMemOpIdx oi, label->datahi_reg = datahi; label->addrlo_reg = addrlo; label->addrhi_reg = addrhi; - label->raddr = raddr; + /* TODO: Cast goes away when all hosts converted */ + label->raddr = (void *)tcg_splitwx_to_rx(raddr); label->label_ptr[0] = label_ptr[0]; } @@ -1012,7 +1016,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l) } /* resolve label address */ - if (!reloc_sbimm12(l->label_ptr[0], s->code_ptr)) { + if (!reloc_sbimm12(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) { return false; } @@ -1046,7 +1050,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l) } /* resolve label address */ - if (!reloc_sbimm12(l->label_ptr[0], s->code_ptr)) { + if (!reloc_sbimm12(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) { return false; } @@ -1232,7 +1236,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64) #endif } -static tcg_insn_unit *tb_ret_addr; +static const tcg_insn_unit *tb_ret_addr; static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, const int *const_args) @@ -1780,11 +1784,12 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_opc_imm(s, OPC_JALR, TCG_REG_ZERO, tcg_target_call_iarg_regs[1], 0); /* Return path for goto_ptr. Set return value to 0 */ - tcg_code_gen_epilogue = s->code_ptr; + /* TODO: Cast goes away when all hosts converted */ + tcg_code_gen_epilogue = (void *)tcg_splitwx_to_rx(s->code_ptr); tcg_out_mov(s, TCG_TYPE_REG, TCG_REG_A0, TCG_REG_ZERO); /* TB epilogue */ - tb_ret_addr = s->code_ptr; + tb_ret_addr = tcg_splitwx_to_rx(s->code_ptr); for (i = 0; i < ARRAY_SIZE(tcg_target_callee_save_regs); i++) { tcg_out_ld(s, TCG_TYPE_REG, tcg_target_callee_save_regs[i], TCG_REG_SP, SAVE_OFS + i * REG_SIZE);