Skip to contentSkip to conversation

target/i386/tcg: Clear cc_op_dirty after UCOMI

PATCH In review Hungyu Lin 2 participants 3 messages Oct 10 – Oct 14

lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 target/i386/tcg: Clear cc_op_dirty after UCOMI

A self-XOR can leave cc_op_dirty set when UCOMI keeps the CC_OP_EFLAGS selector, causing a redundant store to cpu_cc_op. The UCOMI helper already writes CC_OP_EFLAGS, so clear the dirty flag after assume_cc_op() to avoid emitting that store.

---
 target/i386/tcg/emit.c.inc | 1 +
 1 file changed, 1 insertion(+)
target/i386/tcg/emit.c.inc +1 -0
index 531398d..918122b 100644
@@ -4914,6 +4914,7 @@ static void gen_VUCOMI(DisasContext *s, X86DecodedInsn *decode)
     fn = s->prefix & PREFIX_DATA ? gen_helper_ucomisd : gen_helper_ucomiss;
     fn(tcg_env, OP_PTR1, OP_PTR2);
     assume_cc_op(s, CC_OP_EFLAGS);
+    s->cc_op_dirty = false;
 }
 
 static void gen_VZEROALL(DisasContext *s, X86DecodedInsn *decode)
Signature · 1 line
2.43.0
#1 lore raw
Quoted 15 lines · Hungyu Lin

A self-XOR can leave cc_op_dirty set when UCOMI keeps the CC_OP_EFLAGS selector, causing a redundant store to cpu_cc_op. The UCOMI helper already writes CC_OP_EFLAGS, so clear the dirty flag after assume_cc_op() to avoid emitting that store.

---
  target/i386/tcg/emit.c.inc | 1 +
  1 file changed, 1 insertion(+)
target/i386/tcg/emit.c.inc +0 -0
index 531398d..918122b 100644

target/i386/tcg/emit.c.inc static void gen_VUCOMI(DisasContext *s, X86DecodedInsn *decode) · line 4920

Quoted 7 lines
target/i386/tcg/emit.c.inc +1 -0
@@ -4914,6 +4914,7 @@ static void gen_VUCOMI(DisasContext *s, X86DecodedInsn *decode)
      fn = s->prefix & PREFIX_DATA ? gen_helper_ucomisd : gen_helper_ucomiss;
      fn(tcg_env, OP_PTR1, OP_PTR2);
      assume_cc_op(s, CC_OP_EFLAGS);
+    s->cc_op_dirty = false;
  }
 
  static void gen_VZEROALL(DisasContext *s, X86DecodedInsn *decode)

This is definitely wrong.

If there's something you're trying to fix, explain that.

r~

author
#2 lore raw
Quoted 1 line

If there's something you're trying to fix, explain that.

For XOR -> UCOMISD -> JMP, I see CC_OP_EFLAGS stored twice: once by the helper and again at the jump because cc_op_dirty is still set.

Could you point out which state-tracking invariant clearing it here would violate?

Thanks,
Hungyu