aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2024-12-15 10:06:02 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2025-01-23 11:35:33 +0100
commitb519556f58dcb548f295c5cbbf91617377c5c564 (patch)
tree93aff364f422e01f3bbd35800c7c1174d40bfd76
parente604be4fb4ed1abe5286f8f4145701bf3fc15b97 (diff)
downloadqemu-b519556f58dcb548f295c5cbbf91617377c5c564.zip
qemu-b519556f58dcb548f295c5cbbf91617377c5c564.tar.gz
qemu-b519556f58dcb548f295c5cbbf91617377c5c564.tar.bz2
target/i386: unify REP and REPZ/REPNZ generation
It only differs in a single call to gen_jcc, so use a "bool" argument to distinguish the two cases; do not duplicate code. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Link: https://lore.kernel.org/r/20241215090613.89588-4-pbonzini@redhat.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--target/i386/tcg/translate.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
index a2101b5..877b584 100644
--- a/target/i386/tcg/translate.c
+++ b/target/i386/tcg/translate.c
@@ -1310,14 +1310,18 @@ static void gen_outs(DisasContext *s, MemOp ot)
gen_bpt_io(s, s->tmp2_i32, ot);
}
-/* Generate jumps to current or next instruction */
-static void gen_repz(DisasContext *s, MemOp ot,
- void (*fn)(DisasContext *s, MemOp ot))
+static void do_gen_rep(DisasContext *s, MemOp ot,
+ void (*fn)(DisasContext *s, MemOp ot),
+ bool is_repz_nz)
{
TCGLabel *l2;
l2 = gen_jz_ecx_string(s);
fn(s, ot);
gen_op_add_reg_im(s, s->aflag, R_ECX, -1);
+ if (is_repz_nz) {
+ int nz = (s->prefix & PREFIX_REPNZ) ? 1 : 0;
+ gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), l2);
+ }
/*
* A loop would cause two single step exceptions if ECX = 1
* before rep string_insn
@@ -1325,28 +1329,25 @@ static void gen_repz(DisasContext *s, MemOp ot,
if (s->repz_opt) {
gen_op_jz_ecx(s, l2);
}
+ /*
+ * For CMPS/SCAS there is no need to set CC_OP_DYNAMIC: only one iteration
+ * is done at a time, so the translation block ends unconditionally after
+ * this instruction and there is no control flow junction.
+ */
gen_jmp_rel_csize(s, -cur_insn_len(s), 0);
}
+static void gen_repz(DisasContext *s, MemOp ot,
+ void (*fn)(DisasContext *s, MemOp ot))
+
+{
+ do_gen_rep(s, ot, fn, false);
+}
+
static void gen_repz_nz(DisasContext *s, MemOp ot,
void (*fn)(DisasContext *s, MemOp ot))
{
- TCGLabel *l2;
- int nz = (s->prefix & PREFIX_REPNZ) ? 1 : 0;
-
- l2 = gen_jz_ecx_string(s);
- fn(s, ot);
- gen_op_add_reg_im(s, s->aflag, R_ECX, -1);
- gen_jcc(s, (JCC_Z << 1) | (nz ^ 1), l2);
- if (s->repz_opt) {
- gen_op_jz_ecx(s, l2);
- }
- /*
- * Only one iteration is done at a time, so the translation
- * block ends unconditionally after this instruction and there
- * is no control flow junction - no need to set CC_OP_DYNAMIC.
- */
- gen_jmp_rel_csize(s, -cur_insn_len(s), 0);
+ do_gen_rep(s, ot, fn, true);
}
static void gen_helper_fp_arith_ST0_FT0(int op)