This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
if/then/else hint ?
- From: Greg Smith <rys at epaibm dot rtpnc dot epa dot gov>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 08 Jan 2004 12:49:52 -0500
- Subject: 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