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]
Other format: [Raw text]

Re: if/then/else hint ?


> Running gcc 3.2.2 on i686
> 
> We have a situation where we have coded in a heavily used loop
> that is critical for performance:
> 
>   if (<condition>)
>      <fastpath>;
>   else
>      <slowpath>;
> 
> <fastpath> is taken about 250 times for each time <slowpath> is
> taken; however if <condition> was randomly distributed then
> <slowpath> would be taken more often.  (This is the instruction
> fetch piece of an emulator, <condition> is the instruction address
> so we know that generally <condition> is not randomly distributed).
> 
> However, the emitted code looks like:
> 
>     test_condition
>     jump_conditionally fastpath
>     <slowpath>
> x:
>     .  .  .  .  .
> 
> fastpath:
>     <fastpath>
>     jump x
> 
> We would much prefer to fall thru to <fastpath> instead and jump
> away to <slowpath> (reducing path length for <fastpath> by an
> instruction).  Is there a way to give the compiler the hint ??
> 

Yes.  See __builtin_expect in the manual.

R. 



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