By the way, has anybody actually benchmarked these macros to see if they
make any difference. I did a few quick inexact benchmarks on test code and
found that in most cases there was no difference and in some cases code was
made worse.
--
David Schwartz
<[email protected]>
David Schwartz wrote:
>
> By the way, has anybody actually benchmarked these macros to see if they
> make any difference. I did a few quick inexact benchmarks on test code and
> found that in most cases there was no difference and in some cases code was
> made worse.
likely/unlikely set the branch prediction values to 99% or 1%
respectively. If this causes the code generated to perform less
optimally than without, I'm sure the gcc guys would be -very- interested
to hear that...
--
Jeff Garzik | Alternate titles for LOTR:
Building 1024 | Fast Times at Uruk-Hai
MandrakeSoft | The Took, the Elf, His Daughter and Her Lover
| Samwise Gamgee: International Hobbit of Mystery
> likely/unlikely set the branch prediction values to 99% or 1%
> respectively. If this causes the code generated to perform less
> optimally than without, I'm sure the gcc guys would be -very- interested
> to hear that...
On some ppc64 the branch prediction is quite good and static prediction
will override the dynamic prediction. I think we avoid predicting a
branch unless we are quite sure (95%/5%).
So if likely/unlikely is overused (on more marginal conditionals) then
it could be a performance loss.
Anton
> likely/unlikely set the branch prediction values to 99% or 1%
So all of the BUG() routines in the kernel would benifit greatly from this.
Craig.
On Wed, 16 Jan 2002, Craig Christophel wrote:
> > likely/unlikely set the branch prediction values to 99% or 1%
>
>
> So all of the BUG() routines in the kernel would benifit greatly from this.
In the 2.5 kernels this is done when you use the BUG_ON macro that is
defined as follows:
#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
BTW: Note that likely/unlikely doesn't has any effect for most of us
because __builtin_expect is only available in gcc >= 2.96.
> Craig.
cu
Adrian
Anton Blanchard wrote:
>
>
> > likely/unlikely set the branch prediction values to 99% or 1%
> > respectively. If this causes the code generated to perform less
> > optimally than without, I'm sure the gcc guys would be -very- interested
> > to hear that...
>
> On some ppc64 the branch prediction is quite good and static prediction
> will override the dynamic prediction. I think we avoid predicting a
> branch unless we are quite sure (95%/5%).
>
> So if likely/unlikely is overused (on more marginal conditionals) then
> it could be a performance loss.
oh agreed... but marginal conditionals should not be getting
likely()/unlikely() as you are then lying to the compiler about the true
branch predictability...
Jeff
--
Jeff Garzik | Alternate titles for LOTR:
Building 1024 | Fast Times at Uruk-Hai
MandrakeSoft | The Took, the Elf, His Daughter and Her Lover
| Samwise Gamgee: International Hobbit of Mystery
Craig Christophel wrote:
>
> > likely/unlikely set the branch prediction values to 99% or 1%
>
> So all of the BUG() routines in the kernel would benifit greatly from this.
It's likely :) I would put one unlikely() in the definition of BUG_ON,
rather rather touching all the code that calls BUG(), though.
Jeff
--
Jeff Garzik | Alternate titles for LOTR:
Building 1024 | Fast Times at Uruk-Hai
MandrakeSoft | The Took, the Elf, His Daughter and Her Lover
| Samwise Gamgee: International Hobbit of Mystery
On Wed, Jan 16 2002, Jeff Garzik wrote:
> Craig Christophel wrote:
> >
> > > likely/unlikely set the branch prediction values to 99% or 1%
> >
> > So all of the BUG() routines in the kernel would benifit greatly from this.
>
>
> It's likely :) I would put one unlikely() in the definition of BUG_ON,
> rather rather touching all the code that calls BUG(), though.
BUG_ON has had unlikely since the very beginning :-)
--
Jens Axboe