[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 23/37] target/i386: Use gen_jmp_rel for loop, repz, jecxz insns
From: |
Paolo Bonzini |
Subject: |
[PULL 23/37] target/i386: Use gen_jmp_rel for loop, repz, jecxz insns |
Date: |
Tue, 11 Oct 2022 12:26:46 +0200 |
From: Richard Henderson <richard.henderson@linaro.org>
With gen_jmp_rel, we may chain to the next tb instead of merely
writing to eip and exiting. For repz, subtract cur_insn_len to
restart the current insn.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20221001140935.465607-19-richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/tcg/translate.c | 36 +++++++++++++++---------------------
1 file changed, 15 insertions(+), 21 deletions(-)
diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
index ba1bd7c707..434a6ad6cd 100644
--- a/target/i386/tcg/translate.c
+++ b/target/i386/tcg/translate.c
@@ -224,9 +224,9 @@ STUB_HELPER(wrmsr, TCGv_env env)
static void gen_eob(DisasContext *s);
static void gen_jr(DisasContext *s);
-static void gen_jmp(DisasContext *s, target_ulong eip);
static void gen_jmp_tb(DisasContext *s, target_ulong eip, int tb_num);
static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num);
+static void gen_jmp_rel_csize(DisasContext *s, int diff, int tb_num);
static void gen_op(DisasContext *s1, int op, MemOp ot, int d);
static void gen_exception_gpf(DisasContext *s);
@@ -1185,7 +1185,7 @@ static TCGLabel *gen_jz_ecx_string(DisasContext *s)
TCGLabel *l2 = gen_new_label();
gen_op_jnz_ecx(s, s->aflag, l1);
gen_set_label(l2);
- gen_jmp_tb(s, s->pc - s->cs_base, 1);
+ gen_jmp_rel_csize(s, 0, 1);
gen_set_label(l1);
return l2;
}
@@ -1288,7 +1288,7 @@ static void gen_repz(DisasContext *s, MemOp ot,
if (s->repz_opt) {
gen_op_jz_ecx(s, s->aflag, l2);
}
- gen_jmp(s, s->base.pc_next - s->cs_base);
+ gen_jmp_rel_csize(s, -cur_insn_len(s), 0);
}
#define GEN_REPZ(op) \
@@ -1308,7 +1308,7 @@ static void gen_repz2(DisasContext *s, MemOp ot, int nz,
if (s->repz_opt) {
gen_op_jz_ecx(s, s->aflag, l2);
}
- gen_jmp(s, s->base.pc_next - s->cs_base);
+ gen_jmp_rel_csize(s, -cur_insn_len(s), 0);
}
#define GEN_REPZ2(op) \
@@ -2793,6 +2793,7 @@ static void gen_jmp_tb(DisasContext *s, target_ulong eip,
int tb_num)
}
}
+/* Jump to eip+diff, truncating the result to OT. */
static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num)
{
target_ulong dest = s->pc - s->cs_base + diff;
@@ -2808,9 +2809,11 @@ static void gen_jmp_rel(DisasContext *s, MemOp ot, int
diff, int tb_num)
gen_jmp_tb(s, dest, tb_num);
}
-static void gen_jmp(DisasContext *s, target_ulong eip)
+/* Jump to eip+diff, truncating to the current code size. */
+static void gen_jmp_rel_csize(DisasContext *s, int diff, int tb_num)
{
- gen_jmp_tb(s, eip, 0);
+ /* CODE64 ignores the OT argument, so we need not consider it. */
+ gen_jmp_rel(s, CODE32(s) ? MO_32 : MO_16, diff, tb_num);
}
static inline void gen_ldq_env_A0(DisasContext *s, int offset)
@@ -7404,24 +7407,18 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
case 0xe2: /* loop */
case 0xe3: /* jecxz */
{
- TCGLabel *l1, *l2, *l3;
-
- tval = (int8_t)insn_get(env, s, MO_8);
- tval += s->pc - s->cs_base;
- if (dflag == MO_16) {
- tval &= 0xffff;
- }
+ TCGLabel *l1, *l2;
+ int diff = (int8_t)insn_get(env, s, MO_8);
l1 = gen_new_label();
l2 = gen_new_label();
- l3 = gen_new_label();
gen_update_cc_op(s);
b &= 3;
switch(b) {
case 0: /* loopnz */
case 1: /* loopz */
gen_op_add_reg_im(s, s->aflag, R_ECX, -1);
- gen_op_jz_ecx(s, s->aflag, l3);
+ gen_op_jz_ecx(s, s->aflag, l2);
gen_jcc1(s, (JCC_Z << 1) | (b ^ 1), l1);
break;
case 2: /* loop */
@@ -7434,14 +7431,11 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
break;
}
- gen_set_label(l3);
- gen_update_eip_next(s);
- tcg_gen_br(l2);
+ gen_set_label(l2);
+ gen_jmp_rel_csize(s, 0, 1);
gen_set_label(l1);
- gen_jmp_im(s, tval);
- gen_set_label(l2);
- s->base.is_jmp = DISAS_EOB_ONLY;
+ gen_jmp_rel(s, dflag, diff, 0);
}
break;
case 0x130: /* wrmsr */
--
2.37.3
- [PULL 12/37] target/i386: Introduce DISAS_EOB*, (continued)
- [PULL 12/37] target/i386: Introduce DISAS_EOB*, Paolo Bonzini, 2022/10/11
- [PULL 17/37] target/i386: Remove cur_eip, next_eip arguments to gen_repz*, Paolo Bonzini, 2022/10/11
- [PULL 19/37] target/i386: Truncate values for lcall_real to i32, Paolo Bonzini, 2022/10/11
- [PULL 07/37] target/i386: Return bool from disas_insn, Paolo Bonzini, 2022/10/11
- [PULL 18/37] target/i386: Introduce DISAS_JUMP, Paolo Bonzini, 2022/10/11
- [PULL 16/37] target/i386: Create cur_insn_len, cur_insn_len_i32, Paolo Bonzini, 2022/10/11
- [PULL 20/37] target/i386: Create eip_next_*, Paolo Bonzini, 2022/10/11
- [PULL 13/37] target/i386: Use DISAS_EOB* in gen_movl_seg_T0, Paolo Bonzini, 2022/10/11
- [PULL 21/37] target/i386: Use DISAS_TOO_MANY to exit after gen_io_start, Paolo Bonzini, 2022/10/11
- [PULL 22/37] target/i386: Create gen_jmp_rel, Paolo Bonzini, 2022/10/11
- [PULL 23/37] target/i386: Use gen_jmp_rel for loop, repz, jecxz insns,
Paolo Bonzini <=
- [PULL 24/37] target/i386: Use gen_jmp_rel for gen_jcc, Paolo Bonzini, 2022/10/11
- [PULL 25/37] target/i386: Use gen_jmp_rel for DISAS_TOO_MANY, Paolo Bonzini, 2022/10/11
- [PULL 27/37] target/i386: Merge gen_jmp_tb and gen_goto_tb into gen_jmp_rel, Paolo Bonzini, 2022/10/11
- [PULL 29/37] target/i386: Add cpu_eip, Paolo Bonzini, 2022/10/11
- [PULL 26/37] target/i386: Remove MemOp argument to gen_op_j*_ecx, Paolo Bonzini, 2022/10/11
- [PULL 30/37] target/i386: Inline gen_jmp_im, Paolo Bonzini, 2022/10/11
- [PULL 28/37] target/i386: Create eip_cur_tl, Paolo Bonzini, 2022/10/11
- [PULL 31/37] target/i386: Enable TARGET_TB_PCREL, Paolo Bonzini, 2022/10/11
- [PULL 32/37] x86: Implement MSR_CORE_THREAD_COUNT MSR, Paolo Bonzini, 2022/10/11
- [PULL 35/37] linux-user: i386/signal: move fpstate at the end of the 32-bit frames, Paolo Bonzini, 2022/10/11