Skip to contentSkip to conversation

target/i386: Fix incorrect tcg generation for RCR & RCL instructions

PATCH In review Abhigyan Kumar 1 participant 2 messages May 28 – Aug 14

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/i386: Fix incorrect tcg generation for RCR & RCL instructions

RCR and RCL instructions of a count of 9 is meaningless for 8-bit operands. In gen_RCR and gen_RCL functions, gen_rotc_mod converts a rotation of 9 to 0. But, the can_be_zero flag wasn't updated and hence we skip the immediate if branch. This causes 0 to underflow into -1 at tcg_gen_subi_tl(count, count, 1);

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3452

---
 target/i386/tcg/emit.c.inc | 2 ++
 1 file changed, 2 insertions(+)
target/i386/tcg/emit.c.inc +2 -0
index ce636b6c5..a71af846d 100644
@@ -3452,6 +3452,7 @@ static void gen_RCL(DisasContext *s, X86DecodedInsn *decode)
     low_count = tcg_temp_new();
 
     gen_rotc_mod(ot, count);
+    can_be_zero = (ot == MO_8 || ot == MO_16);
     have_1bit_cin = gen_eflags_adcox(s, decode, true, can_be_zero);
     if (can_be_zero) {
         zero_label = gen_new_label();
@@ -3504,6 +3505,7 @@ static void gen_RCR(DisasContext *s, X86DecodedInsn *decode)
     high_count = tcg_temp_new();
 
     gen_rotc_mod(ot, count);
+    can_be_zero = (ot == MO_8 || ot == MO_16);
     have_1bit_cin = gen_eflags_adcox(s, decode, true, can_be_zero);
     if (can_be_zero) {
         zero_label = gen_new_label();
Signature · 1 line
2.54.0
author
#1 lore raw
Quoted 25 lines · Abhigyan Kumar

RCR and RCL instructions of a count of 9 is meaningless for 8-bit operands. In gen_RCR and gen_RCL functions, gen_rotc_mod converts a rotation of 9 to 0. But, the can_be_zero flag wasn't updated and hence we skip the immediate if branch. This causes 0 to underflow into -1 at tcg_gen_subi_tl(count, count, 1);

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3452

---
  target/i386/tcg/emit.c.inc | 2 ++
  1 file changed, 2 insertions(+)
target/i386/tcg/emit.c.inc +1 -0
index ce636b6c5..a71af846d 100644
@@ -3452,6 +3452,7 @@ static void gen_RCL(DisasContext *s, X86DecodedInsn *decode)
      low_count = tcg_temp_new();
 
      gen_rotc_mod(ot, count);
+    can_be_zero = (ot == MO_8 || ot == MO_16);
      have_1bit_cin = gen_eflags_adcox(s, decode, true, can_be_zero);
      if (can_be_zero) {
          zero_label = gen_new_label();

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

Quoted 7 lines
target/i386/tcg/emit.c.inc +1 -0
@@ -3504,6 +3505,7 @@ static void gen_RCR(DisasContext *s, X86DecodedInsn *decode)
      high_count = tcg_temp_new();
 
      gen_rotc_mod(ot, count);
+    can_be_zero = (ot == MO_8 || ot == MO_16);
      have_1bit_cin = gen_eflags_adcox(s, decode, true, can_be_zero);
      if (can_be_zero) {
          zero_label = gen_new_label();

Greetings. It has been over two and a half months since I submitted this patch. It's my humble request to know the status of the review/acceptance for my patch. Please inform me about any required amends.

Thank you for your patience and attention.

Signature · 1 line
Abhigyan Kumar