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: Any way to do branch hints?


Ah, but the conditional branch hint field just changes the default
branch hint, right?  (This is typically to assume that forward branches
aren't taken and backward branches are).  So if gcc arranges the code
such that the __builtin_expect direction is the fall-through direction,
then it would be no faster to use the branch hint prefix.  Right?

I think in the specific case of the P4 you may actually still get a boon from using the hint prefixes. I cant lay my hands on the docs right now so this is from 2-years old yellow-book memory, but I think that the branch hint prefixes bias the insn decoder to actually fetch code from the forwards address of the conditional jump and start getting them in-flight.

Yes, if the code has been ordered such that the taken branch
is immediately following the conditional jump then chances
are those insns are already in flight anyway, but I seem to
recall that the hint prefixes would help in the case where
the distance between the conditional jump and the taken
case code was greater than the decoding queue. So for
example, if the taken-take was, say, 10K further up in
memory, and you used a branch hint, that the decoder would
actually start fetching insns from that location and begin
moving them through the CPU quite early, so that by the
time you actually take the branch, there is a high
probability that the first insn at the jumped-to address
is the next insn to come off the queue.

You pay the penalty of having to possibly re-decode some
insns in the exception case, but that is generally deemed
acceptable. I will try and find the relevant sections in
the Intel data books and point you at a reference.

Kean


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