Patchwork [56/57] target-i386: Simplify bsf/bsr flags computation

login
register
mail settings
Submitter Richard Henderson
Date Jan. 24, 2013, 4:03 a.m.
Message ID <1359000221-19834-57-git-send-email-rth@twiddle.net>
Download mbox | patch
Permalink /patch/215247/
State New
Headers show

Comments

Richard Henderson - Jan. 24, 2013, 4:03 a.m.
There's no need for a branch or for a local temporary.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 target-i386/translate.c | 60 +++++++++++++++++++++----------------------------
 1 file changed, 25 insertions(+), 35 deletions(-)

Patch

diff --git a/target-i386/translate.c b/target-i386/translate.c
index fdb06a1..a9bc21d 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -7153,44 +7153,34 @@  static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
         break;
     case 0x1bc: /* bsf */
     case 0x1bd: /* bsr */
-        {
-            int label1;
-            TCGv t0;
-
-            ot = dflag + OT_WORD;
-            modrm = cpu_ldub_code(env, s->pc++);
-            reg = ((modrm >> 3) & 7) | rex_r;
-            gen_ldst_modrm(env, s,modrm, ot, OR_TMP0, 0);
-            gen_extu(ot, cpu_T[0]);
-            t0 = tcg_temp_local_new();
-            tcg_gen_mov_tl(t0, cpu_T[0]);
-            if ((b & 1) && (prefixes & PREFIX_REPZ) &&
-                (s->cpuid_ext3_features & CPUID_EXT3_ABM)) {
-                switch(ot) {
-                case OT_WORD: gen_helper_lzcnt(cpu_T[0], t0,
-                    tcg_const_i32(16)); break;
-                case OT_LONG: gen_helper_lzcnt(cpu_T[0], t0,
-                    tcg_const_i32(32)); break;
-                case OT_QUAD: gen_helper_lzcnt(cpu_T[0], t0,
-                    tcg_const_i32(64)); break;
-                }
-                gen_op_mov_reg_T0(ot, reg);
+        ot = dflag + OT_WORD;
+        modrm = cpu_ldub_code(env, s->pc++);
+        reg = ((modrm >> 3) & 7) | rex_r;
+        gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0);
+        gen_extu(ot, cpu_T[0]);
+        if ((b & 1) && (prefixes & PREFIX_REPZ) &&
+            (s->cpuid_ext3_features & CPUID_EXT3_ABM)) {
+            switch (ot) {
+            case OT_WORD:
+                gen_helper_lzcnt(cpu_T[0], cpu_T[0], tcg_const_i32(16));
+                break;
+            case OT_LONG:
+                gen_helper_lzcnt(cpu_T[0], cpu_T[0], tcg_const_i32(32));
+                break;
+            case OT_QUAD:
+                gen_helper_lzcnt(cpu_T[0], cpu_T[0], tcg_const_i32(64));
+                break;
+            }
+        } else {
+            tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
+            set_cc_op(s, CC_OP_LOGICB + ot);
+            if (b & 1) {
+                gen_helper_bsr(cpu_T[0], cpu_T[0]);
             } else {
-                label1 = gen_new_label();
-                tcg_gen_movi_tl(cpu_cc_dst, 0);
-                tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, label1);
-                if (b & 1) {
-                    gen_helper_bsr(cpu_T[0], t0);
-                } else {
-                    gen_helper_bsf(cpu_T[0], t0);
-                }
-                gen_op_mov_reg_T0(ot, reg);
-                tcg_gen_movi_tl(cpu_cc_dst, 1);
-                gen_set_label(label1);
-                set_cc_op(s, CC_OP_LOGICB + ot);
+                gen_helper_bsf(cpu_T[0], cpu_T[0]);
             }
-            tcg_temp_free(t0);
         }
+        gen_op_mov_reg_T0(ot, reg);
         break;
         /************************/
         /* bcd */