All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] TCG and branches
@ 2016-07-30 23:53 Benjamin Herrenschmidt
  2016-07-31 18:25 ` [Qemu-devel] [Qemu-ppc] " Nikunj A Dadhania
  2016-08-06  2:43 ` [Qemu-devel] " Richard Henderson
  0 siblings, 2 replies; 4+ messages in thread
From: Benjamin Herrenschmidt @ 2016-07-30 23:53 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel, qemu-ppc

Hi Richard !

So in my discovery of TCG, one thing I noticed is the horrendous amount
of code generated for branches, especially conditional ones.

I have a patch at least to remove a bunch of dead gunk on target-ppc
for non-conditional ones (we still generated the "else" of the
condition even when never branching to it).

However, I wonder if there are ways to do better.

The first obvious thing that comes to mind is to avoid stopping the
TB on a non-taken conditional branch. The reason that can't be done
today, from my limited understanding of things, is because we only
support index 0 and 1 today for gen_goto_tb().

Now I haven't completely figured out how TB linkage works under the
hood but do you know of any fundamental reason why we have that limit ?

Could we, for example, have a limit of, for example, 8 and only break
the TB after a branch if we have less than 2 left ?

Or are there deeper reasons why we really can't link more than 2 ?

With the current implementation, a non-taken branch results in three
branches: One to "skip over" the condition-true case, one to the new TB
and one in the header of that new TB to check for exits. We could
reduce to one in most cases.

Cheers,
Ben.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] TCG and branches
  2016-07-30 23:53 [Qemu-devel] TCG and branches Benjamin Herrenschmidt
@ 2016-07-31 18:25 ` Nikunj A Dadhania
  2016-07-31 18:31   ` Nikunj A Dadhania
  2016-08-06  2:43 ` [Qemu-devel] " Richard Henderson
  1 sibling, 1 reply; 4+ messages in thread
From: Nikunj A Dadhania @ 2016-07-31 18:25 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Richard Henderson; +Cc: qemu-ppc, qemu-devel

Benjamin Herrenschmidt <benh@kernel.crashing.org> writes:

> Hi Richard !
>
> So in my discovery of TCG, one thing I noticed is the horrendous amount
> of code generated for branches, especially conditional ones.
>

static inline void gen_bcond(DisasContext *ctx, int type)
{
[...]
    if ((bo & 0x4) == 0) {
        /* Decrement and test CTR */
        [...]
        if (bo & 0x2) {
            tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
        } else {
            tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
        }

BUG, both jumping to same label?

Can we replace it unconditionally with

tcg_gen_br(l1) ?

Regards
Nikunj

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] TCG and branches
  2016-07-31 18:25 ` [Qemu-devel] [Qemu-ppc] " Nikunj A Dadhania
@ 2016-07-31 18:31   ` Nikunj A Dadhania
  0 siblings, 0 replies; 4+ messages in thread
From: Nikunj A Dadhania @ 2016-07-31 18:31 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Richard Henderson; +Cc: qemu-ppc, qemu-devel

Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> writes:

> Benjamin Herrenschmidt <benh@kernel.crashing.org> writes:
>
>> Hi Richard !
>>
>> So in my discovery of TCG, one thing I noticed is the horrendous amount
>> of code generated for branches, especially conditional ones.
>>
>
> static inline void gen_bcond(DisasContext *ctx, int type)
> {
> [...]
>     if ((bo & 0x4) == 0) {
>         /* Decrement and test CTR */
>         [...]
>         if (bo & 0x2) {
>             tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
>         } else {
>             tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
>         }
>
> BUG, both jumping to same label?

Sorry for the noise, I understood it wrong.

Regards
Nikunj

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] TCG and branches
  2016-07-30 23:53 [Qemu-devel] TCG and branches Benjamin Herrenschmidt
  2016-07-31 18:25 ` [Qemu-devel] [Qemu-ppc] " Nikunj A Dadhania
@ 2016-08-06  2:43 ` Richard Henderson
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2016-08-06  2:43 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: qemu-ppc, qemu-devel

On 07/31/2016 05:23 AM, Benjamin Herrenschmidt wrote:
> The first obvious thing that comes to mind is to avoid stopping the
> TB on a non-taken conditional branch. The reason that can't be done
> today, from my limited understanding of things, is because we only
> support index 0 and 1 today for gen_goto_tb().

Correct.

> Now I haven't completely figured out how TB linkage works under the
> hood but do you know of any fundamental reason why we have that limit ?
>
> Could we, for example, have a limit of, for example, 8 and only break
> the TB after a branch if we have less than 2 left ?

We do borrow low bits of a pointer (to a TranslationBlock) in implementing 
exit_tb.  See TB_EXIT_MASK and the large block comment just above its 
definition in tcg/tcg.h.

However, increasing the alignment of TranslationBlock ought to be trivial, 
giving you as many bits as required.  With that, I see no reason in principal 
that this wouldn't work.

Such a change would need some measurement to see how often this occurs, and how 
much this helps the actual runtime performance.


r~

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-08-06  2:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-30 23:53 [Qemu-devel] TCG and branches Benjamin Herrenschmidt
2016-07-31 18:25 ` [Qemu-devel] [Qemu-ppc] " Nikunj A Dadhania
2016-07-31 18:31   ` Nikunj A Dadhania
2016-08-06  2:43 ` [Qemu-devel] " Richard Henderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.