Skip to contentSkip to conversation

Fix flags after shift by zero

Qemu-devel Andreas Schwab 1 participant 1 message Jul 27, 2008

lore
Share & tools
lore
#0 lore raw

When the shift count is zero in a shift insn the carry flag is supposed to be cleared and the X flag is unaffected.

Andreas.

helper.c +9 -6
Index: target-m68k/helper.c
===================================================================
@@ -437,7 +437,7 @@ uint32_t HELPER(shl_cc)(CPUState *env, u
     shift &= 63;
     if (shift == 0) {
         result = val;
-        cf = env->cc_src & CCF_C;
+        cf = 0;
     } else if (shift < 32) {
         result = val << shift;
         cf = (val >> (32 - shift)) & 1;
@@ -449,7 +449,8 @@ uint32_t HELPER(shl_cc)(CPUState *env, u
         cf = 0;
     }
     env->cc_src = cf;
-    env->cc_x = (cf != 0);
+    if (shift != 0)
+        env->cc_x = cf;
     env->cc_dest = result;
     return result;
 }
@@ -462,7 +463,7 @@ uint32_t HELPER(shr_cc)(CPUState *env, u
     shift &= 63;
     if (shift == 0) {
         result = val;
-        cf = env->cc_src & CCF_C;
+        cf = 0;
     } else if (shift < 32) {
         result = val >> shift;
         cf = (val >> (shift - 1)) & 1;
@@ -474,7 +475,8 @@ uint32_t HELPER(shr_cc)(CPUState *env, u
         cf = 0;
     }
     env->cc_src = cf;
-    env->cc_x = (cf != 0);
+    if (shift != 0)
+        env->cc_x = cf;
     env->cc_dest = result;
     return result;
 }
@@ -487,7 +489,7 @@ uint32_t HELPER(sar_cc)(CPUState *env, u
     shift &= 63;
     if (shift == 0) {
         result = val;
-        cf = (env->cc_src & CCF_C) != 0;
+        cf = 0;
     } else if (shift < 32) {
         result = (int32_t)val >> shift;
         cf = (val >> (shift - 1)) & 1;
@@ -496,7 +498,8 @@ uint32_t HELPER(sar_cc)(CPUState *env, u
         cf = val >> 31;
     }
     env->cc_src = cf;
-    env->cc_x = cf;
+    if (shift != 0)
+        env->cc_x = cf;
     env->cc_dest = result;
     return result;
 }
translate.c +0 -3
Index: target-m68k/translate.c
===================================================================
@@ -1902,7 +1902,6 @@ DISAS_INSN(shift_im)
     if (tmp == 0)
         tmp = 8;
     shift = gen_im32(tmp);
-    /* No need to flush flags becuse we know we will set C flag.  */
     if (insn & 0x100) {
         gen_helper_shl_cc(reg, cpu_env, reg, shift);
     } else {
@@ -1922,8 +1921,6 @@ DISAS_INSN(shift_reg)
 
     reg = DREG(insn, 0);
     shift = DREG(insn, 9);
-    /* Shift by zero leaves C flag unmodified.   */
-    gen_flush_flags(s);
     if (insn & 0x100) {
         gen_helper_shl_cc(reg, cpu_env, reg, shift);
     } else {
Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."