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]

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

I really don't know that much about pentium branch prediction so
might I be worrying about something that won't make any difference ??

Thanks,

Greg Smith


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