This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: if/then/else hint ?
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: Greg Smith <rys at epaibm dot rtpnc dot epa dot gov>
- Cc: gcc at gcc dot gnu dot org, Richard dot Earnshaw at arm dot com
- Date: Thu, 08 Jan 2004 18:00:03 +0000
- Subject: Re: if/then/else hint ?
- Organization: ARM Ltd.
- Reply-to: Richard dot Earnshaw at arm dot com
> 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.