disabling branch probability guessing (patch)

Aldy Hernandez aldyh@redhat.com
Tue Jan 16 06:04:00 GMT 2001


> > 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


More information about the Gcc mailing list