This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: disabling branch probability guessing (patch)



> > One of our clients is trying to use __builtin_expect and is getting
> > unexpected results because estimate_probability() in predict.c is 
> > guessing the branch probability in an undetermined way.  This patch
> > solves the problem by providing an option to disable the probability
> > guessing altogether.
> 
> Cool. This is useful for the linux kernel too. I found out that the 
> prediction guessing undoes some of the carefully crafted goto woods
> to keep fast paths jumpless.
> 
> 
> e.g.
> 
> f()
> {
>         int err = -EBLA; 
>         if (unlikely error case) 
>                 goto error;

Why don't you use __builtin_expect() for this?

ala:

	if (__builtin_expect(unlikely error case, 0))
		goto error;
	blah blah

This will place the code in "blah blah" in the fall through path which
is the expected path.  Of course, I have a test case for the i960 in which
this isn't working as advertised, but at least it seems to working fine
for the x86. :-)

Cheers.
Aldy

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]