From patchwork Sun May 27 14:13:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 137015 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1788437lji; Sun, 27 May 2018 07:20:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKICi4iL2TJE8gOa0Rc1eKle9vI8EJqxgEsdn6nNSCjuuSBLV5VZW/RIPMEkj/DRu/8nhGuU X-Received: by 2002:ac8:2acc:: with SMTP id c12-v6mr8897719qta.389.1527430817656; Sun, 27 May 2018 07:20:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527430817; cv=none; d=google.com; s=arc-20160816; b=yUC228C7I5InlcwwywYOyf4IPGJijbwNrsu3LJK/+lRPYyo5TmtEC4EdgWjU8z96F8 pFhCzxDzOHxDqqMGd74C06psMNGtc6jEzQ8bwl6kQvfTsmm4ec+gwGEw7xmm5hj3ghrI fP8e8U/VpUmf3PxGtMjwQ5/m61PaYvlUcM3XCCqmXlbxr1XdSC8FGBBv2KzeaYMlaoqz H1xniB4g8Sh/xAnDxpmJElM1XreJ8vnHTDjk5LswrTlFZAW6DMrjDMtQMQ6+ZDE2ecm4 vvC3Bwxw84ABIAaK5jzljOMb26pc5kMIR1cK1/8Jqg4BNbHMnW9TF+JZJR5HOor9stxn MsZA== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=QDXgm3i/pXo06XR66oqaDP01zaQl6YB/cBs/fNoDwM0=; b=et9vazsE+64SMwNNRsqvHl9UfAwNU2e9gYvLnnF8NyDcBX6EE3E5tXkmYm461J7f1Z pp7KhKmhwjh2OvkWBLy+h5p0DEdHwwyzykXICB9b1McBq1onH/AsuFz269AaoQ79HECD WDgC+vMhXgHCl5Q/vivjaRc0oEcLt6139y/CiRg9YJv88YqO727s5Fs4FM5qW6cWtFKh bpysIzxLGxO+NTg3oRHUTbiJuOuwV01EwV7QS8PNza9Ca/tAyChyqp8OCtQR3XEZwY4N SmoZN/oEy99XJOF5PIeqPQ/omsOsn+fvyvi6tW7Pq/HJ5ppTygBlz/rNz0Z0Jqn9A+/I WJHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eLVrZn8Q; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id r12-v6si3765607qki.227.2018.05.27.07.20.17 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 27 May 2018 07:20:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eLVrZn8Q; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fMwWv-0003k7-10 for patch@linaro.org; Sun, 27 May 2018 10:20:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57702) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fMwQT-0008Q3-AW for qemu-devel@nongnu.org; Sun, 27 May 2018 10:13:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fMwQS-0004NX-3p for qemu-devel@nongnu.org; Sun, 27 May 2018 10:13:37 -0400 Received: from mail-pl0-x22e.google.com ([2607:f8b0:400e:c01::22e]:36874) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fMwQR-0004NQ-SW for qemu-devel@nongnu.org; Sun, 27 May 2018 10:13:36 -0400 Received: by mail-pl0-x22e.google.com with SMTP id w19-v6so5735806plq.4 for ; Sun, 27 May 2018 07:13:35 -0700 (PDT) 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; bh=QDXgm3i/pXo06XR66oqaDP01zaQl6YB/cBs/fNoDwM0=; b=eLVrZn8Q0jtlQu/T5U8noBnhNNi3sE3fHEt0eU7AQtu4U2ISl3vBQNePHy7xjyOLFp A1M8eFOJQhPxyJRTC1ab+d4g9wCiQ5oUWj8m1SCFjRleIeYMFp1FJ270BmV9o624mdua 90DfzZsN/TeZxDmymh+XaDCY52k/IS4+YTZ34= 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; bh=QDXgm3i/pXo06XR66oqaDP01zaQl6YB/cBs/fNoDwM0=; b=cEJrbI4xhzH2dMINRnFTm9Qnoi2lStiyZMJXrCLbpK0vhS5c5jObvKGktIAiozjdzu qjFhe/HGJyP/BBmAPhxurp6uliTneXHii8AR4PO7ELpd9tPmLG5voyMvKMkbL0sfVg8h a8COcJHGVaQJN6R+juGsPMjPrGTld56uTncqw+UIMwKDygQJALPKICcimcduHQJrFQ7A 430cjPi6aZkJfcWX3KqIVtlftqy8CW3VsvYXdTWwwaJFECDlB3C4ZP8EBQV2nV8kvuZR DNKU5pZUhlAjUFdCXqHHNcegbSJehIv2gyJGUzJxlxvGuADyoVRtShE4JZcf6tYGysuO mKqQ== X-Gm-Message-State: ALKqPwfV11bnVcO6vv2v4L+rVFGVsTZnF9seSs2wOvINw8uOGrmYecDK YHU69+6VpOBnCdEb6voR+kHaiGUog84= X-Received: by 2002:a17:902:d706:: with SMTP id w6-v6mr10129556ply.142.1527430414572; Sun, 27 May 2018 07:13:34 -0700 (PDT) Received: from cloudburst.twiddle.net (50-233-235-3-static.hfc.comcastbusiness.net. [50.233.235.3]) by smtp.gmail.com with ESMTPSA id b89-v6sm66680075pfd.85.2018.05.27.07.13.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 May 2018 07:13:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 27 May 2018 09:13:08 -0500 Message-Id: <20180527141324.11937-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180527141324.11937-1-richard.henderson@linaro.org> References: <20180527141324.11937-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::22e Subject: [Qemu-devel] [PATCH 04/20] target/openrisc: Link more translation blocks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stafford Horne Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Track direct jumps via dc->jmp_pc_imm. Use that in preference to jmp_pc when possible. Emit goto_tb in that case, and lookup_and_goto_tb otherwise. Signed-off-by: Richard Henderson --- target/openrisc/translate.c | 82 +++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 36 deletions(-) -- 2.17.0 Reviewed-by: Stafford Horne diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c index e566be6d3c..a8afb9a562 100644 --- a/target/openrisc/translate.c +++ b/target/openrisc/translate.c @@ -42,13 +42,16 @@ /* is_jmp field values */ #define DISAS_EXIT DISAS_TARGET_0 /* force exit to main loop */ -#define DISAS_UPDATE DISAS_TARGET_1 /* cpu state was modified dynamically */ +#define DISAS_JUMP DISAS_TARGET_1 /* exit via jmp_pc/jmp_pc_imm */ typedef struct DisasContext { DisasContextBase base; uint32_t mem_idx; uint32_t tb_flags; uint32_t delayed_branch; + + /* If not -1, jmp_pc contains this value and so is a direct jump. */ + target_ulong jmp_pc_imm; } DisasContext; /* Include the auto-generated decoder. */ @@ -164,34 +167,6 @@ static void check_ov64s(DisasContext *dc) } \ } while (0) -static inline bool use_goto_tb(DisasContext *dc, target_ulong dest) -{ - if (unlikely(dc->base.singlestep_enabled)) { - return false; - } - -#ifndef CONFIG_USER_ONLY - return (dc->base.tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK); -#else - return true; -#endif -} - -static void gen_goto_tb(DisasContext *dc, int n, target_ulong dest) -{ - if (use_goto_tb(dc, dest)) { - tcg_gen_movi_tl(cpu_pc, dest); - tcg_gen_goto_tb(n); - tcg_gen_exit_tb((uintptr_t)dc->base.tb + n); - } else { - tcg_gen_movi_tl(cpu_pc, dest); - if (dc->base.singlestep_enabled) { - gen_exception(dc, EXCP_DEBUG); - } - tcg_gen_exit_tb(0); - } -} - static void gen_ove_cy(DisasContext *dc) { if (dc->tb_flags & SR_OVE) { @@ -655,6 +630,7 @@ static bool trans_l_j(DisasContext *dc, arg_l_j *a, uint32_t insn) LOG_DIS("l.j %d\n", a->n); tcg_gen_movi_tl(jmp_pc, tmp_pc); + dc->jmp_pc_imm = tmp_pc; dc->delayed_branch = 2; return true; } @@ -669,6 +645,7 @@ static bool trans_l_jal(DisasContext *dc, arg_l_jal *a, uint32_t insn) /* Optimize jal being used to load the PC for PIC. */ if (tmp_pc != ret_pc) { tcg_gen_movi_tl(jmp_pc, tmp_pc); + dc->jmp_pc_imm = tmp_pc; dc->delayed_branch = 2; } return true; @@ -1381,6 +1358,8 @@ static void openrisc_tr_init_disas_context(DisasContextBase *dcb, CPUState *cs) dc->mem_idx = cpu_mmu_index(env, false); dc->tb_flags = dc->base.tb->flags; dc->delayed_branch = (dc->tb_flags & TB_FLAGS_DFLAG) != 0; + dc->jmp_pc_imm = -1; + bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4; dc->base.max_insns = MIN(dc->base.max_insns, bound); } @@ -1437,10 +1416,7 @@ static void openrisc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) if (dc->delayed_branch) { dc->delayed_branch--; if (!dc->delayed_branch) { - tcg_gen_mov_tl(cpu_pc, jmp_pc); - tcg_gen_discard_tl(jmp_pc); - dc->base.is_jmp = DISAS_UPDATE; - return; + dc->base.is_jmp = DISAS_JUMP; } } } @@ -1448,22 +1424,56 @@ static void openrisc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) static void openrisc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) { DisasContext *dc = container_of(dcbase, DisasContext, base); + target_ulong jmp_dest; /* If we have already exited the TB, nothing following has effect. */ if (dc->base.is_jmp == DISAS_NORETURN) { return; } + /* Adjust the delayed branch state for the next TB. */ if ((dc->tb_flags & TB_FLAGS_DFLAG ? 1 : 0) != (dc->delayed_branch != 0)) { tcg_gen_movi_i32(cpu_dflag, dc->delayed_branch != 0); } - tcg_gen_movi_tl(cpu_ppc, dc->base.pc_next - 4); + /* For DISAS_TOO_MANY, jump to the next insn. */ + jmp_dest = dc->base.pc_next; + tcg_gen_movi_tl(cpu_ppc, jmp_dest - 4); + switch (dc->base.is_jmp) { + case DISAS_JUMP: + jmp_dest = dc->jmp_pc_imm; + if (jmp_dest == -1) { + /* The jump destination is indirect/computed; use jmp_pc. */ + tcg_gen_mov_tl(cpu_pc, jmp_pc); + tcg_gen_discard_tl(jmp_pc); + if (unlikely(dc->base.singlestep_enabled)) { + gen_exception(dc, EXCP_DEBUG); + } else { + tcg_gen_lookup_and_goto_ptr (); + } + break; + } + /* The jump destination is direct; use jmp_pc_imm. + However, we will have stored into jmp_pc as well; + we know now that it wasn't needed. */ + tcg_gen_discard_tl(jmp_pc); + /* fallthru */ + case DISAS_TOO_MANY: - gen_goto_tb(dc, 0, dc->base.pc_next); + if (unlikely(dc->base.singlestep_enabled)) { + tcg_gen_movi_tl(cpu_pc, jmp_dest); + gen_exception(dc, EXCP_DEBUG); + } else if ((dc->base.pc_first ^ jmp_dest) & TARGET_PAGE_MASK) { + tcg_gen_movi_tl(cpu_pc, jmp_dest); + tcg_gen_lookup_and_goto_ptr (); + } else { + tcg_gen_goto_tb(0); + tcg_gen_movi_tl(cpu_pc, jmp_dest); + tcg_gen_exit_tb((uintptr_t)dc->base.tb + 0); + } break; - case DISAS_UPDATE: + case DISAS_EXIT: if (unlikely(dc->base.singlestep_enabled)) { gen_exception(dc, EXCP_DEBUG);