This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: optimizing predictable branches on x86
- From: Kenny Simpson <theonetruekenny at yahoo dot com>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 27 Feb 2008 00:21:35 -0800 (PST)
- Subject: Re: optimizing predictable branches on x86
> At least on x86 it should also be a good idea to know which way
> the branch is going to go, because it doesn't have explicit branch
> hints, you really want to be able to optimize the cold branch
> predictor case if converting from cmov to conditional branches.
x86 as of Pentium 4 does have branch hint instruction prefixes, but their use is somewhat
discouraged:
from http://softwarecommunity.intel.com/articles/eng/3431.htm:
"
The Pentium® 4 Processor introduced new instructions for adding static hints to branches. It is
not recommended that a programmer use these instructions, as they add slightly to the size of the
code and are static hints only. It is best to use a conditional branch in the manner that the
static predictor expects, rather than adding these branch hints.
In the event that a branch hint is necessary, the following instruction prefixes can be added
before a branch instruction to change the way the static predictor behaves:
* 0x3E ? statically predict a branch as taken
* 0x2E ? statically predict a branch as not taken
"
see also section 2.1.1 Instruction Prefixes in
http://download.intel.com/design/processor/manuals/253666.pdf:
"
Branch hint prefixes (2EH, 3EH) allow a program to give a hint to the processor about
the most likely code path for a branch. Use these prefixes only with conditional
branch instructions (Jcc). Other use of branch hint prefixes and/or other undefined
opcodes with Intel 64 or IA-32 instructions is reserved; such use may cause unpre-
dictable behavior.
"
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs