dotgnu-libjit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Dotgnu-libjit] performance of conditionals


From: ktreichel
Subject: Re: [Dotgnu-libjit] performance of conditionals
Date: Mon, 10 Nov 2008 16:56:54 +0100

Hi Paul,

> -----Urspr√ľngliche Nachricht-----
> Von: "Paul Brannan" <address@hidden>
> Gesendet: 10.11.08 16:31:04
> An: address@hidden
> Betreff: [Dotgnu-libjit] performance of conditionals


> I have a conditional in which one case is many more times likely to
> occur than the other case.  Currently the implementation does this:
> 
>       branch_if_not(cond, L1)
>       <true case>
>       branch(L2)
>   L1: <false case>
>   L2: <remainder of code>
>       ...
>       return
> 

This is usually the fastest way if the code in <true case> is not too short.
The static branch prediction assumes a forward branch not being taken. (This is 
according to intel x86 docs).
An unconditional branch should not cause misprediction.

But you have to keep in mind that different cpu's (even of the same family) 
behave different in such cases.

> I have considered implementing it like this instead:
> 
>       branch_if_not(cond, L1)
>       <true case>
>   L2: <remainder of code>
>       ...
>       return
>   L1: <false case>
>       branch(L2)
> 
> thus avoiding the branch for the usual case.
> 

With libjit this can't be generated because jit_insn_ret generates a branch to 
the epilog which is always at the very end of the function.
So you'll end up with:

 
      branch_if_not(cond, L1)
      <true case>
  L2: <remainder of code>
       ...
       branch(epilog)
   L1: <false case>
       branch(L2)
   epilog:
       ...
       return 

Klaus

_________________________________________________________________________
In 5 Schritten zur eigenen Homepage. Jetzt Domain sichern und gestalten! 
Nur 3,99 EUR/Monat! http://www.maildomain.web.de/?mc=021114





reply via email to

[Prev in Thread] Current Thread [Next in Thread]