diff mbox series

[v2,18/23] target/i386: Use gen_jmp_rel for loop and jecxz insns

Message ID 20220906100932.343523-19-richard.henderson@linaro.org
State New
Headers show
Series target/i386: pc-relative translation blocks | expand

Commit Message

Richard Henderson Sept. 6, 2022, 10:09 a.m. UTC
With gen_jmp_rel, we may chain to the next tb
instead of merely writing to eip and exiting.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/i386/tcg/translate.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

Comments

Paolo Bonzini Sept. 21, 2022, 1:06 p.m. UTC | #1
On Tue, Sep 6, 2022 at 12:09 PM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> With gen_jmp_rel, we may chain to the next tb
> instead of merely writing to eip and exiting.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

See comment on the previous patch.

Paolo

> ---
>  target/i386/tcg/translate.c | 21 ++++++---------------
>  1 file changed, 6 insertions(+), 15 deletions(-)
>
> diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
> index 07c7764649..fdd17c3cf3 100644
> --- a/target/i386/tcg/translate.c
> +++ b/target/i386/tcg/translate.c
> @@ -7355,24 +7355,18 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
>      case 0xe2: /* loop */
>      case 0xe3: /* jecxz */
>          {
> -            TCGLabel *l1, *l2, *l3;
> -
> -            tval = (int8_t)insn_get(env, s, MO_8);
> -            tval += s->pc - s->cs_base;
> -            if (dflag == MO_16) {
> -                tval &= 0xffff;
> -            }
> +            TCGLabel *l1, *l2;
> +            int diff = (int8_t)insn_get(env, s, MO_8);
>
>              l1 = gen_new_label();
>              l2 = gen_new_label();
> -            l3 = gen_new_label();
>              gen_update_cc_op(s);
>              b &= 3;
>              switch(b) {
>              case 0: /* loopnz */
>              case 1: /* loopz */
>                  gen_op_add_reg_im(s, s->aflag, R_ECX, -1);
> -                gen_op_jz_ecx(s, s->aflag, l3);
> +                gen_op_jz_ecx(s, s->aflag, l2);
>                  gen_jcc1(s, (JCC_Z << 1) | (b ^ 1), l1);
>                  break;
>              case 2: /* loop */
> @@ -7385,14 +7379,11 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
>                  break;
>              }
>
> -            gen_set_label(l3);
> -            gen_update_eip_next(s);
> -            tcg_gen_br(l2);
> +            gen_set_label(l2);
> +            gen_jmp_rel(s, MO_32, 0, 1);
>
>              gen_set_label(l1);
> -            gen_jmp_im(s, tval);
> -            gen_set_label(l2);
> -            s->base.is_jmp = DISAS_EOB_ONLY;
> +            gen_jmp_rel(s, dflag, diff, 0);
>          }
>          break;
>      case 0x130: /* wrmsr */
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
index 07c7764649..fdd17c3cf3 100644
--- a/target/i386/tcg/translate.c
+++ b/target/i386/tcg/translate.c
@@ -7355,24 +7355,18 @@  static bool disas_insn(DisasContext *s, CPUState *cpu)
     case 0xe2: /* loop */
     case 0xe3: /* jecxz */
         {
-            TCGLabel *l1, *l2, *l3;
-
-            tval = (int8_t)insn_get(env, s, MO_8);
-            tval += s->pc - s->cs_base;
-            if (dflag == MO_16) {
-                tval &= 0xffff;
-            }
+            TCGLabel *l1, *l2;
+            int diff = (int8_t)insn_get(env, s, MO_8);
 
             l1 = gen_new_label();
             l2 = gen_new_label();
-            l3 = gen_new_label();
             gen_update_cc_op(s);
             b &= 3;
             switch(b) {
             case 0: /* loopnz */
             case 1: /* loopz */
                 gen_op_add_reg_im(s, s->aflag, R_ECX, -1);
-                gen_op_jz_ecx(s, s->aflag, l3);
+                gen_op_jz_ecx(s, s->aflag, l2);
                 gen_jcc1(s, (JCC_Z << 1) | (b ^ 1), l1);
                 break;
             case 2: /* loop */
@@ -7385,14 +7379,11 @@  static bool disas_insn(DisasContext *s, CPUState *cpu)
                 break;
             }
 
-            gen_set_label(l3);
-            gen_update_eip_next(s);
-            tcg_gen_br(l2);
+            gen_set_label(l2);
+            gen_jmp_rel(s, MO_32, 0, 1);
 
             gen_set_label(l1);
-            gen_jmp_im(s, tval);
-            gen_set_label(l2);
-            s->base.is_jmp = DISAS_EOB_ONLY;
+            gen_jmp_rel(s, dflag, diff, 0);
         }
         break;
     case 0x130: /* wrmsr */