Skip to contentSkip to conversation

target/i386: cmpxchg should not touch accumulator

PATCH In review yqwfh 2 participants 2 messages Jul 31, 2021 – Aug 2, 2021

lore
Share & tools
lore

yqwfh

author
#0 lore raw

PATCH 1/1 target/i386: cmpxchg should not touch accumulator

---
 target/i386/tcg/translate.c | 9 ---------
 1 file changed, 9 deletions(-)
target/i386/tcg/translate.c +0 -9
index aacb605..41386dd 100644
@@ -5366,7 +5366,6 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)
                 gen_lea_modrm(env, s, modrm);
                 tcg_gen_atomic_cmpxchg_tl(oldv, s->A0, cmpv, newv,
                                           s->mem_index, ot | MO_LE);
-                gen_op_mov_reg_v(s, ot, R_EAX, oldv);
             } else {
                 if (mod == 3) {
                     rm = (modrm & 7) | REX_B(s);
@@ -5381,15 +5380,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)
                 /* store value = (old == cmp ? new : old);  */
                 tcg_gen_movcond_tl(TCG_COND_EQ, newv, oldv, cmpv, newv, oldv);
                 if (mod == 3) {
-                    gen_op_mov_reg_v(s, ot, R_EAX, oldv);
                     gen_op_mov_reg_v(s, ot, rm, newv);
-                } else {
-                    /* Perform an unconditional store cycle like physical cpu;
-                       must be before changing accumulator to ensure
-                       idempotency if the store faults and the instruction
-                       is restarted */
-                    gen_op_st_v(s, ot, newv, s->A0);
-                    gen_op_mov_reg_v(s, ot, R_EAX, oldv);
                 }
             }
             tcg_gen_mov_tl(cpu_cc_src, oldv);
Signature · 1 line
2.26.3
#1 lore raw
Quoted 21 lines · yqwfh
---
  target/i386/tcg/translate.c | 9 ---------
  1 file changed, 9 deletions(-)
target/i386/tcg/translate.c +0 -1
index aacb605..41386dd 100644
@@ -5366,7 +5366,6 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)
                  gen_lea_modrm(env, s, modrm);
                  tcg_gen_atomic_cmpxchg_tl(oldv, s->A0, cmpv, newv,
                                            s->mem_index, ot | MO_LE);
-                gen_op_mov_reg_v(s, ot, R_EAX, oldv);
              } else {
                  if (mod == 3) {
                      rm = (modrm & 7) | REX_B(s);
@@ -5381,15 +5380,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)
                  /* store value = (old == cmp ? new : old);  */
                  tcg_gen_movcond_tl(TCG_COND_EQ, newv, oldv, cmpv, newv, oldv);
                  if (mod == 3) {

target/i386/tcg/translate.c static target_ulong disas_insn(DisasContext *s, CPUState *cpu) · line 5384

Quoted 10 lines
target/i386/tcg/translate.c +0 -8
-                    gen_op_mov_reg_v(s, ot, R_EAX, oldv);
                      gen_op_mov_reg_v(s, ot, rm, newv);
-                } else {
-                    /* Perform an unconditional store cycle like physical cpu;
-                       must be before changing accumulator to ensure
-                       idempotency if the store faults and the instruction
-                       is restarted */
-                    gen_op_st_v(s, ot, newv, s->A0);
-                    gen_op_mov_reg_v(s, ot, R_EAX, oldv);
                  }

Obviously incorrect. You can't *not* store to EAX. You must conditionally store to EAX.

r~