Setting branch probabilities manually

Gabriel Moruz gabi@daimi.au.dk
Mon Mar 27 12:29:00 GMT 2006


Hi everybody,

  After some google and gcc documentation browsing, I am in the position 
of turning to you for some help. Shortly, I am trying to set manually 
the branch probabilities with __builtin_expect(), but it seems to me 
that it doesn't take the probability I give into account, but it takes 
it at most as a hint (CPU: P4, gcc version: 3.3.2). For example, for a 
vector a[] with a[i] between 0 and 100, the following code achieves fast 
running times for param=0 and param=100 and slower for param=50 instead 
of growing linearly with param.

  for(i=0;i<n;i++)
    if(__builtin_expect(a[i]<param,0) )
      j++;
    else
      j--;

Anything I might have forgot (I compiled the code with -O3)? Any kernel 
patch/kernel option/gcc hidden option that would help this thing out?

Thanks,
Gabriel



More information about the Gcc-help mailing list