qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Desnogues <laurent.desnogues@gmail.com>
To: Richard Henderson <rth@twiddle.net>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH 4/6] tcg-i386: Implement small forward branches.
Date: Fri, 18 Dec 2009 12:39:54 +0100	[thread overview]
Message-ID: <761ea48b0912180339p111e052cuca152598ef86dc0e@mail.gmail.com> (raw)
In-Reply-To: <89dbe5fc9e003225157911e8ad8b19b73cae7177.1261078375.git.rth@twiddle.net>

On Thu, Dec 17, 2009 at 6:55 PM, Richard Henderson <rth@twiddle.net> wrote:
> There are places, like brcond2, where we know that the destination
> of a forward branch will be within 127 bytes.  Add the R_386_PC8
> relocation type to support this, and add a flag to tcg_out_jxx to
> generate it.  Set the flag in the small forward branches in brcond2.
>
> Signed-off-by: Richard Henderson <rth@twiddle.net>
> ---
>  elf.h                 |    2 ++
>  tcg/i386/tcg-target.c |   36 +++++++++++++++++++++++++-----------
>  2 files changed, 27 insertions(+), 11 deletions(-)
>
> diff --git a/elf.h b/elf.h
> index 11674d7..c84c8ab 100644
> --- a/elf.h
> +++ b/elf.h
> @@ -243,6 +243,8 @@ typedef struct {
>  #define R_386_GOTOFF   9
>  #define R_386_GOTPC    10
>  #define R_386_NUM      11
> +/* Not a dynamic reloc, so not included in R_386_NUM.  Used in TCG.  */
> +#define R_386_PC8      23
>
>  #define R_MIPS_NONE            0
>  #define R_MIPS_16              1
> diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
> index 972b102..cc3d28f 100644
> --- a/tcg/i386/tcg-target.c
> +++ b/tcg/i386/tcg-target.c
> @@ -61,6 +61,9 @@ static void patch_reloc(uint8_t *code_ptr, int type,
>     case R_386_PC32:
>         *(uint32_t *)code_ptr = value - (long)code_ptr;
>         break;
> +    case R_386_PC8:
> +        *(uint8_t *)code_ptr = value - (long)code_ptr;
> +        break;
>     default:
>         tcg_abort();
>     }
> @@ -305,7 +308,8 @@ static void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val)
>         tgen_arithi(s, ARITH_ADD, reg, val, 0);
>  }
>
> -static void tcg_out_jxx(TCGContext *s, int opc, int label_index)
> +/* Use SMALL != 0 to force a short forward branch.  */
> +static void tcg_out_jxx(TCGContext *s, int opc, int label_index, int small)
>  {
>     int32_t val, val1;
>     TCGLabel *l = &s->labels[label_index];
> @@ -320,6 +324,7 @@ static void tcg_out_jxx(TCGContext *s, int opc, int label_index)
>                 tcg_out8(s, 0x70 + opc);
>             tcg_out8(s, val1);
>         } else {
> +            assert (!small);

To be consistent with the rest I'd use:

  if (small)
    tcg_abort();

>             if (opc == -1) {
>                 tcg_out8(s, 0xe9);
>                 tcg_out32(s, val - 5);
> @@ -329,6 +334,15 @@ static void tcg_out_jxx(TCGContext *s, int opc, int label_index)
>                 tcg_out32(s, val - 6);
>             }
>         }
> +    } else if (small) {
> +        if (opc == -1) {
> +            tcg_out8(s, 0xeb);
> +        } else {
> +            tcg_out8(s, 0x0f);

I don't think this prefix should be output.


Laurent

> +            tcg_out8(s, 0x70 + opc);
> +        }
> +        tcg_out_reloc(s, s->code_ptr, R_386_PC8, label_index, -1);
> +        s->code_ptr += 1;
>     } else {
>         if (opc == -1) {
>             tcg_out8(s, 0xe9);
> @@ -355,7 +369,7 @@ static void tcg_out_brcond(TCGContext *s, int cond,
>     } else {
>         tcg_out_modrm(s, 0x01 | (ARITH_CMP << 3), arg2, arg1);
>     }
> -    tcg_out_jxx(s, tcg_cond_to_jcc[cond], label_index);
> +    tcg_out_jxx(s, tcg_cond_to_jcc[cond], label_index, 0);
>  }
>
>  /* XXX: we implement it at the target level to avoid having to
> @@ -376,42 +390,42 @@ static void tcg_out_brcond2(TCGContext *s,
>         break;
>     case TCG_COND_LT:
>         tcg_out_brcond(s, TCG_COND_LT, args[1], args[3], const_args[3], args[5]);
> -        tcg_out_jxx(s, JCC_JNE, label_next);
> +        tcg_out_jxx(s, JCC_JNE, label_next, 1);
>         tcg_out_brcond(s, TCG_COND_LTU, args[0], args[2], const_args[2], args[5]);
>         break;
>     case TCG_COND_LE:
>         tcg_out_brcond(s, TCG_COND_LT, args[1], args[3], const_args[3], args[5]);
> -        tcg_out_jxx(s, JCC_JNE, label_next);
> +        tcg_out_jxx(s, JCC_JNE, label_next, 1);
>         tcg_out_brcond(s, TCG_COND_LEU, args[0], args[2], const_args[2], args[5]);
>         break;
>     case TCG_COND_GT:
>         tcg_out_brcond(s, TCG_COND_GT, args[1], args[3], const_args[3], args[5]);
> -        tcg_out_jxx(s, JCC_JNE, label_next);
> +        tcg_out_jxx(s, JCC_JNE, label_next, 1);
>         tcg_out_brcond(s, TCG_COND_GTU, args[0], args[2], const_args[2], args[5]);
>         break;
>     case TCG_COND_GE:
>         tcg_out_brcond(s, TCG_COND_GT, args[1], args[3], const_args[3], args[5]);
> -        tcg_out_jxx(s, JCC_JNE, label_next);
> +        tcg_out_jxx(s, JCC_JNE, label_next, 1);
>         tcg_out_brcond(s, TCG_COND_GEU, args[0], args[2], const_args[2], args[5]);
>         break;
>     case TCG_COND_LTU:
>         tcg_out_brcond(s, TCG_COND_LTU, args[1], args[3], const_args[3], args[5]);
> -        tcg_out_jxx(s, JCC_JNE, label_next);
> +        tcg_out_jxx(s, JCC_JNE, label_next, 1);
>         tcg_out_brcond(s, TCG_COND_LTU, args[0], args[2], const_args[2], args[5]);
>         break;
>     case TCG_COND_LEU:
>         tcg_out_brcond(s, TCG_COND_LTU, args[1], args[3], const_args[3], args[5]);
> -        tcg_out_jxx(s, JCC_JNE, label_next);
> +        tcg_out_jxx(s, JCC_JNE, label_next, 1);
>         tcg_out_brcond(s, TCG_COND_LEU, args[0], args[2], const_args[2], args[5]);
>         break;
>     case TCG_COND_GTU:
>         tcg_out_brcond(s, TCG_COND_GTU, args[1], args[3], const_args[3], args[5]);
> -        tcg_out_jxx(s, JCC_JNE, label_next);
> +        tcg_out_jxx(s, JCC_JNE, label_next, 1);
>         tcg_out_brcond(s, TCG_COND_GTU, args[0], args[2], const_args[2], args[5]);
>         break;
>     case TCG_COND_GEU:
>         tcg_out_brcond(s, TCG_COND_GTU, args[1], args[3], const_args[3], args[5]);
> -        tcg_out_jxx(s, JCC_JNE, label_next);
> +        tcg_out_jxx(s, JCC_JNE, label_next, 1);
>         tcg_out_brcond(s, TCG_COND_GEU, args[0], args[2], const_args[2], args[5]);
>         break;
>     default:
> @@ -913,7 +927,7 @@ static inline void tcg_out_op(TCGContext *s, int opc,
>         }
>         break;
>     case INDEX_op_br:
> -        tcg_out_jxx(s, JCC_JMP, args[0]);
> +        tcg_out_jxx(s, JCC_JMP, args[0], 0);
>         break;
>     case INDEX_op_movi_i32:
>         tcg_out_movi(s, TCG_TYPE_I32, args[0], args[1]);
> --
> 1.6.5.2
>
>

  reply	other threads:[~2009-12-18 11:40 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <761ea48b0912170620l534dcb02m8ea6b59524d76dbe@mail.gmail.com>
2009-12-17 19:32 ` [Qemu-devel] [PATCH 0/6] tcg conditional set/move, round 2 Richard Henderson
2009-12-17 17:27   ` [Qemu-devel] [PATCH 1/6] tcg: Generic support for conditional set and conditional move Richard Henderson
2009-12-17 20:50     ` malc
2009-12-18 11:38     ` [Qemu-devel] " Laurent Desnogues
2009-12-17 17:28   ` [Qemu-devel] [PATCH 2/6] tcg: Add tcg_invert_cond Richard Henderson
2009-12-18 11:39     ` [Qemu-devel] " Laurent Desnogues
2009-12-17 17:32   ` [Qemu-devel] [PATCH 3/6] tcg-x86_64: Implement setcond and movcond Richard Henderson
2009-12-18 11:39     ` [Qemu-devel] " Laurent Desnogues
2009-12-18 17:11       ` Richard Henderson
2009-12-18 17:41         ` Laurent Desnogues
2009-12-17 17:55   ` [Qemu-devel] [PATCH 4/6] tcg-i386: Implement small forward branches Richard Henderson
2009-12-18 11:39     ` Laurent Desnogues [this message]
2009-12-18 17:16       ` [Qemu-devel] " Richard Henderson
2009-12-17 18:38   ` [Qemu-devel] [PATCH 5/6] tcg-i386: Simplify brcond2 Richard Henderson
2009-12-18 11:40     ` [Qemu-devel] " Laurent Desnogues
2009-12-18 17:45       ` Richard Henderson
2009-12-17 19:08   ` [Qemu-devel] [PATCH 6/6] tcg-i386: Implement setcond, movcond, setcond2 Richard Henderson
2009-12-18 11:37   ` [Qemu-devel] Re: [PATCH 0/6] tcg conditional set/move, round 2 Laurent Desnogues
2009-12-18 21:38     ` [Qemu-devel] tcg conditional set/move, round 3 Richard Henderson
2009-12-19 11:40       ` [Qemu-devel] " Laurent Desnogues
2009-12-19 16:09         ` Richard Henderson
2009-12-19 12:09       ` [Qemu-devel] " Andreas Färber
2009-12-19 13:03       ` Aurelien Jarno
2009-12-19 13:32         ` Aurelien Jarno
2009-12-19 16:19         ` Richard Henderson
2009-12-19 23:02           ` Aurelien Jarno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=761ea48b0912180339p111e052cuca152598ef86dc0e@mail.gmail.com \
    --to=laurent.desnogues@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).